2021-02-22 18:11:08 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"google.golang.org/protobuf/compiler/protogen"
|
|
|
|
)
|
|
|
|
|
2021-03-26 15:00:55 +03:00
|
|
|
func (g *Generator) microGenerate(component string, plugin *protogen.Plugin, genClient bool, genServer bool) error {
|
2021-02-22 18:11:08 +03:00
|
|
|
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"
|
2021-02-25 14:19:09 +03:00
|
|
|
|
|
|
|
path := file.GoImportPath
|
|
|
|
if g.standalone {
|
|
|
|
path = "."
|
|
|
|
}
|
|
|
|
gfile := plugin.NewGeneratedFile(gname, path)
|
2021-02-22 18:11:08 +03:00
|
|
|
|
2021-06-22 01:34:06 +03:00
|
|
|
gfile.P("// Code generated by protoc-gen-go-micro. DO NOT EDIT.")
|
|
|
|
gfile.P("// protoc-gen-go-micro version: " + versionComment)
|
2021-05-08 00:06:40 +03:00
|
|
|
gfile.P("// source: ", file.Proto.GetName())
|
2021-06-23 00:23:38 +03:00
|
|
|
gfile.P()
|
2021-02-22 18:11:08 +03:00
|
|
|
gfile.P("package ", file.GoPackageName)
|
2021-02-22 23:46:19 +03:00
|
|
|
gfile.P()
|
2021-02-22 18:11:08 +03:00
|
|
|
|
2021-02-23 23:54:53 +03:00
|
|
|
gfile.Import(contextPackage)
|
|
|
|
gfile.Import(microApiPackage)
|
2021-03-26 15:00:55 +03:00
|
|
|
if genClient {
|
|
|
|
gfile.Import(microClientPackage)
|
|
|
|
}
|
2021-02-22 18:11:08 +03:00
|
|
|
// generate services
|
|
|
|
for _, service := range file.Services {
|
2022-03-19 15:13:34 +03:00
|
|
|
g.generateServiceEndpoints(gfile, service)
|
2021-03-26 15:00:55 +03:00
|
|
|
if genClient {
|
2022-03-19 15:13:34 +03:00
|
|
|
g.generateServiceClientInterface(gfile, service)
|
|
|
|
g.generateServiceClientStreamInterface(gfile, service)
|
2021-03-26 15:00:55 +03:00
|
|
|
}
|
|
|
|
if genServer {
|
2022-03-19 15:13:34 +03:00
|
|
|
g.generateServiceServerInterface(gfile, service)
|
|
|
|
g.generateServiceServerStreamInterface(gfile, service)
|
2021-03-26 15:00:55 +03:00
|
|
|
}
|
2021-02-22 18:11:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|