2016-11-04 23:45:25 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/golang/protobuf/proto"
|
|
|
|
"github.com/golang/protobuf/protoc-gen-go/generator"
|
|
|
|
)
|
|
|
|
|
|
|
|
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())
|
|
|
|
|
|
|
|
// Generate the clients
|
|
|
|
for _, file := range g.Request.GetProtoFile() {
|
|
|
|
for _, service := range file.GetService() {
|
2016-11-06 19:20:57 +03:00
|
|
|
encoder := NewGenericTemplateBasedEncoder("templates", service, file)
|
2016-11-04 23:45:25 +03:00
|
|
|
g.Response.File = append(g.Response.File, encoder.Files()...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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")
|
|
|
|
}
|
|
|
|
}
|