use plain struct for endpoints

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2021-06-23 00:23:38 +03:00
parent 0e902b1022
commit dd872a03b3
7 changed files with 16 additions and 6 deletions

1
chi.go
View File

@ -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("// Code generated by protoc-gen-go-micro. DO NOT EDIT.")
gfile.P("// protoc-gen-go-micro version: " + versionComment) gfile.P("// protoc-gen-go-micro version: " + versionComment)
gfile.P()
gfile.P("package ", file.GoPackageName) gfile.P("package ", file.GoPackageName)
gfile.P() gfile.P()

View File

@ -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("// Code generated by protoc-gen-go-micro. DO NOT EDIT.")
gfile.P("// protoc-gen-go-micro version: " + versionComment) gfile.P("// protoc-gen-go-micro version: " + versionComment)
gfile.P()
gfile.P("package ", file.GoPackageName) gfile.P("package ", file.GoPackageName)
gfile.P() gfile.P()

View File

@ -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("// Code generated by protoc-gen-go-micro. DO NOT EDIT.")
gfile.P("// protoc-gen-go-micro version: " + versionComment) gfile.P("// protoc-gen-go-micro version: " + versionComment)
gfile.P("// source: ", file.Proto.GetName()) gfile.P("// source: ", file.Proto.GetName())
gfile.P()
gfile.P("package ", file.GoPackageName) gfile.P("package ", file.GoPackageName)
gfile.P() gfile.P()

View File

@ -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("// Code generated by protoc-gen-go-micro. DO NOT EDIT.")
gfile.P("// protoc-gen-go-micro version: " + versionComment) gfile.P("// protoc-gen-go-micro version: " + versionComment)
gfile.P("// source: ", file.Proto.GetName()) gfile.P("// source: ", file.Proto.GetName())
gfile.P()
gfile.P("package ", file.GoPackageName) gfile.P("package ", file.GoPackageName)
gfile.P() gfile.P()

1
rpc.go
View File

@ -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("// Code generated by protoc-gen-go-micro. DO NOT EDIT.")
gfile.P("// protoc-gen-go-micro version: " + versionComment) gfile.P("// protoc-gen-go-micro version: " + versionComment)
gfile.P("// source: ", file.Proto.GetName()) gfile.P("// source: ", file.Proto.GetName())
gfile.P()
gfile.P("package ", file.GoPackageName) gfile.P("package ", file.GoPackageName)
gfile.P() gfile.P()

15
util.go
View File

@ -284,8 +284,8 @@ func generateServiceRegister(gfile *protogen.GeneratedFile, service *protogen.Se
gfile.P("}") gfile.P("}")
gfile.P("h := &", unexport(serviceName), "Server{sh}") gfile.P("h := &", unexport(serviceName), "Server{sh}")
gfile.P("var nopts []", microServerPackage.Ident("HandlerOption")) gfile.P("var nopts []", microServerPackage.Ident("HandlerOption"))
gfile.P("for _, endpoint := range New", serviceName, "Endpoints() {") gfile.P("for _, endpoint := range ", serviceName, "Endpoints {")
gfile.P("nopts = append(nopts, ", microApiPackage.Ident("WithEndpoint"), "(endpoint))") gfile.P("nopts = append(nopts, ", microApiPackage.Ident("WithEndpoint"), "(&endpoint))")
gfile.P("}") gfile.P("}")
gfile.P("return s.Handle(s.NewHandler(&", serviceName, "{h}, append(nopts, opts...)...))") gfile.P("return s.Handle(s.NewHandler(&", serviceName, "{h}, append(nopts, opts...)...))")
gfile.P("}") gfile.P("}")
@ -448,8 +448,8 @@ func generateServiceServerStreamInterface(gfile *protogen.GeneratedFile, service
func generateServiceEndpoints(gfile *protogen.GeneratedFile, service *protogen.Service) { func generateServiceEndpoints(gfile *protogen.GeneratedFile, service *protogen.Service) {
serviceName := service.GoName serviceName := service.GoName
gfile.P("func New", serviceName, "Endpoints() []*", microApiPackage.Ident("Endpoint"), " {") gfile.P("var (")
gfile.P("return []*", microApiPackage.Ident("Endpoint"), "{") gfile.P(serviceName, "Endpoints", "=", "[]", microApiPackage.Ident("Endpoint"), "{")
for _, method := range service.Methods { for _, method := range service.Methods {
if method.Desc.Options() == nil { if method.Desc.Options() == nil {
continue continue
@ -457,13 +457,18 @@ func generateServiceEndpoints(gfile *protogen.GeneratedFile, service *protogen.S
if proto.HasExtension(method.Desc.Options(), api_options.E_Http) { if proto.HasExtension(method.Desc.Options(), api_options.E_Http) {
endpoints, streaming := generateEndpoints(method) endpoints, streaming := generateEndpoints(method)
for _, endpoint := range endpoints { for _, endpoint := range endpoints {
gfile.P("&", microApiPackage.Ident("Endpoint"), "{") gfile.P(microApiPackage.Ident("Endpoint"), "{")
generateEndpoint(gfile, serviceName, method.GoName, endpoint, streaming) generateEndpoint(gfile, serviceName, method.GoName, endpoint, streaming)
gfile.P("},") gfile.P("},")
} }
} }
} }
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("}")
gfile.P() gfile.P()
} }

View File

@ -17,5 +17,5 @@ var (
microClientHttpPackage = protogen.GoImportPath("github.com/unistack-org/micro-client-http/v3") microClientHttpPackage = protogen.GoImportPath("github.com/unistack-org/micro-client-http/v3")
timePackage = protogen.GoImportPath("time") timePackage = protogen.GoImportPath("time")
deprecationComment = "// Deprecated: Do not use." deprecationComment = "// Deprecated: Do not use."
versionComment = "v3.4.0" versionComment = "v3.4.1"
) )