56 lines
1.3 KiB
Go
Raw Permalink Normal View History

package main
import (
"google.golang.org/protobuf/compiler/protogen"
)
func (g *Generator) httpGenerate(component string, plugin *protogen.Plugin, genClient bool, genServer bool) error {
for _, file := range plugin.Files {
if !file.Generate {
continue
}
if len(file.Services) == 0 {
continue
}
gname := file.GeneratedFilenamePrefix + "_micro_" + component + ".pb.go"
path := file.GoImportPath
if g.standalone {
path = "."
}
gfile := plugin.NewGeneratedFile(gname, path)
gfile.P("// Code generated by protoc-gen-go-micro. DO NOT EDIT.")
gfile.P("// protoc-gen-go-micro version: " + versionComment)
gfile.P("// source: ", file.Proto.GetName())
gfile.P()
gfile.P("package ", file.GoPackageName)
gfile.P()
gfile.Import(contextPackage)
if genClient {
gfile.Import(microClientPackage)
gfile.Import(microClientHttpPackage)
}
if genServer {
gfile.Import(microServerPackage)
}
for _, service := range file.Services {
g.generateServiceEndpoints(gfile, service, component)
if genClient {
g.generateServiceClient(gfile, file, service)
g.generateServiceClientMethods(gfile, service, component)
}
if genServer {
g.generateServiceServer(gfile, file, service)
g.generateServiceServerMethods(gfile, service)
g.generateServiceRegister(gfile, file, service, component)
}
}
}
return nil
}