protoc-gen-go-micro/http.go
Vasiliy Tolstov fcd8dd1f7c minor changes for generator
* allow to split client and server generation
* allow to override options for handler

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2021-03-26 15:00:55 +03:00

53 lines
1.2 KiB
Go

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-micro")
gfile.P("// source: ", *file.Proto.Name)
gfile.P("package ", file.GoPackageName)
gfile.P()
gfile.Import(contextPackage)
gfile.Import(microApiPackage)
if genClient {
gfile.Import(microClientPackage)
gfile.Import(microClientHttpPackage)
}
if genServer {
gfile.Import(microServerPackage)
}
for _, service := range file.Services {
if genClient {
generateServiceClient(gfile, service)
generateServiceClientMethods(gfile, service, true)
}
if genServer {
generateServiceServer(gfile, service)
generateServiceServerMethods(gfile, service)
generateServiceRegister(gfile, service)
}
}
}
return nil
}