use plain struct for endpoints
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
0e902b1022
commit
dd872a03b3
1
chi.go
1
chi.go
@ -32,6 +32,7 @@ func (g *Generator) chiGenerate(component string, plugin *protogen.Plugin) error
|
||||
|
||||
gfile.P("// Code generated by protoc-gen-go-micro. DO NOT EDIT.")
|
||||
gfile.P("// protoc-gen-go-micro version: " + versionComment)
|
||||
gfile.P()
|
||||
gfile.P("package ", file.GoPackageName)
|
||||
gfile.P()
|
||||
|
||||
|
@ -32,6 +32,7 @@ func (g *Generator) gorillaGenerate(component string, plugin *protogen.Plugin) e
|
||||
|
||||
gfile.P("// Code generated by protoc-gen-go-micro. DO NOT EDIT.")
|
||||
gfile.P("// protoc-gen-go-micro version: " + versionComment)
|
||||
gfile.P()
|
||||
gfile.P("package ", file.GoPackageName)
|
||||
gfile.P()
|
||||
|
||||
|
1
http.go
1
http.go
@ -23,6 +23,7 @@ func (g *Generator) httpGenerate(component string, plugin *protogen.Plugin, genC
|
||||
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()
|
||||
|
||||
|
1
micro.go
1
micro.go
@ -24,6 +24,7 @@ func (g *Generator) microGenerate(component string, plugin *protogen.Plugin, gen
|
||||
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()
|
||||
|
||||
|
1
rpc.go
1
rpc.go
@ -23,6 +23,7 @@ func (g *Generator) rpcGenerate(component string, plugin *protogen.Plugin, genCl
|
||||
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()
|
||||
|
||||
|
15
util.go
15
util.go
@ -284,8 +284,8 @@ func generateServiceRegister(gfile *protogen.GeneratedFile, service *protogen.Se
|
||||
gfile.P("}")
|
||||
gfile.P("h := &", unexport(serviceName), "Server{sh}")
|
||||
gfile.P("var nopts []", microServerPackage.Ident("HandlerOption"))
|
||||
gfile.P("for _, endpoint := range New", serviceName, "Endpoints() {")
|
||||
gfile.P("nopts = append(nopts, ", microApiPackage.Ident("WithEndpoint"), "(endpoint))")
|
||||
gfile.P("for _, endpoint := range ", serviceName, "Endpoints {")
|
||||
gfile.P("nopts = append(nopts, ", microApiPackage.Ident("WithEndpoint"), "(&endpoint))")
|
||||
gfile.P("}")
|
||||
gfile.P("return s.Handle(s.NewHandler(&", serviceName, "{h}, append(nopts, opts...)...))")
|
||||
gfile.P("}")
|
||||
@ -448,8 +448,8 @@ func generateServiceServerStreamInterface(gfile *protogen.GeneratedFile, service
|
||||
|
||||
func generateServiceEndpoints(gfile *protogen.GeneratedFile, service *protogen.Service) {
|
||||
serviceName := service.GoName
|
||||
gfile.P("func New", serviceName, "Endpoints() []*", microApiPackage.Ident("Endpoint"), " {")
|
||||
gfile.P("return []*", microApiPackage.Ident("Endpoint"), "{")
|
||||
gfile.P("var (")
|
||||
gfile.P(serviceName, "Endpoints", "=", "[]", microApiPackage.Ident("Endpoint"), "{")
|
||||
for _, method := range service.Methods {
|
||||
if method.Desc.Options() == nil {
|
||||
continue
|
||||
@ -457,13 +457,18 @@ func generateServiceEndpoints(gfile *protogen.GeneratedFile, service *protogen.S
|
||||
if proto.HasExtension(method.Desc.Options(), api_options.E_Http) {
|
||||
endpoints, streaming := generateEndpoints(method)
|
||||
for _, endpoint := range endpoints {
|
||||
gfile.P("&", microApiPackage.Ident("Endpoint"), "{")
|
||||
gfile.P(microApiPackage.Ident("Endpoint"), "{")
|
||||
generateEndpoint(gfile, serviceName, method.GoName, endpoint, streaming)
|
||||
gfile.P("},")
|
||||
}
|
||||
}
|
||||
}
|
||||
gfile.P("}")
|
||||
gfile.P(")")
|
||||
gfile.P()
|
||||
|
||||
gfile.P("func New", serviceName, "Endpoints()", "[]", microApiPackage.Ident("Endpoint"), "{")
|
||||
gfile.P("return ", serviceName, "Endpoints")
|
||||
gfile.P("}")
|
||||
gfile.P()
|
||||
}
|
||||
|
@ -17,5 +17,5 @@ var (
|
||||
microClientHttpPackage = protogen.GoImportPath("github.com/unistack-org/micro-client-http/v3")
|
||||
timePackage = protogen.GoImportPath("time")
|
||||
deprecationComment = "// Deprecated: Do not use."
|
||||
versionComment = "v3.4.0"
|
||||
versionComment = "v3.4.1"
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user