Skip to content

Commit dbd25d0

Browse files
committed
Fix a generation bug when an interceptor does not have any accessors
- With the change of `goa.InterceptorInfo` from a struct to an interface, the generation of implementation of the interface methods on the generated interceptor info structs became necessary. The code for those methods was included in a section of the template that was conditional on the interceptor having accessors. Now, the conditional has been moved to a more appropriate place so the interface methods are implemented.
1 parent 0094132 commit dbd25d0

7 files changed

+167
-1
lines changed

codegen/service/templates/interceptors.go.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
{{- if hasPrivateImplementationTypes . }}
21
// Public accessor methods for Info types
32
{{- range . }}
43

@@ -149,6 +148,7 @@ func (info *{{ .Name }}Info) ServerStreamingResult() {{ .Name }}StreamingResult
149148
{{- end }}
150149
{{- end }}
151150

151+
{{- if hasPrivateImplementationTypes . }}
152152
// Private implementation methods
153153
{{- range . }}
154154
{{ $interceptor := . }}

codegen/service/testdata/interceptors/multiple-interceptors_client_interceptors.go.golden

+41
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,44 @@ func WrapMethodClientEndpoint(endpoint goa.Endpoint, i ClientInterceptors) goa.E
3535
return endpoint
3636
}
3737

38+
// Public accessor methods for Info types
39+
40+
// Service returns the name of the service handling the request.
41+
func (info *Test2Info) Service() string {
42+
return info.service
43+
}
44+
45+
// Method returns the name of the method handling the request.
46+
func (info *Test2Info) Method() string {
47+
return info.method
48+
}
49+
50+
// CallType returns the type of call the interceptor is handling.
51+
func (info *Test2Info) CallType() goa.InterceptorCallType {
52+
return info.callType
53+
}
54+
55+
// RawPayload returns the raw payload of the request.
56+
func (info *Test2Info) RawPayload() any {
57+
return info.rawPayload
58+
}
59+
60+
// Service returns the name of the service handling the request.
61+
func (info *Test4Info) Service() string {
62+
return info.service
63+
}
64+
65+
// Method returns the name of the method handling the request.
66+
func (info *Test4Info) Method() string {
67+
return info.method
68+
}
69+
70+
// CallType returns the type of call the interceptor is handling.
71+
func (info *Test4Info) CallType() goa.InterceptorCallType {
72+
return info.callType
73+
}
74+
75+
// RawPayload returns the raw payload of the request.
76+
func (info *Test4Info) RawPayload() any {
77+
return info.rawPayload
78+
}

codegen/service/testdata/interceptors/multiple-interceptors_service_interceptors.go.golden

+41
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,44 @@ func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoin
3535
return endpoint
3636
}
3737

38+
// Public accessor methods for Info types
39+
40+
// Service returns the name of the service handling the request.
41+
func (info *TestInfo) Service() string {
42+
return info.service
43+
}
44+
45+
// Method returns the name of the method handling the request.
46+
func (info *TestInfo) Method() string {
47+
return info.method
48+
}
49+
50+
// CallType returns the type of call the interceptor is handling.
51+
func (info *TestInfo) CallType() goa.InterceptorCallType {
52+
return info.callType
53+
}
54+
55+
// RawPayload returns the raw payload of the request.
56+
func (info *TestInfo) RawPayload() any {
57+
return info.rawPayload
58+
}
59+
60+
// Service returns the name of the service handling the request.
61+
func (info *Test3Info) Service() string {
62+
return info.service
63+
}
64+
65+
// Method returns the name of the method handling the request.
66+
func (info *Test3Info) Method() string {
67+
return info.method
68+
}
69+
70+
// CallType returns the type of call the interceptor is handling.
71+
func (info *Test3Info) CallType() goa.InterceptorCallType {
72+
return info.callType
73+
}
74+
75+
// RawPayload returns the raw payload of the request.
76+
func (info *Test3Info) RawPayload() any {
77+
return info.rawPayload
78+
}

codegen/service/testdata/interceptors/single-api-server-interceptor_service_interceptors.go.golden

+21
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,24 @@ func WrapMethod2Endpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoi
3232
return endpoint
3333
}
3434

35+
// Public accessor methods for Info types
36+
37+
// Service returns the name of the service handling the request.
38+
func (info *LoggingInfo) Service() string {
39+
return info.service
40+
}
41+
42+
// Method returns the name of the method handling the request.
43+
func (info *LoggingInfo) Method() string {
44+
return info.method
45+
}
46+
47+
// CallType returns the type of call the interceptor is handling.
48+
func (info *LoggingInfo) CallType() goa.InterceptorCallType {
49+
return info.callType
50+
}
51+
52+
// RawPayload returns the raw payload of the request.
53+
func (info *LoggingInfo) RawPayload() any {
54+
return info.rawPayload
55+
}

codegen/service/testdata/interceptors/single-client-interceptor_client_interceptors.go.golden

+21
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,24 @@ func WrapMethodClientEndpoint(endpoint goa.Endpoint, i ClientInterceptors) goa.E
2525
return endpoint
2626
}
2727

28+
// Public accessor methods for Info types
29+
30+
// Service returns the name of the service handling the request.
31+
func (info *TracingInfo) Service() string {
32+
return info.service
33+
}
34+
35+
// Method returns the name of the method handling the request.
36+
func (info *TracingInfo) Method() string {
37+
return info.method
38+
}
39+
40+
// CallType returns the type of call the interceptor is handling.
41+
func (info *TracingInfo) CallType() goa.InterceptorCallType {
42+
return info.callType
43+
}
44+
45+
// RawPayload returns the raw payload of the request.
46+
func (info *TracingInfo) RawPayload() any {
47+
return info.rawPayload
48+
}

codegen/service/testdata/interceptors/single-method-server-interceptor_service_interceptors.go.golden

+21
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,24 @@ func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoin
2525
return endpoint
2626
}
2727

28+
// Public accessor methods for Info types
29+
30+
// Service returns the name of the service handling the request.
31+
func (info *LoggingInfo) Service() string {
32+
return info.service
33+
}
34+
35+
// Method returns the name of the method handling the request.
36+
func (info *LoggingInfo) Method() string {
37+
return info.method
38+
}
39+
40+
// CallType returns the type of call the interceptor is handling.
41+
func (info *LoggingInfo) CallType() goa.InterceptorCallType {
42+
return info.callType
43+
}
44+
45+
// RawPayload returns the raw payload of the request.
46+
func (info *LoggingInfo) RawPayload() any {
47+
return info.rawPayload
48+
}

codegen/service/testdata/interceptors/single-service-server-interceptor_service_interceptors.go.golden

+21
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,24 @@ func WrapMethod2Endpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoi
3232
return endpoint
3333
}
3434

35+
// Public accessor methods for Info types
36+
37+
// Service returns the name of the service handling the request.
38+
func (info *LoggingInfo) Service() string {
39+
return info.service
40+
}
41+
42+
// Method returns the name of the method handling the request.
43+
func (info *LoggingInfo) Method() string {
44+
return info.method
45+
}
46+
47+
// CallType returns the type of call the interceptor is handling.
48+
func (info *LoggingInfo) CallType() goa.InterceptorCallType {
49+
return info.callType
50+
}
51+
52+
// RawPayload returns the raw payload of the request.
53+
func (info *LoggingInfo) RawPayload() any {
54+
return info.rawPayload
55+
}

0 commit comments

Comments
 (0)