diff --git a/chi.go b/chi.go index bf7ddf9..b0b96a6 100644 --- a/chi.go +++ b/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() diff --git a/gorilla.go b/gorilla.go index 5b812ca..6147cdd 100644 --- a/gorilla.go +++ b/gorilla.go @@ -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() diff --git a/http.go b/http.go index 2e992b3..03cdaf3 100644 --- a/http.go +++ b/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() diff --git a/micro.go b/micro.go index 1235978..0daf737 100644 --- a/micro.go +++ b/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() diff --git a/rpc.go b/rpc.go index 3143249..157114c 100644 --- a/rpc.go +++ b/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() diff --git a/util.go b/util.go index 94a640c..003b058 100644 --- a/util.go +++ b/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() } diff --git a/variables.go b/variables.go index bff2c10..ef57f27 100644 --- a/variables.go +++ b/variables.go @@ -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" )