forked from horizon-games/protoc-gen-twirp_ts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (39 loc) · 797 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
48
49
50
51
package main
import (
"log"
"os"
"errors"
"io"
"io/ioutil"
"github.com/golang/protobuf/proto"
plugin "github.com/golang/protobuf/protoc-gen-go/plugin"
)
func read(rdr io.Reader) (*plugin.CodeGeneratorRequest, error) {
buf, err := ioutil.ReadAll(rdr)
if err != nil {
return nil, err
}
req := &plugin.CodeGeneratorRequest{}
if err := proto.Unmarshal(buf, req); err != nil {
return nil, err
}
if len(req.FileToGenerate) < 1 {
return nil, errors.New(`no files to generate`)
}
return req, err
}
func main() {
req, err := read(os.Stdin)
if err != nil {
log.Fatal("read: ", err)
}
res, err := generate(req)
if err != nil {
log.Fatal("generate: ", err)
}
buf, err := proto.Marshal(res)
if err != nil {
log.Fatal("marshal: ", err)
}
os.Stdout.Write(buf)
}