protoc-gen-go-micro/rpc.go
Vasiliy Tolstov a974da658b generate error types for http
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2021-02-23 14:30:23 +03:00

53 lines
1.4 KiB
Go

package main
import (
"google.golang.org/protobuf/compiler/protogen"
)
func (g *Generator) rpcGenerate(component string, plugin *protogen.Plugin) error {
for _, file := range plugin.Files {
if !file.Generate {
continue
}
if len(file.Services) == 0 {
continue
}
gname := file.GeneratedFilenamePrefix + "_micro_" + component + ".pb.go"
gfile := plugin.NewGeneratedFile(gname, ".")
gfile.P("// Code generated by protoc-gen-micro")
gfile.P("// source: ", *file.Proto.Name)
gfile.P("package ", file.GoPackageName)
gfile.P()
gfile.P("import (")
gfile.P(`"context"`)
gfile.P()
gfile.P(`micro_api "github.com/unistack-org/micro/v3/api"`)
gfile.P(`micro_client "github.com/unistack-org/micro/v3/client"`)
gfile.P(`micro_server "github.com/unistack-org/micro/v3/server"`)
gfile.P(")")
gfile.P()
gfile.P("// Reference imports to suppress errors if they are not otherwise used.")
gfile.P("var (")
gfile.P("_ ", "micro_api.Endpoint")
gfile.P("_ ", "context.Context")
gfile.P(" _ ", "micro_client.Option")
gfile.P(" _ ", "micro_server.Option")
gfile.P(")")
gfile.P()
for _, service := range file.Services {
generateServiceClient(gfile, service)
generateServiceClientMethods(gfile, service, false)
generateServiceServer(gfile, service)
generateServiceServerMethods(gfile, service)
generateServiceRegister(gfile, service)
}
}
return nil
}