-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.go
45 lines (37 loc) · 836 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 (
"fmt"
"io/ioutil"
"os"
"github.com/golang/protobuf/proto"
plugin "github.com/golang/protobuf/protoc-gen-go/plugin"
)
func main() {
data, err := ioutil.ReadAll(os.Stdin)
if err != nil {
fmt.Fprintln(os.Stderr, "error reading input")
os.Exit(1)
}
req := &plugin.CodeGeneratorRequest{}
err = proto.Unmarshal(data, req)
if err != nil {
fmt.Fprintln(os.Stderr, "error parsing input proto")
os.Exit(1)
}
g := newGenerator(req)
err = g.Generate()
if err != nil {
fmt.Fprintf(os.Stderr, "error generating output: %s\n", err)
os.Exit(1)
}
data, err = proto.Marshal(g.Response)
if err != nil {
fmt.Fprintln(os.Stderr, "error marshaling output proto")
os.Exit(1)
}
_, err = os.Stdout.Write(data)
if err != nil {
fmt.Fprintln(os.Stderr, "error writing output")
os.Exit(1)
}
}