blob: 682234dbba7c559ece392d09589c45c1083bb563 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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
}
|