Skip to content

Commit 8035d69

Browse files
committed
Separate StreamingPayload and StreamingResult methods to Client and Server variations
1 parent c36dfb6 commit 8035d69

File tree

37 files changed

+286
-230
lines changed

37 files changed

+286
-230
lines changed

codegen/service/templates/client_interceptor_wrappers.go.tpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func wrapClient{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Interceptor
1111
service: "{{ $.Service }}",
1212
method: "{{ .MethodName }}",
1313
callType: goa.InterceptorUnary,
14-
payload: req,
14+
rawPayload: req,
1515
}
1616
res, ctx, err := i.{{ $interceptor.Name }}(ctx, info, endpoint)
1717
{{- else }}
@@ -29,7 +29,7 @@ func wrapClient{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Interceptor
2929
service: "{{ $.Service }}",
3030
method: "{{ .MethodName }}",
3131
callType: goa.InterceptorStreamingSend,
32-
payload: req,
32+
rawPayload: req,
3333
}
3434
_, ctx, err := i.{{ $interceptor.Name }}(ctx, info, func(ctx context.Context, req any) (any, context.Context, error) {
3535
castReq, _ := req.({{ .ClientStream.SendTypeRef }})
@@ -60,7 +60,7 @@ func wrapClient{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Interceptor
6060
service: "{{ $.Service }}",
6161
method: "{{ .MethodName }}",
6262
callType: goa.InterceptorUnary,
63-
payload: req,
63+
rawPayload: req,
6464
}
6565
return i.{{ $interceptor.Name }}(ctx, info, endpoint)
6666
{{- end }}

codegen/service/templates/interceptors.go.tpl

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func (info *{{ .Name }}Info) CallType() goa.InterceptorCallType {
1919

2020
// RawPayload returns the raw payload of the request.
2121
func (info *{{ .Name }}Info) RawPayload() any {
22-
return info.payload
22+
return info.rawPayload
2323
}
2424
{{- if .HasPayloadAccess }}
2525

@@ -59,8 +59,8 @@ func (info *{{ .Name }}Info) Result(res any) {{ .Name }}Result {
5959
{{- end }}
6060

6161
{{- if .HasStreamingPayloadAccess }}
62-
// StreamingPayload returns a type-safe accessor for the method streaming payload.
63-
func (info *{{ .Name }}Info) StreamingPayload() {{ .Name }}StreamingPayload {
62+
// ClientStreamingPayload returns a type-safe accessor for the method streaming payload for a client-side interceptor.
63+
func (info *{{ .Name }}Info) ClientStreamingPayload() {{ .Name }}StreamingPayload {
6464
{{- if gt (len .Methods) 1 }}
6565
switch info.Method() {
6666
{{- range .Methods }}
@@ -77,8 +77,8 @@ func (info *{{ .Name }}Info) StreamingPayload() {{ .Name }}StreamingPayload {
7777
{{- end }}
7878

7979
{{- if .HasStreamingResultAccess }}
80-
// StreamingResult returns a type-safe accessor for the method streaming result.
81-
func (info *{{ .Name }}Info) StreamingResult(res any) {{ .Name }}StreamingResult {
80+
// ClientStreamingResult returns a type-safe accessor for the method streaming result for a client-side interceptor.
81+
func (info *{{ .Name }}Info) ClientStreamingResult(res any) {{ .Name }}StreamingResult {
8282
{{- if gt (len .Methods) 1 }}
8383
switch info.Method() {
8484
{{- range .Methods }}
@@ -91,6 +91,42 @@ func (info *{{ .Name }}Info) StreamingResult(res any) {{ .Name }}StreamingResult
9191
{{- else }}
9292
return &{{ (index .Methods 0).StreamingResultAccess }}{result: res.({{ (index .Methods 0).StreamingResultRef }})}
9393
{{- end }}
94+
}
95+
{{- end }}
96+
97+
{{- if .HasStreamingPayloadAccess }}
98+
// ServerStreamingPayload returns a type-safe accessor for the method streaming payload for a server-side interceptor.
99+
func (info *{{ .Name }}Info) ServerStreamingPayload(pay any) {{ .Name }}StreamingPayload {
100+
{{- if gt (len .Methods) 1 }}
101+
switch info.Method() {
102+
{{- range .Methods }}
103+
case "{{ .MethodName }}":
104+
return &{{ .StreamingPayloadAccess }}{payload: pay.({{ .StreamingPayloadRef }})}
105+
{{- end }}
106+
default:
107+
return nil
108+
}
109+
{{- else }}
110+
return &{{ (index .Methods 0).StreamingPayloadAccess }}{payload: pay.({{ (index .Methods 0).StreamingPayloadRef }})}
111+
{{- end }}
112+
}
113+
{{- end }}
114+
115+
{{- if .HasStreamingResultAccess }}
116+
// ServerStreamingResult returns a type-safe accessor for the method streaming result for a server-side interceptor.
117+
func (info *{{ .Name }}Info) ServerStreamingResult() {{ .Name }}StreamingResult {
118+
{{- if gt (len .Methods) 1 }}
119+
switch info.Method() {
120+
{{- range .Methods }}
121+
case "{{ .MethodName }}":
122+
return &{{ .StreamingResultAccess }}{result: info.RawPayload().({{ .StreamingResultRef }})}
123+
{{- end }}
124+
default:
125+
return nil
126+
}
127+
{{- else }}
128+
return &{{ (index .Methods 0).StreamingResultAccess }}{result: info.RawPayload().({{ (index .Methods 0).StreamingResultRef }})}
129+
{{- end }}
94130
}
95131
{{- end }}
96132
{{- end }}

codegen/service/templates/interceptors_types.go.tpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ type (
55
// {{ .Name }}Info provides metadata about the current interception.
66
// It includes service name, method name, and access to the endpoint.
77
{{ .Name }}Info struct {
8-
service string
9-
method string
10-
callType goa.InterceptorCallType
11-
payload any
8+
service string
9+
method string
10+
callType goa.InterceptorCallType
11+
rawPayload any
1212
}
1313
{{- if .HasPayloadAccess }}
1414

codegen/service/templates/server_interceptor_wrappers.go.tpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func wrap{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.InterceptorEndpoi
1111
service: "{{ $.Service }}",
1212
method: "{{ .MethodName }}",
1313
callType: goa.InterceptorUnary,
14-
payload: req,
14+
rawPayload: req,
1515
}
1616
res, ctx, err := i.{{ $interceptor.Name }}(ctx, info, endpoint)
1717
{{- else }}
@@ -29,7 +29,7 @@ func wrap{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.InterceptorEndpoi
2929
service: "{{ $.Service }}",
3030
method: "{{ .MethodName }}",
3131
callType: goa.InterceptorStreamingSend,
32-
payload: req,
32+
rawPayload: req,
3333
}
3434
_, ctx, err := i.{{ $interceptor.Name }}(ctx, info, func(ctx context.Context, req any) (any, context.Context, error) {
3535
castReq, _ := req.({{ .ServerStream.SendTypeRef }})
@@ -60,7 +60,7 @@ func wrap{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.InterceptorEndpoi
6060
service: "{{ $.Service }}",
6161
method: "{{ .MethodName }}",
6262
callType: goa.InterceptorUnary,
63-
payload: req,
63+
rawPayload: req,
6464
}
6565
return i.{{ $interceptor.Name }}(ctx, info, endpoint)
6666
{{- end }}

codegen/service/testdata/interceptors/interceptor-with-read-payload_interceptor_wrappers.go.golden

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
func wrapMethodValidation(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint {
55
return func(ctx context.Context, req any) (any, context.Context, error) {
66
info := &ValidationInfo{
7-
service: "InterceptorWithReadPayload",
8-
method: "Method",
9-
callType: goa.InterceptorUnary,
10-
payload: req,
7+
service: "InterceptorWithReadPayload",
8+
method: "Method",
9+
callType: goa.InterceptorUnary,
10+
rawPayload: req,
1111
}
1212
return i.Validation(ctx, info, endpoint)
1313
}
@@ -18,10 +18,10 @@ func wrapMethodValidation(endpoint goa.InterceptorEndpoint, i ServerInterceptors
1818
func wrapClientMethodValidation(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint {
1919
return func(ctx context.Context, req any) (any, context.Context, error) {
2020
info := &ValidationInfo{
21-
service: "InterceptorWithReadPayload",
22-
method: "Method",
23-
callType: goa.InterceptorUnary,
24-
payload: req,
21+
service: "InterceptorWithReadPayload",
22+
method: "Method",
23+
callType: goa.InterceptorUnary,
24+
rawPayload: req,
2525
}
2626
return i.Validation(ctx, info, endpoint)
2727
}

codegen/service/testdata/interceptors/interceptor-with-read-payload_service_interceptors.go.golden

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ type (
1111
// ValidationInfo provides metadata about the current interception.
1212
// It includes service name, method name, and access to the endpoint.
1313
ValidationInfo struct {
14-
service string
15-
method string
16-
callType goa.InterceptorCallType
17-
payload any
14+
service string
15+
method string
16+
callType goa.InterceptorCallType
17+
rawPayload any
1818
}
1919

2020
// ValidationPayload provides type-safe access to the method payload.
@@ -65,7 +65,7 @@ func (info *ValidationInfo) CallType() goa.InterceptorCallType {
6565

6666
// RawPayload returns the raw payload of the request.
6767
func (info *ValidationInfo) RawPayload() any {
68-
return info.payload
68+
return info.rawPayload
6969
}
7070

7171
// Payload returns a type-safe accessor for the method payload.

codegen/service/testdata/interceptors/interceptor-with-read-result_interceptor_wrappers.go.golden

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
func wrapMethodCaching(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint {
55
return func(ctx context.Context, req any) (any, context.Context, error) {
66
info := &CachingInfo{
7-
service: "InterceptorWithReadResult",
8-
method: "Method",
9-
callType: goa.InterceptorUnary,
10-
payload: req,
7+
service: "InterceptorWithReadResult",
8+
method: "Method",
9+
callType: goa.InterceptorUnary,
10+
rawPayload: req,
1111
}
1212
return i.Caching(ctx, info, endpoint)
1313
}
@@ -17,10 +17,10 @@ func wrapMethodCaching(endpoint goa.InterceptorEndpoint, i ServerInterceptors) g
1717
func wrapClientMethodCaching(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint {
1818
return func(ctx context.Context, req any) (any, context.Context, error) {
1919
info := &CachingInfo{
20-
service: "InterceptorWithReadResult",
21-
method: "Method",
22-
callType: goa.InterceptorUnary,
23-
payload: req,
20+
service: "InterceptorWithReadResult",
21+
method: "Method",
22+
callType: goa.InterceptorUnary,
23+
rawPayload: req,
2424
}
2525
return i.Caching(ctx, info, endpoint)
2626
}

codegen/service/testdata/interceptors/interceptor-with-read-result_service_interceptors.go.golden

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ type (
1111
// CachingInfo provides metadata about the current interception.
1212
// It includes service name, method name, and access to the endpoint.
1313
CachingInfo struct {
14-
service string
15-
method string
16-
callType goa.InterceptorCallType
17-
payload any
14+
service string
15+
method string
16+
callType goa.InterceptorCallType
17+
rawPayload any
1818
}
1919

2020
// CachingResult provides type-safe access to the method result.
@@ -65,7 +65,7 @@ func (info *CachingInfo) CallType() goa.InterceptorCallType {
6565

6666
// RawPayload returns the raw payload of the request.
6767
func (info *CachingInfo) RawPayload() any {
68-
return info.payload
68+
return info.rawPayload
6969
}
7070

7171
// Result returns a type-safe accessor for the method result.

codegen/service/testdata/interceptors/interceptor-with-read-write-payload_interceptor_wrappers.go.golden

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
func wrapMethodValidation(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint {
55
return func(ctx context.Context, req any) (any, context.Context, error) {
66
info := &ValidationInfo{
7-
service: "InterceptorWithReadWritePayload",
8-
method: "Method",
9-
callType: goa.InterceptorUnary,
10-
payload: req,
7+
service: "InterceptorWithReadWritePayload",
8+
method: "Method",
9+
callType: goa.InterceptorUnary,
10+
rawPayload: req,
1111
}
1212
return i.Validation(ctx, info, endpoint)
1313
}
@@ -18,10 +18,10 @@ func wrapMethodValidation(endpoint goa.InterceptorEndpoint, i ServerInterceptors
1818
func wrapClientMethodValidation(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint {
1919
return func(ctx context.Context, req any) (any, context.Context, error) {
2020
info := &ValidationInfo{
21-
service: "InterceptorWithReadWritePayload",
22-
method: "Method",
23-
callType: goa.InterceptorUnary,
24-
payload: req,
21+
service: "InterceptorWithReadWritePayload",
22+
method: "Method",
23+
callType: goa.InterceptorUnary,
24+
rawPayload: req,
2525
}
2626
return i.Validation(ctx, info, endpoint)
2727
}

codegen/service/testdata/interceptors/interceptor-with-read-write-payload_service_interceptors.go.golden

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ type (
1111
// ValidationInfo provides metadata about the current interception.
1212
// It includes service name, method name, and access to the endpoint.
1313
ValidationInfo struct {
14-
service string
15-
method string
16-
callType goa.InterceptorCallType
17-
payload any
14+
service string
15+
method string
16+
callType goa.InterceptorCallType
17+
rawPayload any
1818
}
1919

2020
// ValidationPayload provides type-safe access to the method payload.
@@ -66,7 +66,7 @@ func (info *ValidationInfo) CallType() goa.InterceptorCallType {
6666

6767
// RawPayload returns the raw payload of the request.
6868
func (info *ValidationInfo) RawPayload() any {
69-
return info.payload
69+
return info.rawPayload
7070
}
7171

7272
// Payload returns a type-safe accessor for the method payload.

codegen/service/testdata/interceptors/interceptor-with-read-write-result_interceptor_wrappers.go.golden

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
func wrapMethodCaching(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint {
55
return func(ctx context.Context, req any) (any, context.Context, error) {
66
info := &CachingInfo{
7-
service: "InterceptorWithReadWriteResult",
8-
method: "Method",
9-
callType: goa.InterceptorUnary,
10-
payload: req,
7+
service: "InterceptorWithReadWriteResult",
8+
method: "Method",
9+
callType: goa.InterceptorUnary,
10+
rawPayload: req,
1111
}
1212
return i.Caching(ctx, info, endpoint)
1313
}
@@ -17,10 +17,10 @@ func wrapMethodCaching(endpoint goa.InterceptorEndpoint, i ServerInterceptors) g
1717
func wrapClientMethodCaching(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint {
1818
return func(ctx context.Context, req any) (any, context.Context, error) {
1919
info := &CachingInfo{
20-
service: "InterceptorWithReadWriteResult",
21-
method: "Method",
22-
callType: goa.InterceptorUnary,
23-
payload: req,
20+
service: "InterceptorWithReadWriteResult",
21+
method: "Method",
22+
callType: goa.InterceptorUnary,
23+
rawPayload: req,
2424
}
2525
return i.Caching(ctx, info, endpoint)
2626
}

codegen/service/testdata/interceptors/interceptor-with-read-write-result_service_interceptors.go.golden

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ type (
1111
// CachingInfo provides metadata about the current interception.
1212
// It includes service name, method name, and access to the endpoint.
1313
CachingInfo struct {
14-
service string
15-
method string
16-
callType goa.InterceptorCallType
17-
payload any
14+
service string
15+
method string
16+
callType goa.InterceptorCallType
17+
rawPayload any
1818
}
1919

2020
// CachingResult provides type-safe access to the method result.
@@ -66,7 +66,7 @@ func (info *CachingInfo) CallType() goa.InterceptorCallType {
6666

6767
// RawPayload returns the raw payload of the request.
6868
func (info *CachingInfo) RawPayload() any {
69-
return info.payload
69+
return info.rawPayload
7070
}
7171

7272
// Result returns a type-safe accessor for the method result.

codegen/service/testdata/interceptors/interceptor-with-write-payload_interceptor_wrappers.go.golden

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
func wrapMethodValidation(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint {
55
return func(ctx context.Context, req any) (any, context.Context, error) {
66
info := &ValidationInfo{
7-
service: "InterceptorWithWritePayload",
8-
method: "Method",
9-
callType: goa.InterceptorUnary,
10-
payload: req,
7+
service: "InterceptorWithWritePayload",
8+
method: "Method",
9+
callType: goa.InterceptorUnary,
10+
rawPayload: req,
1111
}
1212
return i.Validation(ctx, info, endpoint)
1313
}
@@ -18,10 +18,10 @@ func wrapMethodValidation(endpoint goa.InterceptorEndpoint, i ServerInterceptors
1818
func wrapClientMethodValidation(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint {
1919
return func(ctx context.Context, req any) (any, context.Context, error) {
2020
info := &ValidationInfo{
21-
service: "InterceptorWithWritePayload",
22-
method: "Method",
23-
callType: goa.InterceptorUnary,
24-
payload: req,
21+
service: "InterceptorWithWritePayload",
22+
method: "Method",
23+
callType: goa.InterceptorUnary,
24+
rawPayload: req,
2525
}
2626
return i.Validation(ctx, info, endpoint)
2727
}

0 commit comments

Comments
 (0)