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.3 KiB
Go

package main
import (
"google.golang.org/protobuf/compiler/protogen"
)
func (g *Generator) microGenerate(component string, plugin *protogen.Plugin) error {
for _, file := range plugin.Files {
if !file.Generate {
continue
}
if len(file.Services) == 0 {
continue
}
gname := file.GeneratedFilenamePrefix + "_" + 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(")")
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(")")
gfile.P()
// generate services
for _, service := range file.Services {
generateServiceEndpoints(gfile, service)
generateServiceClientInterface(gfile, service)
generateServiceClientStreamInterface(gfile, service)
generateServiceServerInterface(gfile, service)
generateServiceServerStreamInterface(gfile, service)
}
}
return nil
}