Repository: goadesign/goa
Pull request #3547 (2024-07-05 21:05:17)

Fix example generation
so the code uses the clue logger


Patch:
diff --git a/codegen/service/example_svc.go b/codegen/service/example_svc.go
index 7b63b70b..4d8cc7c4 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 b11ad78b..8b4222f1 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 7569dd27..0e9a9fca 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 405d4c16..baefc91d 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 f99557c2..3dccf649 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)
 		}()
 


Test patch:
diff --git a/grpc/codegen/testdata/server-no-server.golden b/grpc/codegen/testdata/server-no-server.golden
index 6e0e8f44..5b125b7f 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 a693a561..e9311a56 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 6e0e8f44..5b125b7f 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)
 		}()