forked from metaverse/truss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
47 lines (37 loc) · 849 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
46
47
package main
import (
"fmt"
"io/ioutil"
"os"
"github.com/gogo/protobuf/proto"
plugin "github.com/gogo/protobuf/protoc-gen-gogo/plugin"
)
func main() {
input, err := ioutil.ReadAll(os.Stdin)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
req := new(plugin.CodeGeneratorRequest)
if err = proto.Unmarshal(input, req); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
filesOut := req.GetFileToGenerate()
//fmt.Fprintln(os.Stderr, "test")
fileName := filesOut[0]
protocOut := string(input)
codeGenFile := plugin.CodeGeneratorResponse_File{
Name: &fileName,
Content: &protocOut,
}
output := &plugin.CodeGeneratorResponse{
File: []*plugin.CodeGeneratorResponse_File{
&codeGenFile,
},
}
buf, err := proto.Marshal(output)
if _, err := os.Stdout.Write(buf); err != nil {
os.Exit(1)
}
}