本文整理汇总了Golang中github.com/golang/protobuf/protoc-gen-go/plugin.CodeGeneratorRequest.GetField方法的典型用法代码示例。如果您正苦于以下问题:Golang CodeGeneratorRequest.GetField方法的具体用法?Golang CodeGeneratorRequest.GetField怎么用?Golang CodeGeneratorRequest.GetField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/golang/protobuf/protoc-gen-go/plugin.CodeGeneratorRequest
的用法示例。
在下文中一共展示了CodeGeneratorRequest.GetField方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
msg := plugin.CodeGeneratorRequest{}
buff, err := ioutil.ReadAll(os.Stdin)
if err != nil {
panic(err)
}
if err := proto.Unmarshal(buff, &msg); err != nil {
panic(err)
}
ret := &plugin.CodeGeneratorResponse{}
defer func() {
buff, _ := proto.Marshal(ret)
os.Stdout.Write(buff)
}()
param := msg.GetParameter()
imports := map[string]string{}
sources := map[string]string{}
for _, p := range strings.Split(param, ",") {
if len(p) == 0 {
continue
}
if p[0] == 'M' {
parts := strings.Split(p[1:], "=")
imports[parts[0]] = parts[1]
}
}
messages := map[string]message{}
for _, file := range msg.GetProtoFile() {
for _, msg := range file.GetMessageType() {
m := message{}
for _, f := range msg.GetField() {
m.Fields = append(m.Fields, field{
ProtoName: f.GetName(),
GoName: goise(f.GetName()),
})
}
messages["."+file.GetPackage()+"."+msg.GetName()] = m
sources["."+file.GetPackage()+"."+msg.GetName()] = file.GetName()
}
}
for _, file := range msg.GetProtoFile() {
services := map[string]service{}
goPackage := "main"
if file.GetOptions() != nil {
goPackage = file.GetOptions().GetGoPackage()
}
for _, svc := range file.GetService() {
s := service{
GoName: goise(svc.GetName()),
}
for _, meth := range svc.GetMethod() {
m := method{
GoName: goise(meth.GetName()),
GoInputType: goise(meth.GetInputType()),
Input: messages[meth.GetInputType()],
InputType: meth.GetInputType(),
}
if meth.GetOptions() == nil {
continue
}
if tmp, err := proto.GetExtension(meth.GetOptions(), google_api.E_Http); err == nil {
http := tmp.(*google_api.HttpRule)
if http.Get != "" {
m.PathArgs = parsePath(messages, meth, http.Get)
m.Path = http.Get
m.Method = "GET"
}
if http.Put != "" {
m.PathArgs = parsePath(messages, meth, http.Put)
m.Path = http.Put
m.Method = "PUT"
}
if http.Post != "" {
m.PathArgs = parsePath(messages, meth, http.Post)
m.Path = http.Post
m.Method = "POST"
}
if http.Delete != "" {
m.PathArgs = parsePath(messages, meth, http.Delete)
m.Path = http.Delete
//.........这里部分代码省略.........