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

15
util.go
View File

@@ -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()
}