-
-
Notifications
You must be signed in to change notification settings - Fork 68
/
main.go
45 lines (33 loc) · 939 Bytes
/
main.go
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
45
package main // import "moul.io/protoc-gen-gotemplate"
import (
"io/ioutil"
"os"
"github.com/golang/protobuf/proto" // nolint:staticcheck
"github.com/golang/protobuf/protoc-gen-go/generator" // nolint:staticcheck
pgghelpers "moul.io/protoc-gen-gotemplate/helpers"
)
func main() {
g := generator.New()
data, err := ioutil.ReadAll(os.Stdin)
if err != nil {
g.Error(err, "reading input")
}
if err = proto.Unmarshal(data, g.Request); err != nil {
g.Error(err, "parsing input proto")
}
if len(g.Request.FileToGenerate) == 0 {
g.Fail("no files to generate")
}
g.CommandLineParameters(g.Request.GetParameter())
pgghelpers.ParseParams(g)
// Generate the protobufs
g.GenerateAllFiles()
data, err = proto.Marshal(g.Response)
if err != nil {
g.Error(err, "failed to marshal output proto")
}
_, err = os.Stdout.Write(data)
if err != nil {
g.Error(err, "failed to write output proto")
}
}