diff options
| author | Jeff Carr <[email protected]> | 2024-11-29 15:19:04 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-11-29 15:19:04 -0600 |
| commit | a6035cb90f0b86272dd9878c91b59048044873de (patch) | |
| tree | a47731d795cb776ca7dd460da92f56e2814af7b1 /addMutex.go | |
| parent | 678cb67c9be01a4a785ff24065d5b68e869a770e (diff) | |
move autogen sort.pb.go into seperate file
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'addMutex.go')
| -rw-r--r-- | addMutex.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/addMutex.go b/addMutex.go new file mode 100644 index 0000000..fa56a82 --- /dev/null +++ b/addMutex.go @@ -0,0 +1,46 @@ +package main + +// eh, screw it, just add the damned mutex to the pb.go file + +import ( + "errors" + "fmt" + "os" + "strings" + + "go.wit.com/log" +) + +func addMutex(names map[string]string) error { + fullname := names["protobase"] + ".pb.go" + log.Info("fullname:", fullname) + data, err := os.ReadFile(fullname) + if err != nil { + // log.Info("open config file :", err) + return err + } + + w, _ := os.OpenFile(names["protobase"]+".pb.go", os.O_WRONLY|os.O_CREATE, 0600) + + var found bool + + lines := strings.Split(string(data), "\n") + for _, line := range lines { + // log.Info("line:", line) + start := "type " + names["Bases"] + " struct {" + if strings.HasSuffix(line, start) { + found = true + log.Info("FOUND line:", line) + fmt.Fprintln(w, line) + fmt.Fprintln(w, "\tsync.RWMutex // auto-added by go.wit.com/apps/autogenpb") + fmt.Fprintln(w, "") + } else { + fmt.Fprintln(w, line) + } + } + // os.Exit(-1) + if found { + return nil + } + return errors.New("addMutex() parse didn't work") +} |
