本文整理汇总了Golang中github.com/golang/protobuf/protoc-gen-go/plugin.CodeGeneratorRequest类的典型用法代码示例。如果您正苦于以下问题:Golang CodeGeneratorRequest类的具体用法?Golang CodeGeneratorRequest怎么用?Golang CodeGeneratorRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CodeGeneratorRequest类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Load
// Load loads definitions of services, methods, messages, enumerations and fields from "req".
func (r *Registry) Load(req *plugin.CodeGeneratorRequest) error {
for _, file := range req.GetProtoFile() {
r.loadFile(file)
}
var targetPkg string
for _, name := range req.FileToGenerate {
target := r.files[name]
if target == nil {
return fmt.Errorf("no such file: %s", name)
}
name := packageIdentityName(target.FileDescriptorProto)
if targetPkg == "" {
targetPkg = name
} else {
if targetPkg != name {
return fmt.Errorf("inconsistent package names: %s %s", targetPkg, name)
}
}
if err := r.loadServices(target); err != nil {
return err
}
}
return nil
}
开发者ID:peter-edge,项目名称:protoeasy-go,代码行数:27,代码来源:registry.go
示例2: main
func main() {
var (
err error
data []byte
protoFiles []*descriptor.FileDescriptorProto
totalErrors int
generatorRequest = new(protoc.CodeGeneratorRequest)
)
data, err = ioutil.ReadAll(os.Stdin)
panicOnError(err)
err = proto.Unmarshal(data, generatorRequest)
panicOnError(err)
protoFiles = generatorRequest.GetProtoFile()
for _, file := range protoFiles {
numErrors, err := linter.LintProtoFile(file, os.Stderr)
panicOnError(err)
totalErrors += numErrors
}
os.Exit(totalErrors)
}
开发者ID:ckaznocha,项目名称:protoc-gen-lint,代码行数:25,代码来源:main.go
示例3: Load
// Load loads definitions of services, methods, messages and fields from "req".
func (r *Registry) Load(req *plugin.CodeGeneratorRequest) error {
for _, file := range req.GetProtoFile() {
r.loadFile(file)
}
for _, target := range req.FileToGenerate {
if err := r.loadServices(target); err != nil {
return err
}
}
return nil
}
开发者ID:vvakame,项目名称:grpc-gateway,代码行数:12,代码来源:registry.go
示例4: ParseParams
// ParseParams parses the comma-separated command-line parameters passed to the
// generator by protoc via r.GetParameters. Returned is a map of key=value
// parameters with whitespace preserved.
func ParseParams(r *plugin.CodeGeneratorRequest) map[string]string {
// Split the parameter string and initialize the map.
split := strings.Split(r.GetParameter(), ",")
param := make(map[string]string, len(split))
// Map the parameters.
for _, p := range split {
eq := strings.Split(p, "=")
if len(eq) == 1 {
param[strings.TrimSpace(eq[0])] = ""
continue
}
val := strings.TrimSpace(eq[1])
param[strings.TrimSpace(eq[0])] = val
}
return param
}
开发者ID:ethernetdan,项目名称:prototools,代码行数:20,代码来源:util.go
示例5: convert
func convert(req *plugin.CodeGeneratorRequest) (*plugin.CodeGeneratorResponse, error) {
generateTargets := make(map[string]bool)
for _, file := range req.GetFileToGenerate() {
generateTargets[file] = true
}
res := &plugin.CodeGeneratorResponse{}
for _, file := range req.GetProtoFile() {
for _, msg := range file.GetMessageType() {
glog.V(1).Infof("Loading a message type %s from package %s", msg.GetName(), file.GetPackage())
registerType(file.Package, msg)
}
}
for _, file := range req.GetProtoFile() {
if _, ok := generateTargets[file.GetName()]; ok {
glog.V(1).Info("Converting ", file.GetName())
converted, err := convertFile(file)
if err != nil {
res.Error = proto.String(fmt.Sprintf("Failed to convert %s: %v", file.GetName(), err))
return res, err
}
res.File = append(res.File, converted...)
}
}
return res, nil
}
开发者ID:GoogleCloudPlatform,项目名称:protoc-gen-bq-schema,代码行数:26,代码来源:main.go
示例6: 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
//.........这里部分代码省略.........
开发者ID:AmandaCameron,项目名称:protoc-gen-gokit,代码行数:101,代码来源:main.go
注:本文中的github.com/golang/protobuf/protoc-gen-go/plugin.CodeGeneratorRequest类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论