2021-02-22 18:11:08 +03:00
|
|
|
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
|
|
|
|
}
|
2021-02-22 23:42:49 +03:00
|
|
|
if len(file.Services) == 0 {
|
|
|
|
continue
|
|
|
|
}
|
2021-02-22 18:11:08 +03:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2021-02-22 23:46:19 +03:00
|
|
|
gfile.P()
|
|
|
|
gfile.P("import (")
|
|
|
|
gfile.P(`"context"`)
|
2021-02-23 14:30:23 +03:00
|
|
|
gfile.P()
|
2021-02-22 23:46:19 +03:00
|
|
|
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()
|
2021-02-22 18:11:08 +03:00
|
|
|
|
|
|
|
gfile.P("// Reference imports to suppress errors if they are not otherwise used.")
|
|
|
|
gfile.P("var (")
|
2021-02-22 23:46:19 +03:00
|
|
|
gfile.P("_ ", "micro_api.Endpoint")
|
2021-02-22 18:11:08 +03:00
|
|
|
gfile.P("_ ", "context.Context")
|
2021-02-22 23:46:19 +03:00
|
|
|
gfile.P(" _ ", "micro_client.Option")
|
2021-02-22 18:11:08 +03:00
|
|
|
gfile.P(")")
|
|
|
|
gfile.P()
|
|
|
|
|
|
|
|
// generate services
|
|
|
|
for _, service := range file.Services {
|
2021-02-22 23:42:49 +03:00
|
|
|
generateServiceEndpoints(gfile, service)
|
|
|
|
generateServiceClientInterface(gfile, service)
|
|
|
|
generateServiceClientStreamInterface(gfile, service)
|
|
|
|
generateServiceServerInterface(gfile, service)
|
|
|
|
generateServiceServerStreamInterface(gfile, service)
|
2021-02-22 18:11:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|