From 84a677b6d1648605d9148107cc910d298006fd05 Mon Sep 17 00:00:00 2001 From: Raphael Simon Date: Fri, 5 Jul 2024 14:05:00 -0700 Subject: [PATCH] Fix example generation so the code uses the clue logger --- codegen/service/example_svc.go | 1 + codegen/service/templates/endpoint.go.tpl | 2 +- codegen/service/templates/service_init.go.tpl | 4 ++-- codegen/service/templates/service_struct.go.tpl | 4 +--- grpc/codegen/templates/server_grpc_end.go.tpl | 2 +- grpc/codegen/testdata/server-no-server.golden | 2 +- .../testdata/server-server-hosting-multiple-services.golden | 2 +- .../testdata/server-server-hosting-service-subset.golden | 2 +- 8 files changed, 9 insertions(+), 10 deletions(-) diff --git a/codegen/service/example_svc.go b/codegen/service/example_svc.go index 7b63b70b86..4d8cc7c40d 100644 --- a/codegen/service/example_svc.go +++ b/codegen/service/example_svc.go @@ -72,6 +72,7 @@ func exampleServiceFile(genpkg string, _ *expr.RootExpr, svc *expr.ServiceExpr, {Path: "fmt"}, {Path: "strings"}, {Path: path.Join(genpkg, svcName), Name: data.PkgName}, + {Path: "goa.design/clue/log"}, {Path: "goa.design/goa/v3/security"}, } sections := []*codegen.SectionTemplate{ diff --git a/codegen/service/templates/endpoint.go.tpl b/codegen/service/templates/endpoint.go.tpl index b11ad78bde..8b4222f1d1 100644 --- a/codegen/service/templates/endpoint.go.tpl +++ b/codegen/service/templates/endpoint.go.tpl @@ -24,6 +24,6 @@ func (s *{{ .ServiceVarName }}srvc) {{ .VarName }}(ctx context.Context{{ if .Pay {{- end }} {{- end }} {{- end }} - s.logger.Print("{{ .ServiceVarName }}.{{ .Name }}") + log.Print(ctx, "{{ .ServiceVarName }}.{{ .Name }}") return } diff --git a/codegen/service/templates/service_init.go.tpl b/codegen/service/templates/service_init.go.tpl index 7569dd2735..0e9a9fca28 100644 --- a/codegen/service/templates/service_init.go.tpl +++ b/codegen/service/templates/service_init.go.tpl @@ -1,4 +1,4 @@ {{ printf "New%s returns the %s service implementation." .StructName .Name | comment }} -func New{{ .StructName }}(logger *log.Logger) {{ .PkgName }}.Service { - return &{{ .VarName }}srvc{logger} +func New{{ .StructName }}() {{ .PkgName }}.Service { + return &{{ .VarName }}srvc{} } diff --git a/codegen/service/templates/service_struct.go.tpl b/codegen/service/templates/service_struct.go.tpl index 405d4c162c..baefc91ddb 100644 --- a/codegen/service/templates/service_struct.go.tpl +++ b/codegen/service/templates/service_struct.go.tpl @@ -1,4 +1,2 @@ {{ printf "%s service example implementation.\nThe example methods log the requests and return zero values." .Name | comment }} -type {{ .VarName }}srvc struct { - logger *log.Logger -} +type {{ .VarName }}srvc struct {} diff --git a/grpc/codegen/templates/server_grpc_end.go.tpl b/grpc/codegen/templates/server_grpc_end.go.tpl index f99557c205..3dccf649d8 100644 --- a/grpc/codegen/templates/server_grpc_end.go.tpl +++ b/grpc/codegen/templates/server_grpc_end.go.tpl @@ -12,7 +12,7 @@ if lis == nil { errc <- fmt.Errorf("failed to listen on %q", u.Host) } - logger.Printf("gRPC server listening on %q", u.Host) + log.Printf(ctx, "gRPC server listening on %q", u.Host) errc <- srv.Serve(lis) }() diff --git a/grpc/codegen/testdata/server-no-server.golden b/grpc/codegen/testdata/server-no-server.golden index 6e0e8f444f..5b125b7f57 100644 --- a/grpc/codegen/testdata/server-no-server.golden +++ b/grpc/codegen/testdata/server-no-server.golden @@ -49,7 +49,7 @@ func handleGRPCServer(ctx context.Context, u *url.URL, serviceEndpoints *service if lis == nil { errc <- fmt.Errorf("failed to listen on %q", u.Host) } - logger.Printf("gRPC server listening on %q", u.Host) + log.Printf(ctx, "gRPC server listening on %q", u.Host) errc <- srv.Serve(lis) }() diff --git a/grpc/codegen/testdata/server-server-hosting-multiple-services.golden b/grpc/codegen/testdata/server-server-hosting-multiple-services.golden index a693a56143..e9311a5676 100644 --- a/grpc/codegen/testdata/server-server-hosting-multiple-services.golden +++ b/grpc/codegen/testdata/server-server-hosting-multiple-services.golden @@ -52,7 +52,7 @@ func handleGRPCServer(ctx context.Context, u *url.URL, serviceEndpoints *service if lis == nil { errc <- fmt.Errorf("failed to listen on %q", u.Host) } - logger.Printf("gRPC server listening on %q", u.Host) + log.Printf(ctx, "gRPC server listening on %q", u.Host) errc <- srv.Serve(lis) }() diff --git a/grpc/codegen/testdata/server-server-hosting-service-subset.golden b/grpc/codegen/testdata/server-server-hosting-service-subset.golden index 6e0e8f444f..5b125b7f57 100644 --- a/grpc/codegen/testdata/server-server-hosting-service-subset.golden +++ b/grpc/codegen/testdata/server-server-hosting-service-subset.golden @@ -49,7 +49,7 @@ func handleGRPCServer(ctx context.Context, u *url.URL, serviceEndpoints *service if lis == nil { errc <- fmt.Errorf("failed to listen on %q", u.Host) } - logger.Printf("gRPC server listening on %q", u.Host) + log.Printf(ctx, "gRPC server listening on %q", u.Host) errc <- srv.Serve(lis) }()