diff options
| author | Jeff Carr <[email protected]> | 2024-11-30 15:06:57 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-11-30 15:06:57 -0600 |
| commit | 3a4e0c1046276235488326bb4e032c801280fc15 (patch) | |
| tree | 339de3baf86334068825038f77b8139d9deb7af8 /parseProtoFile.go | |
| parent | d2112f954d68fde00a4781c9f2d8ca8bec837055 (diff) | |
auto detect unique keys in protobuf filev0.0.5
Diffstat (limited to 'parseProtoFile.go')
| -rw-r--r-- | parseProtoFile.go | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/parseProtoFile.go b/parseProtoFile.go new file mode 100644 index 0000000..682234d --- /dev/null +++ b/parseProtoFile.go @@ -0,0 +1,44 @@ +package main + +// auto run protoc with the correct args + +import ( + "os" + "strings" + + "go.wit.com/log" + "golang.org/x/text/cases" + "golang.org/x/text/language" +) + +// finds autogenpb:marshal and autogenpb:unique in the .proto file +// +// adds fields to []marshal and []unique +func findAutogenpb(names map[string]string) error { + log.Info("starting findAutogenpb() on", names["protofile"]) + // read in the .proto file + data, err := os.ReadFile(names["protofile"]) + if err != nil { + // log.Info("open config file :", err) + return err + } + + // look for included proto files + lines := strings.Split(string(data), "\n") + for _, line := range lines { + // log.Info("line:", line) + parts := strings.Fields(line) + if strings.Contains(line, "autogenpb:marshal") { + newm := parts[1] + log.Info("found marshal", newm) + marshalKeys = append(marshalKeys, newm) + } + if strings.Contains(line, "autogenpb:unique") { + newu := parts[1] + newu = cases.Title(language.English, cases.NoLower).String(newu) + log.Info("found unique field", newu) + uniqueKeys = append(uniqueKeys, newu) + } + } + return nil +} |
