From 9f853b800fd3ab84a6e97cc1854bfa561f2fdb6c Mon Sep 17 00:00:00 2001 From: Douglas Thrift Date: Thu, 23 Jan 2025 17:48:18 -0800 Subject: [PATCH 01/23] Add read/write streaming payload/result methods to interceptor DSL --- codegen/service/service_data.go | 2 +- dsl/api.go | 12 ++-- dsl/http.go | 4 +- dsl/interceptor.go | 100 ++++++++++++++++++++++++++++++-- dsl/result_type.go | 2 +- dsl/security.go | 2 +- dsl/server.go | 2 +- expr/api.go | 2 +- expr/http_endpoint.go | 2 +- expr/interceptor.go | 8 +++ 10 files changed, 118 insertions(+), 18 deletions(-) diff --git a/codegen/service/service_data.go b/codegen/service/service_data.go index 7270e1e49b..bbdf955c3d 100644 --- a/codegen/service/service_data.go +++ b/codegen/service/service_data.go @@ -2093,7 +2093,7 @@ func walkViewAttrs(obj *expr.Object, view *expr.ViewExpr, walker func(name strin } // removeMeta removes the meta attributes from the given attribute. This is -// needed to make sure that any field name overridding is removed when +// needed to make sure that any field name overriding is removed when // generating protobuf types (as protogen itself won't honor these overrides). func removeMeta(att *expr.AttributeExpr) { _ = codegen.Walk(att, func(a *expr.AttributeExpr) error { diff --git a/dsl/api.go b/dsl/api.go index e34a4326b5..1cc7b9afe2 100644 --- a/dsl/api.go +++ b/dsl/api.go @@ -56,7 +56,7 @@ func API(name string, fn func()) *expr.APIExpr { // Title sets the API title. It is used by the generated OpenAPI specification. // -// Title must appear in a API expression. +// Title must appear in an API expression. // // Title accepts a single string argument. // @@ -75,7 +75,7 @@ func Title(val string) { // Version specifies the API version. One design describes one version. // -// Version must appear in a API expression. +// Version must appear in an API expression. // // Version accepts a single string argument. // @@ -94,7 +94,7 @@ func Version(ver string) { // Contact sets the API contact information. // -// Contact must appear in a API expression. +// Contact must appear in an API expression. // // Contact takes a single argument which is the defining DSL. // @@ -121,7 +121,7 @@ func Contact(fn func()) { // License sets the API license information. // -// License must appear in a API expression. +// License must appear in an API expression. // // License takes a single argument which is the defining DSL. // @@ -147,7 +147,7 @@ func License(fn func()) { // Randomizer sets the API example randomizer. // -// Randomizer must appear in a API expression. +// Randomizer must appear in an API expression. // // Randomizer takes a single argument which is an implementation of // expr.Randomizer. @@ -215,7 +215,7 @@ func Docs(fn func()) { // TermsOfService describes the API terms of services or links to them. // -// TermsOfService must appear in a API expression. +// TermsOfService must appear in an API expression. // // TermsOfService takes a single argument which is the TOS text or URL. // diff --git a/dsl/http.go b/dsl/http.go index fe26072d87..826d6f5335 100644 --- a/dsl/http.go +++ b/dsl/http.go @@ -233,7 +233,7 @@ func Produces(args ...string) { // As a special case, if you want to generate a path with a trailing slash, you can use // GET("/./") to generate a path such as '/foo/'. // -// Path must appear in a API HTTP expression or a Service HTTP expression. +// Path must appear in an API HTTP expression or a Service HTTP expression. // // Path accepts one argument: the HTTP path prefix. func Path(val string) { @@ -1166,7 +1166,7 @@ func cookies(exp eval.Expression) *expr.MappedAttributeExpr { } // params returns the mapped attribute containing the path and query params for -// the given expression if it's either the root, a API server, a service or an +// the given expression if it's either the root, an API server, a service or an // endpoint - nil otherwise. func params(exp eval.Expression) *expr.MappedAttributeExpr { switch e := exp.(type) { diff --git a/dsl/interceptor.go b/dsl/interceptor.go index fdb42fa1b8..44de81370a 100644 --- a/dsl/interceptor.go +++ b/dsl/interceptor.go @@ -8,7 +8,7 @@ import ( // Interceptor defines a request interceptor. Interceptors provide a type-safe way // to read and write from and to the request and response. // -// Interceptor must appear in a API, Service or Method expression. +// Interceptor must appear in an API, Service or Method expression. // // Interceptor accepts two arguments: the name of the interceptor and the // defining DSL. @@ -143,10 +143,102 @@ func WriteResult(arg any) { }) } +// ReadStreamingPayload defines the streaming payload attributes read by the interceptor. +// +// ReadStreamingPayload must appear in an interceptor DSL. +// +// ReadStreamingPayload takes a function as argument which can use the Attribute DSL to +// define the attributes read by the interceptor. +// +// Example: +// +// ReadStreamingPayload(func() { +// Attribute("id") +// }) +// +// ReadStreamingPayload also accepts user defined types: +// +// // Interceptor can read any streaming payload field +// ReadStreamingPayload(MethodStreamingPayload) +func ReadStreamingPayload(arg any) { + setInterceptorAttribute(arg, func(i *expr.InterceptorExpr, attr *expr.AttributeExpr) { + i.ReadStreamingPayload = attr + }) +} + +// WriteStreamingPayload defines the streaming payload attributes written by the interceptor. +// +// WriteStreamingPayload must appear in an interceptor DSL. +// +// WriteStreamingPayload takes a function as argument which can use the Attribute DSL to +// define the attributes written by the interceptor. +// +// Example: +// +// WriteStreamingPayload(func() { +// Attribute("id") +// }) +// +// WriteStreamingPayload also accepts user defined types: +// +// // Interceptor can write any streaming payload field +// WriteStreamingPayload(MethodStreamingPayload) +func WriteStreamingPayload(arg any) { + setInterceptorAttribute(arg, func(i *expr.InterceptorExpr, attr *expr.AttributeExpr) { + i.WriteStreamingPayload = attr + }) +} + +// ReadStreamingResult defines the streaming result attributes read by the interceptor. +// +// ReadStreamingResult must appear in an interceptor DSL. +// +// ReadStreamingResult takes a function as argument which can use the Attribute DSL to +// define the attributes read by the interceptor. +// +// Example: +// +// ReadStreamingResult(func() { +// Attribute("cachedAt") +// }) +// +// ReadStreamingResult also accepts user defined types: +// +// // Interceptor can read any streaming result field +// ReadStreamingResult(MethodStreamingResult) +func ReadStreamingResult(arg any) { + setInterceptorAttribute(arg, func(i *expr.InterceptorExpr, attr *expr.AttributeExpr) { + i.ReadStreamingResult = attr + }) +} + +// WriteStreamingResult defines the streaming result attributes written by the interceptor. +// +// WriteStreamingResult must appear in an interceptor DSL. +// +// WriteStreamingResult takes a function as argument which can use the Attribute DSL to +// define the attributes written by the interceptor. +// +// Example: +// +// WriteStreamingResult(func() { +// Attribute("cachedAt") +// }) +// +// WriteStreamingResult also accepts user defined types: +// +// // Interceptor can write any streaming result field +// WriteStreamingResult(MethodStreamingResult) +func WriteStreamingResult(arg any) { + setInterceptorAttribute(arg, func(i *expr.InterceptorExpr, attr *expr.AttributeExpr) { + i.WriteStreamingResult = attr + }) +} + // ServerInterceptor lists the server-side interceptors that apply to all the // API endpoints, all the service endpoints or a specific endpoint. // -// ServerInterceptor must appear in a API, Service or Method expression. +// ServerInterceptor must appear in an API, Service or Method expression. // // ServerInterceptor accepts one or more interceptor or interceptor names as // arguments. ServerInterceptor can appear multiple times in the same DSL. @@ -176,7 +268,7 @@ func ServerInterceptor(interceptors ...any) { // ClientInterceptor lists the client-side interceptors that apply to all the // API endpoints, all the service endpoints or a specific endpoint. // -// ClientInterceptor must appear in a API, Service or Method expression. +// ClientInterceptor must appear in an API, Service or Method expression. // // ClientInterceptor accepts one or more interceptor or interceptor names as // arguments. ClientInterceptor can appear multiple times in the same DSL. @@ -207,7 +299,7 @@ func ClientInterceptor(interceptors ...any) { } // setInterceptorAttribute is a helper function that handles the common logic for -// setting interceptor attributes (ReadPayload, WritePayload, ReadResult, WriteResult). +// setting interceptor attributes (ReadPayload, WritePayload, ReadResult, WriteResult, ReadStreamingPayload, WriteStreamingPayload, ReadStreamingResult, WriteStreamingResult). func setInterceptorAttribute(arg any, setter func(i *expr.InterceptorExpr, attr *expr.AttributeExpr)) { i, ok := eval.Current().(*expr.InterceptorExpr) if !ok { diff --git a/dsl/result_type.go b/dsl/result_type.go index d8e503b9e1..3bafe7c769 100644 --- a/dsl/result_type.go +++ b/dsl/result_type.go @@ -451,7 +451,7 @@ func Reference(t expr.DataType) { // }) // }) // -// var UpdateBottlePayload = Type("UpatePayload", func() { +// var UpdateBottlePayload = Type("UpdatePayload", func() { // Attribute("id", String, "ID of bottle to update") // Extend(CreateBottlePayload) // Adds attributes "name" and "vintage" // }) diff --git a/dsl/security.go b/dsl/security.go index 76aab1d8cb..0af951b22e 100644 --- a/dsl/security.go +++ b/dsl/security.go @@ -186,7 +186,7 @@ func JWTSecurity(name string, fn ...func()) *expr.SchemeExpr { // in the same scope in which case the client may validate any one of the // requirements for the request to be authorized. // -// Security must appear in a API, Service or Method expression. +// Security must appear in an API, Service or Method expression. // // Security accepts an arbitrary number of security schemes as argument // specified by name or by reference and an optional DSL function as last diff --git a/dsl/server.go b/dsl/server.go index dfb861ef7b..f2ffc42e90 100644 --- a/dsl/server.go +++ b/dsl/server.go @@ -18,7 +18,7 @@ import ( // the first host is used to set the OpenAPI v2 specification 'host' and // 'basePath' values. // -// Server must appear in a API expression. +// Server must appear in an API expression. // // Server takes two arguments: the name of the server and the defining DSL. // diff --git a/expr/api.go b/expr/api.go index 7d77fb975e..f5e4557a5c 100644 --- a/expr/api.go +++ b/expr/api.go @@ -7,7 +7,7 @@ import ( ) type ( - // APIExpr contains the global properties for a API expression. + // APIExpr contains the global properties for an API expression. APIExpr struct { // DSLFunc contains the DSL used to initialize the expression. eval.DSLFunc diff --git a/expr/http_endpoint.go b/expr/http_endpoint.go index 774a3a9f78..bd17478469 100644 --- a/expr/http_endpoint.go +++ b/expr/http_endpoint.go @@ -740,7 +740,7 @@ func (e *HTTPEndpointExpr) validateParams() *eval.ValidationErrors { // We have to figure out the actual type for the params because the actual // type is initialized only during the finalize phase. In the validation // phase, all param types are string type by default unless specified - // expliclty. + // explicitly. initAttr(pparams, e.MethodExpr.Payload) initAttr(qparams, e.MethodExpr.Payload) diff --git a/expr/interceptor.go b/expr/interceptor.go index 538d85463f..9338aac810 100644 --- a/expr/interceptor.go +++ b/expr/interceptor.go @@ -25,6 +25,14 @@ type ( ReadResult *AttributeExpr // WriteResult lists the result attribute names written by the interceptor WriteResult *AttributeExpr + // ReadStreamingPayload lists the streaming payload attribute names read by the interceptor + ReadStreamingPayload *AttributeExpr + // WriteStreamingPayload lists the streaming payload attribute names written by the interceptor + WriteStreamingPayload *AttributeExpr + // ReadStreamingResult lists the streaming result attribute names read by the interceptor + ReadStreamingResult *AttributeExpr + // WriteStreamingResult lists the streaming result attribute names written by the interceptor + WriteStreamingResult *AttributeExpr } ) From e547e64ba70c93469a2dad6291436b7c839b7ce2 Mon Sep 17 00:00:00 2001 From: Douglas Thrift Date: Fri, 24 Jan 2025 13:51:50 -0800 Subject: [PATCH 02/23] Weave streaming interceptor stuff through codegen --- codegen/service/interceptors.go | 2 +- codegen/service/interceptors.md | 30 +++++-- codegen/service/service_data.go | 48 ++++++++++- codegen/service/templates/interceptors.go.tpl | 84 +++++++++++++++++++ .../templates/interceptors_types.go.tpl | 48 +++++++++++ ...nterceptors_service_interceptors.go.golden | 63 ++++++++++++++ codegen/service/testdata/interceptors_dsls.go | 15 +++- dsl/interceptor_test.go | 59 +++++++++++++ expr/interceptor.go | 32 +++++++ 9 files changed, 368 insertions(+), 13 deletions(-) diff --git a/codegen/service/interceptors.go b/codegen/service/interceptors.go index 8da90f9f1e..395fb84ecf 100644 --- a/codegen/service/interceptors.go +++ b/codegen/service/interceptors.go @@ -171,7 +171,7 @@ func wrapperFile(svc *Data) *codegen.File { // private implementation types. func hasPrivateImplementationTypes(interceptors []*InterceptorData) bool { for _, intr := range interceptors { - if intr.ReadPayload != nil || intr.WritePayload != nil || intr.ReadResult != nil || intr.WriteResult != nil { + if intr.ReadPayload != nil || intr.WritePayload != nil || intr.ReadResult != nil || intr.WriteResult != nil || intr.ReadStreamingPayload != nil || intr.WriteStreamingPayload != nil || intr.ReadStreamingResult != nil || intr.WriteStreamingResult != nil { return true } } diff --git a/codegen/service/interceptors.md b/codegen/service/interceptors.md index 80795d3d56..f5fd436c30 100644 --- a/codegen/service/interceptors.md +++ b/codegen/service/interceptors.md @@ -1,6 +1,6 @@ # Interceptors Code Generation -Goa generates interceptor code to enable request/response interception and payload/result access. +Goa generates interceptor code to enable request/response interception and payload/result access. --- @@ -10,8 +10,8 @@ Goa generates interceptor code to enable request/response interception and paylo Client and server interceptor code is generated in: -- `gen/client_interceptors.go` -- `gen/service_interceptors.go` +* `gen/client_interceptors.go` +* `gen/service_interceptors.go` ### Templates Used @@ -26,12 +26,13 @@ Client and server interceptor code is generated in: 3. **`client_wrappers.go.tpl`** and **`endpoint_wrappers.go.tpl`** Generate code that wraps client and service endpoints with interceptor callbacks. Each template takes a map with: + ```go map[string]any{ - "MethodVarName": - "Method": - "Service": - "Interceptors": + "MethodVarName": + "Method": + "Service": + "Interceptors": } ``` @@ -43,12 +44,13 @@ Client and server interceptor code is generated in: Endpoint wrapper code for both client and server interceptors is generated in: -- `gen/interceptor_wrappers.go` +* `gen/interceptor_wrappers.go` ### Templates Used 1. **`server_interceptor_wrappers.go.tpl`** Generates server-specific wrapper implementations. This template receives a map with: + ```go map[string]any{ "Service": svc.Name, @@ -58,6 +60,7 @@ Endpoint wrapper code for both client and server interceptors is generated in: 2. **`client_interceptor_wrappers.go.tpl`** Generates client-specific wrapper implementations. This template receives a map with: + ```go map[string]any{ "Service": svc.Name, @@ -78,6 +81,7 @@ Example interceptors are generated by the example command in an interceptors sub 1. **`example_client_interceptor.go.tpl` and `example_server_interceptor.go.tpl`** Generate example interceptor implementations. Each template takes a map with: + ```go map[string]any{ "StructName": @@ -122,10 +126,16 @@ The main structure describing each interceptor’s metadata and requirements: * `Description`: Interceptor description from the design * `HasPayloadAccess`: Indicates if any method requires payload access * `HasResultAccess`: Indicates if any method requires result access +* `HasStreamingPayloadAccess`: Indicates if any method requires streaming payload access +* `HasStreamingResultAccess`: Indicates if any method requires streaming result access * `ReadPayload`: List of readable payload fields ([]AttributeData) * `WritePayload`: List of writable payload fields ([]AttributeData) * `ReadResult`: List of readable result fields ([]AttributeData) * `WriteResult`: List of writable result fields ([]AttributeData) +* `ReadStreamingPayload`: List of readable streaming payload fields ([]AttributeData) +* `WriteStreamingPayload`: List of writable streaming payload fields ([]AttributeData) +* `ReadStreamingResult`: List of readable streaming result fields ([]AttributeData) +* `WriteStreamingResult`: List of writable streaming result fields ([]AttributeData) * `Methods`: A list of MethodInterceptorData containing method-specific interceptor information * `ServerStreamInputStruct`: Server stream variable name (used if streaming) * `ClientStreamInputStruct`: Client stream variable name (used if streaming) @@ -137,8 +147,12 @@ Stores per-method interceptor configuration: * `MethodName`: The method’s Go variable name * `PayloadAccess`: Name of the payload access type * `ResultAccess`: Name of the result access type +* `StreamingPayloadAccess`: Name of the streaming payload access type +* `StreamingResultAccess`: Name of the streaming result access type * `PayloadRef`: Reference to the method's payload type * `ResultRef`: Reference to the method's result type +* `StreamingPayloadRef`: Reference to the method's streaming payload type +* `StreamingResultRef`: Reference to the method's streaming result type ### `AttributeData` diff --git a/codegen/service/service_data.go b/codegen/service/service_data.go index bbdf955c3d..dd26aa3e87 100644 --- a/codegen/service/service_data.go +++ b/codegen/service/service_data.go @@ -269,12 +269,26 @@ type ( // WriteResult contains result attributes that the interceptor can // write. WriteResult []*AttributeData + // ReadStreamingPayload contains streaming payload attributes that the interceptor can read. + ReadStreamingPayload []*AttributeData + // WriteStreamingPayload contains streaming payload attributes that the interceptor can write. + WriteStreamingPayload []*AttributeData + // ReadStreamingResult contains streaming result attributes that the interceptor can read. + ReadStreamingResult []*AttributeData + // WriteStreamingResult contains streaming result attributes that the interceptor can write. + WriteStreamingResult []*AttributeData // HasPayloadAccess indicates that the interceptor info object has a // payload access interface. HasPayloadAccess bool // HasResultAccess indicates that the interceptor info object has a // result access interface. HasResultAccess bool + // HasStreamingPayloadAccess indicates that the interceptor info object has a + // streaming payload access interface. + HasStreamingPayloadAccess bool + // HasStreamingResultAccess indicates that the interceptor info object has a + // streaming result access interface. + HasStreamingResultAccess bool } // MethodInterceptorData contains the data required to render the @@ -286,10 +300,18 @@ type ( PayloadAccess string // ResultAccess is the name of the result access struct. ResultAccess string + // StreamingPayloadAccess is the name of the streaming payload access struct. + StreamingPayloadAccess string + // StreamingResultAccess is the name of the streaming result access struct. + StreamingResultAccess string // PayloadRef is the reference to the method payload type. PayloadRef string // ResultRef is the reference to the method result type. ResultRef string + // StreamingPayloadRef is the reference to the streaming payload type. + StreamingPayloadRef string + // StreamingResultRef is the reference to the streaming result type. + StreamingResultRef string // ServerStreamInputStruct is the name of the server stream input // struct if the endpoint defines a server stream. ServerStreamInputStruct string @@ -1204,17 +1226,27 @@ func buildInterceptorData(svc *expr.ServiceExpr, methods []*MethodData, i *expr. if len(svc.Methods) == 0 { return data } - payload, result := svc.Methods[0].Payload, svc.Methods[0].Result + payload, result, streamingPayload := svc.Methods[0].Payload, svc.Methods[0].Result, svc.Methods[0].StreamingPayload data.ReadPayload = collectAttributes(i.ReadPayload, payload, scope) data.WritePayload = collectAttributes(i.WritePayload, payload, scope) data.ReadResult = collectAttributes(i.ReadResult, result, scope) data.WriteResult = collectAttributes(i.WriteResult, result, scope) + data.ReadStreamingPayload = collectAttributes(i.ReadStreamingPayload, streamingPayload, scope) + data.WriteStreamingPayload = collectAttributes(i.WriteStreamingPayload, streamingPayload, scope) + data.ReadStreamingResult = collectAttributes(i.ReadStreamingResult, result, scope) + data.WriteStreamingResult = collectAttributes(i.WriteStreamingResult, result, scope) if len(data.ReadPayload) > 0 || len(data.WritePayload) > 0 { data.HasPayloadAccess = true } if len(data.ReadResult) > 0 || len(data.WriteResult) > 0 { data.HasResultAccess = true } + if len(data.ReadStreamingPayload) > 0 || len(data.WriteStreamingPayload) > 0 { + data.HasStreamingPayloadAccess = true + } + if len(data.ReadStreamingResult) > 0 || len(data.WriteStreamingResult) > 0 { + data.HasStreamingResultAccess = true + } for _, m := range svc.Methods { applies := false intExprs := m.ServerInterceptors @@ -1247,7 +1279,7 @@ func buildInterceptorData(svc *expr.ServiceExpr, methods []*MethodData, i *expr. return data } -// buildIntercetorMethodData creates the data needed to generate interceptor +// buildInterceptorMethodData creates the data needed to generate interceptor // method code. func buildInterceptorMethodData(i *expr.InterceptorExpr, md *MethodData) *MethodInterceptorData { var serverStream, clientStream string @@ -1257,19 +1289,29 @@ func buildInterceptorMethodData(i *expr.InterceptorExpr, md *MethodData) *Method if md.ClientStream != nil { clientStream = md.ClientStream.VarName } - var payloadAccess, resultAccess string + var payloadAccess, resultAccess, streamingPayloadAccess, streamingResultAccess string if i.ReadPayload != nil || i.WritePayload != nil { payloadAccess = codegen.Goify(i.Name, false) + md.VarName + "Payload" } if i.ReadResult != nil || i.WriteResult != nil { resultAccess = codegen.Goify(i.Name, false) + md.VarName + "Result" } + if i.ReadStreamingPayload != nil || i.WriteStreamingPayload != nil { + streamingPayloadAccess = codegen.Goify(i.Name, false) + md.VarName + "StreamingPayload" + } + if i.ReadStreamingResult != nil || i.WriteStreamingResult != nil { + streamingResultAccess = codegen.Goify(i.Name, false) + md.VarName + "StreamingResult" + } return &MethodInterceptorData{ MethodName: md.VarName, PayloadAccess: payloadAccess, ResultAccess: resultAccess, PayloadRef: md.PayloadRef, ResultRef: md.ResultRef, + StreamingPayloadAccess: streamingPayloadAccess, + StreamingPayloadRef: md.StreamingPayloadRef, + StreamingResultAccess: streamingResultAccess, + StreamingResultRef: md.ResultRef, ClientStreamInputStruct: clientStream, ServerStreamInputStruct: serverStream, } diff --git a/codegen/service/templates/interceptors.go.tpl b/codegen/service/templates/interceptors.go.tpl index ea3b0b5e86..6618e99029 100644 --- a/codegen/service/templates/interceptors.go.tpl +++ b/codegen/service/templates/interceptors.go.tpl @@ -35,6 +35,42 @@ func (info *{{ .Name }}Info) Result(res any) {{ .Name }}Result { {{- else }} return &{{ (index .Methods 0).ResultAccess }}{result: res.({{ (index .Methods 0).ResultRef }})} {{- end }} +} + {{- end }} + + {{- if .HasStreamingPayloadAccess }} +// StreamingPayload returns a type-safe accessor for the method streaming payload. +func (info *{{ .Name }}Info) StreamingPayload() {{ .Name }}StreamingPayload { + {{- if gt (len .Methods) 1 }} + switch info.Method { + {{- range .Methods }} + case "{{ .MethodName }}": + return &{{ .StreamingPayloadAccess }}{payload: info.RawPayload.({{ .StreamingPayloadRef }})} + {{- end }} + default: + return nil + } + {{- else }} + return &{{ (index .Methods 0).StreamingPayloadAccess }}{payload: info.RawPayload.({{ (index .Methods 0).StreamingPayloadRef }})} + {{- end }} +} + {{- end }} + + {{- if .HasStreamingResultAccess }} +// StreamingResult returns a type-safe accessor for the method streaming result. +func (info *{{ .Name }}Info) StreamingResult() {{ .Name }}StreamingResult { + {{- if gt (len .Methods) 1 }} + switch info.Method { + {{- range .Methods }} + case "{{ .MethodName }}": + return &{{ .StreamingResultAccess }}{result: info.RawResult.({{ .StreamingResultRef }})} + {{- end }} + default: + return nil + } + {{- else }} + return &{{ (index .Methods 0).StreamingResultAccess }}{result: info.RawResult.({{ (index .Methods 0).StreamingResultRef }})} + {{- end }} } {{- end }} {{- end }} @@ -89,6 +125,54 @@ func (r *{{ $method.ResultAccess }}) Set{{ .Name }}(v {{ .TypeRef }}) { {{- else }} r.result.{{ .Name }} = v {{- end }} +} + {{- end }} + + {{- range $interceptor.ReadStreamingPayload }} +func (p *{{ $method.StreamingPayloadAccess }}) {{ .Name }}() {{ .TypeRef }} { + {{- if .Pointer }} + if p.payload.{{ .Name }} == nil { + var zero {{ .TypeRef }} + return zero + } + return *p.payload.{{ .Name }} + {{- else }} + return p.payload.{{ .Name }} + {{- end }} +} + {{- end }} + + {{- range $interceptor.WriteStreamingPayload }} +func (p *{{ $method.StreamingPayloadAccess }}) Set{{ .Name }}(v {{ .TypeRef }}) { + {{- if .Pointer }} + p.payload.{{ .Name }} = &v + {{- else }} + p.payload.{{ .Name }} = v + {{- end }} +} + {{- end }} + + {{- range $interceptor.ReadStreamingResult }} +func (r *{{ $method.StreamingResultAccess }}) {{ .Name }}() {{ .TypeRef }} { + {{- if .Pointer }} + if r.result.{{ .Name }} == nil { + var zero {{ .TypeRef }} + return zero + } + return *r.result.{{ .Name }} + {{- else }} + return r.result.{{ .Name }} + {{- end }} +} + {{- end }} + + {{- range $interceptor.WriteStreamingResult }} +func (r *{{ $method.StreamingResultAccess }}) Set{{ .Name }}(v {{ .TypeRef }}) { + {{- if .Pointer }} + r.result.{{ .Name }} = &v + {{- else }} + r.result.{{ .Name }} = v + {{- end }} } {{- end }} {{- end }} diff --git a/codegen/service/templates/interceptors_types.go.tpl b/codegen/service/templates/interceptors_types.go.tpl index 0c542b089e..1e992dd26d 100644 --- a/codegen/service/templates/interceptors_types.go.tpl +++ b/codegen/service/templates/interceptors_types.go.tpl @@ -33,6 +33,34 @@ type ( {{- end }} } {{- end }} + {{- if .HasStreamingPayloadAccess }} + + // {{ .Name }}StreamingPayload provides type-safe access to the method streaming payload. + // It allows reading and writing specific fields of the streaming payload as defined + // in the design. + {{ .Name }}StreamingPayload interface { + {{- range .ReadStreamingPayload }} + {{ .Name }}() {{ .TypeRef }} + {{- end }} + {{- range .WriteStreamingPayload }} + Set{{ .Name }}({{ .TypeRef }}) + {{- end }} + } + {{- end }} + {{- if .HasStreamingResultAccess }} + + // {{ .Name }}StreamingResult provides type-safe access to the method streaming result. + // It allows reading and writing specific fields of the streaming result as defined + // in the design. + {{ .Name }}StreamingResult interface { + {{- range .ReadStreamingResult }} + {{ .Name }}() {{ .TypeRef }} + {{- end }} + {{- range .WriteStreamingResult }} + Set{{ .Name }}({{ .TypeRef }}) + {{- end }} + } + {{- end }} {{- end }} ) {{- if hasPrivateImplementationTypes . }} @@ -58,5 +86,25 @@ type ( {{- end }} {{- end }} {{- end }} + + {{- range . }} + {{- range .Methods }} + {{- if .StreamingPayloadAccess }} + {{ .StreamingPayloadAccess }} struct { + payload {{ .StreamingPayloadRef }} + } + {{- end }} + {{- end }} + {{- end }} + + {{- range . }} + {{- range .Methods }} + {{- if .StreamingResultAccess }} + {{ .StreamingResultAccess }} struct { + result {{ .StreamingResultRef }} + } + {{- end }} + {{- end }} + {{- end }} ) {{- end }} diff --git a/codegen/service/testdata/interceptors/streaming-interceptors_service_interceptors.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors_service_interceptors.go.golden index 58b647a34a..e77c50d369 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors_service_interceptors.go.golden @@ -11,6 +11,34 @@ type ( // LoggingInfo provides metadata about the current interception. // It includes service name, method name, and access to the endpoint. LoggingInfo goa.InterceptorInfo + + // LoggingStreamingPayload provides type-safe access to the method streaming payload. + // It allows reading and writing specific fields of the streaming payload as defined + // in the design. + LoggingStreamingPayload interface { + Chunk() string + SetChunk(string) + } + + // LoggingStreamingResult provides type-safe access to the method streaming result. + // It allows reading and writing specific fields of the streaming result as defined + // in the design. + LoggingStreamingResult interface { + Data() string + SetData(string) + } +) + +// Private implementation types +type ( + loggingMethodStreamingPayload struct { + payload struct { + Chunk *string + } + } + loggingMethodStreamingResult struct { + result *MethodResult + } ) // WrapMethodEndpoint wraps the Method endpoint with the server-side @@ -20,3 +48,38 @@ func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoin return endpoint } +// Public accessor methods for Info types +// StreamingPayload returns a type-safe accessor for the method streaming payload. +func (info *LoggingInfo) StreamingPayload() LoggingStreamingPayload { + return &loggingMethodStreamingPayload{payload: info.RawPayload.(struct { + Chunk *string + })} +} + +// StreamingResult returns a type-safe accessor for the method streaming result. +func (info *LoggingInfo) StreamingResult() LoggingStreamingResult { + return &loggingMethodStreamingResult{result: info.RawResult.(*MethodResult)} +} + +// Private implementation methods + +func (p *loggingMethodStreamingPayload) Chunk() string { + if p.payload.Chunk == nil { + var zero string + return zero + } + return *p.payload.Chunk +} +func (p *loggingMethodStreamingPayload) SetChunk(v string) { + p.payload.Chunk = &v +} +func (r *loggingMethodStreamingResult) Data() string { + if r.result.Data == nil { + var zero string + return zero + } + return *r.result.Data +} +func (r *loggingMethodStreamingResult) SetData(v string) { + r.result.Data = &v +} diff --git a/codegen/service/testdata/interceptors_dsls.go b/codegen/service/testdata/interceptors_dsls.go index dead879c9f..3b1d8ba7a6 100644 --- a/codegen/service/testdata/interceptors_dsls.go +++ b/codegen/service/testdata/interceptors_dsls.go @@ -214,7 +214,20 @@ var InterceptorWithReadWriteResultDSL = func() { } var StreamingInterceptorsDSL = func() { - Interceptor("logging") + Interceptor("logging", func() { + ReadStreamingPayload(func() { + Attribute("chunk") + }) + WriteStreamingPayload(func() { + Attribute("chunk") + }) + ReadStreamingResult(func() { + Attribute("data") + }) + WriteStreamingResult(func() { + Attribute("data") + }) + }) Service("StreamingInterceptors", func() { ServerInterceptor("logging") Method("Method", func() { diff --git a/dsl/interceptor_test.go b/dsl/interceptor_test.go index 7e519768d1..719b600709 100644 --- a/dsl/interceptor_test.go +++ b/dsl/interceptor_test.go @@ -69,6 +69,65 @@ func TestInterceptor(t *testing.T) { assert.NotNil(t, wr.Attribute("qux"), "WriteResult should have a qux attribute") }, }, + "valid-streaming": { + func() { + Interceptor("streaming", func() { + Description("test streaming interceptor") + ReadPayload(func() { + Attribute("foo", String) + }) + WritePayload(func() { + Attribute("bar", String) + }) + ReadStreamingPayload(func() { + Attribute("foo", String) + }) + WriteStreamingPayload(func() { + Attribute("bar", String) + }) + ReadStreamingResult(func() { + Attribute("baz", String) + }) + WriteStreamingResult(func() { + Attribute("qux", String) + }) + }) + }, + func(t *testing.T, intr *expr.InterceptorExpr) { + require.NotNil(t, intr, "interceptor should not be nil") + assert.Equal(t, "test streaming interceptor", intr.Description) + + require.NotNil(t, intr.ReadPayload, "ReadPayload should not be nil") + rp := expr.AsObject(intr.ReadPayload.Type) + require.NotNil(t, rp, "ReadPayload should be an object") + assert.NotNil(t, rp.Attribute("foo"), "ReadPayload should have a foo attribute") + + require.NotNil(t, intr.WritePayload, "WritePayload should not be nil") + wp := expr.AsObject(intr.WritePayload.Type) + require.NotNil(t, wp, "WritePayload should be an object") + assert.NotNil(t, wp.Attribute("bar"), "WritePayload should have a bar attribute") + + require.NotNil(t, intr.ReadStreamingPayload, "ReadStreamingPayload should not be nil") + rs := expr.AsObject(intr.ReadStreamingPayload.Type) + require.NotNil(t, rs, "ReadStreamingPayload should be an object") + assert.NotNil(t, rs.Attribute("foo"), "ReadStreamingPayload should have a foo attribute") + + require.NotNil(t, intr.WriteStreamingPayload, "WriteStreamingPayload should not be nil") + ws := expr.AsObject(intr.WriteStreamingPayload.Type) + require.NotNil(t, ws, "WriteStreamingPayload should be an object") + assert.NotNil(t, ws.Attribute("bar"), "WriteStreamingPayload should have a bar attribute") + + require.NotNil(t, intr.ReadStreamingResult, "ReadStreamingResult should not be nil") + rsr := expr.AsObject(intr.ReadStreamingResult.Type) + require.NotNil(t, rsr, "ReadStreamingResult should be an object") + assert.NotNil(t, rsr.Attribute("baz"), "ReadStreamingResult should have a baz attribute") + + require.NotNil(t, intr.WriteStreamingResult, "WriteStreamingResult should not be nil") + wsr := expr.AsObject(intr.WriteStreamingResult.Type) + require.NotNil(t, wsr, "WriteStreamingResult should be an object") + assert.NotNil(t, wsr.Attribute("qux"), "WriteStreamingResult should have a qux attribute") + }, + }, "empty-name": { func() { Interceptor("", func() {}) diff --git a/expr/interceptor.go b/expr/interceptor.go index 9338aac810..31a243351b 100644 --- a/expr/interceptor.go +++ b/expr/interceptor.go @@ -74,6 +74,38 @@ func (i *InterceptorExpr) validate(m *MethodExpr) *eval.ValidationErrors { } } + if i.ReadStreamingPayload != nil || i.WriteStreamingPayload != nil { + if !m.IsPayloadStreaming() { + verr.Add(m, "interceptor %q cannot be applied because the method payload is not streaming", i.Name) + } + payloadObj := AsObject(m.StreamingPayload.Type) + if payloadObj == nil { + verr.Add(m, "interceptor %q cannot be applied because the method payload is not an object", i.Name) + } + if i.ReadStreamingPayload != nil { + i.validateAttributeAccess(m, "read streaming payload", verr, payloadObj, i.ReadStreamingPayload) + } + if i.WriteStreamingPayload != nil { + i.validateAttributeAccess(m, "write streaming payload", verr, payloadObj, i.WriteStreamingPayload) + } + } + + if i.ReadStreamingResult != nil || i.WriteStreamingResult != nil { + if !m.IsResultStreaming() { + verr.Add(m, "interceptor %q cannot be applied because the method result is not streaming", i.Name) + } + resultObj := AsObject(m.Result.Type) + if resultObj == nil { + verr.Add(m, "interceptor %q cannot be applied because the method result is not an object", i.Name) + } + if i.ReadStreamingResult != nil { + i.validateAttributeAccess(m, "read streaming result", verr, resultObj, i.ReadStreamingResult) + } + if i.WriteStreamingResult != nil { + i.validateAttributeAccess(m, "write streaming result", verr, resultObj, i.WriteStreamingResult) + } + } + return verr } From d6d779db5da7a10178a23e098734e7ce7793c8ed Mon Sep 17 00:00:00 2001 From: Douglas Thrift Date: Fri, 24 Jan 2025 16:50:14 -0800 Subject: [PATCH 03/23] Do not try to use a field from an interface for the raw payload when wrapping streaming methods --- .../service/templates/client_interceptor_wrappers.go.tpl | 4 ---- .../service/templates/server_interceptor_wrappers.go.tpl | 6 +----- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/codegen/service/templates/client_interceptor_wrappers.go.tpl b/codegen/service/templates/client_interceptor_wrappers.go.tpl index cc0ff52a7b..4b53b4e4ab 100644 --- a/codegen/service/templates/client_interceptor_wrappers.go.tpl +++ b/codegen/service/templates/client_interceptor_wrappers.go.tpl @@ -9,11 +9,7 @@ func wrapClient{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i Service: "{{ $.Service }}", Method: "{{ .MethodName }}", Endpoint: endpoint, - {{- if .ClientStreamInputStruct }} - RawPayload: req.(*{{ .ClientStreamInputStruct }}).Payload, - {{- else }} RawPayload: req, - {{- end }} } return i.{{ $interceptor.Name }}(ctx, info, endpoint) } diff --git a/codegen/service/templates/server_interceptor_wrappers.go.tpl b/codegen/service/templates/server_interceptor_wrappers.go.tpl index cb0f5d9c44..6e45db7afe 100644 --- a/codegen/service/templates/server_interceptor_wrappers.go.tpl +++ b/codegen/service/templates/server_interceptor_wrappers.go.tpl @@ -9,14 +9,10 @@ func wrap{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i Serve Service: "{{ $.Service }}", Method: "{{ .MethodName }}", Endpoint: endpoint, - {{- if .ServerStreamInputStruct }} - RawPayload: req.(*{{ .ServerStreamInputStruct }}).Payload, - {{- else }} RawPayload: req, - {{- end }} } return i.{{ $interceptor.Name }}(ctx, info, endpoint) } } {{- end }} -{{- end }} \ No newline at end of file +{{- end }} From fa0bdde8ae06ceb67b06fbb622ef2bf532fbb6bc Mon Sep 17 00:00:00 2001 From: Douglas Thrift Date: Fri, 24 Jan 2025 16:53:15 -0800 Subject: [PATCH 04/23] Fix golden files --- ...ngle-api-server-interceptor_interceptor_wrappers.go.golden | 2 +- ...e-method-server-interceptor_interceptor_wrappers.go.golden | 2 +- ...-service-server-interceptor_interceptor_wrappers.go.golden | 2 +- ...erceptors-with-read-payload_interceptor_wrappers.go.golden | 4 ++-- ...terceptors-with-read-result_interceptor_wrappers.go.golden | 4 ++-- .../streaming-interceptors_interceptor_wrappers.go.golden | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/codegen/service/testdata/interceptors/single-api-server-interceptor_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/single-api-server-interceptor_interceptor_wrappers.go.golden index b7e0eebf4c..7c9edb4592 100644 --- a/codegen/service/testdata/interceptors/single-api-server-interceptor_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/single-api-server-interceptor_interceptor_wrappers.go.golden @@ -24,4 +24,4 @@ func wrapMethod2Logging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoin } return i.Logging(ctx, info, endpoint) } -} \ No newline at end of file +} diff --git a/codegen/service/testdata/interceptors/single-method-server-interceptor_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/single-method-server-interceptor_interceptor_wrappers.go.golden index c06dbb3edd..1a2f722b8a 100644 --- a/codegen/service/testdata/interceptors/single-method-server-interceptor_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/single-method-server-interceptor_interceptor_wrappers.go.golden @@ -11,4 +11,4 @@ func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint } return i.Logging(ctx, info, endpoint) } -} \ No newline at end of file +} diff --git a/codegen/service/testdata/interceptors/single-service-server-interceptor_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/single-service-server-interceptor_interceptor_wrappers.go.golden index c15ab43987..06731b4ed6 100644 --- a/codegen/service/testdata/interceptors/single-service-server-interceptor_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/single-service-server-interceptor_interceptor_wrappers.go.golden @@ -24,4 +24,4 @@ func wrapMethod2Logging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoin } return i.Logging(ctx, info, endpoint) } -} \ No newline at end of file +} diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_interceptor_wrappers.go.golden index 554dade015..4eaf97ae32 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_interceptor_wrappers.go.golden @@ -7,8 +7,8 @@ func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint Service: "StreamingInterceptorsWithReadPayload", Method: "Method", Endpoint: endpoint, - RawPayload: req.(*MethodServerStream).Payload, + RawPayload: req, } return i.Logging(ctx, info, endpoint) } -} \ No newline at end of file +} diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_interceptor_wrappers.go.golden index 2fc769d48b..61fffb56af 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_interceptor_wrappers.go.golden @@ -7,8 +7,8 @@ func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint Service: "StreamingInterceptorsWithReadResult", Method: "Method", Endpoint: endpoint, - RawPayload: req.(*MethodServerStream).Payload, + RawPayload: req, } return i.Logging(ctx, info, endpoint) } -} \ No newline at end of file +} diff --git a/codegen/service/testdata/interceptors/streaming-interceptors_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors_interceptor_wrappers.go.golden index 0361aa2387..e42932575b 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors_interceptor_wrappers.go.golden @@ -7,8 +7,8 @@ func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint Service: "StreamingInterceptors", Method: "Method", Endpoint: endpoint, - RawPayload: req.(*MethodServerStream).Payload, + RawPayload: req, } return i.Logging(ctx, info, endpoint) } -} \ No newline at end of file +} From 946b6776e2b562c10a37b57593eb5e7aa581156e Mon Sep 17 00:00:00 2001 From: Douglas Thrift Date: Mon, 27 Jan 2025 16:50:33 -0800 Subject: [PATCH 05/23] Collect attributes from a method that actually has the interceptor applied; import the correct user types packages when rendering service_interceptors.go; fix an ancient typo --- codegen/service/interceptors.go | 1 + codegen/service/service.go | 2 +- codegen/service/service_data.go | 46 ++++++++++++++++++--------------- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/codegen/service/interceptors.go b/codegen/service/interceptors.go index 395fb84ecf..011b05eb00 100644 --- a/codegen/service/interceptors.go +++ b/codegen/service/interceptors.go @@ -78,6 +78,7 @@ func interceptorFile(svc *Data, server bool) *codegen.File { }, } if len(interceptors) > 0 { + codegen.AddImport(sections[0], svc.UserTypeImports...) sections = append(sections, &codegen.SectionTemplate{ Name: "interceptor-types", Source: readTemplate("interceptors_types"), diff --git a/codegen/service/service.go b/codegen/service/service.go index 706ea255ad..4fb12d67fe 100644 --- a/codegen/service/service.go +++ b/codegen/service/service.go @@ -47,7 +47,7 @@ func Files(genpkg string, service *expr.ServiceExpr, userTypePkgs map[string][]s if m.StreamingPayloadDef != "" { if _, ok := seen[m.StreamingPayload]; !ok { addTypeDefSection(payloadPath, m.StreamingPayload, &codegen.SectionTemplate{ - Name: "service-streamig-payload", + Name: "service-streaming-payload", Source: readTemplate("streaming_payload"), Data: m, }) diff --git a/codegen/service/service_data.go b/codegen/service/service_data.go index dd26aa3e87..6295ef0a75 100644 --- a/codegen/service/service_data.go +++ b/codegen/service/service_data.go @@ -1226,27 +1226,7 @@ func buildInterceptorData(svc *expr.ServiceExpr, methods []*MethodData, i *expr. if len(svc.Methods) == 0 { return data } - payload, result, streamingPayload := svc.Methods[0].Payload, svc.Methods[0].Result, svc.Methods[0].StreamingPayload - data.ReadPayload = collectAttributes(i.ReadPayload, payload, scope) - data.WritePayload = collectAttributes(i.WritePayload, payload, scope) - data.ReadResult = collectAttributes(i.ReadResult, result, scope) - data.WriteResult = collectAttributes(i.WriteResult, result, scope) - data.ReadStreamingPayload = collectAttributes(i.ReadStreamingPayload, streamingPayload, scope) - data.WriteStreamingPayload = collectAttributes(i.WriteStreamingPayload, streamingPayload, scope) - data.ReadStreamingResult = collectAttributes(i.ReadStreamingResult, result, scope) - data.WriteStreamingResult = collectAttributes(i.WriteStreamingResult, result, scope) - if len(data.ReadPayload) > 0 || len(data.WritePayload) > 0 { - data.HasPayloadAccess = true - } - if len(data.ReadResult) > 0 || len(data.WriteResult) > 0 { - data.HasResultAccess = true - } - if len(data.ReadStreamingPayload) > 0 || len(data.WriteStreamingPayload) > 0 { - data.HasStreamingPayloadAccess = true - } - if len(data.ReadStreamingResult) > 0 || len(data.WriteStreamingResult) > 0 { - data.HasStreamingResultAccess = true - } + attributesCollected := false for _, m := range svc.Methods { applies := false intExprs := m.ServerInterceptors @@ -1255,6 +1235,30 @@ func buildInterceptorData(svc *expr.ServiceExpr, methods []*MethodData, i *expr. } for _, in := range intExprs { if in.Name == i.Name { + if !attributesCollected { + payload, result, streamingPayload := m.Payload, m.Result, m.StreamingPayload + data.ReadPayload = collectAttributes(i.ReadPayload, payload, scope) + data.WritePayload = collectAttributes(i.WritePayload, payload, scope) + data.ReadResult = collectAttributes(i.ReadResult, result, scope) + data.WriteResult = collectAttributes(i.WriteResult, result, scope) + data.ReadStreamingPayload = collectAttributes(i.ReadStreamingPayload, streamingPayload, scope) + data.WriteStreamingPayload = collectAttributes(i.WriteStreamingPayload, streamingPayload, scope) + data.ReadStreamingResult = collectAttributes(i.ReadStreamingResult, result, scope) + data.WriteStreamingResult = collectAttributes(i.WriteStreamingResult, result, scope) + if len(data.ReadPayload) > 0 || len(data.WritePayload) > 0 { + data.HasPayloadAccess = true + } + if len(data.ReadResult) > 0 || len(data.WriteResult) > 0 { + data.HasResultAccess = true + } + if len(data.ReadStreamingPayload) > 0 || len(data.WriteStreamingPayload) > 0 { + data.HasStreamingPayloadAccess = true + } + if len(data.ReadStreamingResult) > 0 || len(data.WriteStreamingResult) > 0 { + data.HasStreamingResultAccess = true + } + attributesCollected = true + } applies = true break } From 28789b082b5252bb639db36ba53d0f5c8e638f2b Mon Sep 17 00:00:00 2001 From: Douglas Thrift Date: Mon, 27 Jan 2025 17:11:59 -0800 Subject: [PATCH 06/23] Fix StreamingResult accessor signature and return --- codegen/service/templates/interceptors.go.tpl | 6 +++--- .../streaming-interceptors_service_interceptors.go.golden | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/codegen/service/templates/interceptors.go.tpl b/codegen/service/templates/interceptors.go.tpl index 6618e99029..6f5f2250c0 100644 --- a/codegen/service/templates/interceptors.go.tpl +++ b/codegen/service/templates/interceptors.go.tpl @@ -58,18 +58,18 @@ func (info *{{ .Name }}Info) StreamingPayload() {{ .Name }}StreamingPayload { {{- if .HasStreamingResultAccess }} // StreamingResult returns a type-safe accessor for the method streaming result. -func (info *{{ .Name }}Info) StreamingResult() {{ .Name }}StreamingResult { +func (info *{{ .Name }}Info) StreamingResult(res any) {{ .Name }}StreamingResult { {{- if gt (len .Methods) 1 }} switch info.Method { {{- range .Methods }} case "{{ .MethodName }}": - return &{{ .StreamingResultAccess }}{result: info.RawResult.({{ .StreamingResultRef }})} + return &{{ .StreamingResultAccess }}{result: res.({{ .StreamingResultRef }})} {{- end }} default: return nil } {{- else }} - return &{{ (index .Methods 0).StreamingResultAccess }}{result: info.RawResult.({{ (index .Methods 0).StreamingResultRef }})} + return &{{ (index .Methods 0).StreamingResultAccess }}{result: res.({{ (index .Methods 0).StreamingResultRef }})} {{- end }} } {{- end }} diff --git a/codegen/service/testdata/interceptors/streaming-interceptors_service_interceptors.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors_service_interceptors.go.golden index e77c50d369..52d08d6100 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors_service_interceptors.go.golden @@ -57,8 +57,8 @@ func (info *LoggingInfo) StreamingPayload() LoggingStreamingPayload { } // StreamingResult returns a type-safe accessor for the method streaming result. -func (info *LoggingInfo) StreamingResult() LoggingStreamingResult { - return &loggingMethodStreamingResult{result: info.RawResult.(*MethodResult)} +func (info *LoggingInfo) StreamingResult(res any) LoggingStreamingResult { + return &loggingMethodStreamingResult{result: res.(*MethodResult)} } // Private implementation methods From 905c5d8c6faf038f92c1bdf05ff63d0f1d0d34e7 Mon Sep 17 00:00:00 2001 From: Douglas Thrift Date: Tue, 28 Jan 2025 17:16:29 -0800 Subject: [PATCH 07/23] Add SendWithContext and RecvWithContext methods to the stream interface generation --- codegen/service/service_data.go | 52 ++++++--- codegen/service/templates/service.go.tpl | 4 + grpc/codegen/service_data.go | 80 ++++++++----- grpc/codegen/templates/stream_recv.go.tpl | 5 + grpc/codegen/templates/stream_send.go.tpl | 5 + http/codegen/templates/websocket_recv.go.tpl | 5 + http/codegen/templates/websocket_send.go.tpl | 5 + http/codegen/websocket.go | 116 ++++++++++++------- 8 files changed, 182 insertions(+), 90 deletions(-) diff --git a/codegen/service/service_data.go b/codegen/service/service_data.go index 6295ef0a75..f8494d139c 100644 --- a/codegen/service/service_data.go +++ b/codegen/service/service_data.go @@ -203,6 +203,10 @@ type ( SendName string // SendDesc is the description for the send function. SendDesc string + // SendWithContextName is the name of the send function with context. + SendWithContextName string + // SendWithContextDesc is the description for the send function with context. + SendWithContextDesc string // SendTypeName is the type name sent through the stream. SendTypeName string // SendTypeRef is the reference to the type sent through the stream. @@ -211,6 +215,10 @@ type ( RecvName string // RecvDesc is the description for the recv function. RecvDesc string + // RecvWithContextName is the name of the receive function with context. + RecvWithContextName string + // RecvWithContextDesc is the description for the recv function with context. + RecvWithContextDesc string // RecvTypeName is the type name received from the stream. RecvTypeName string // RecvTypeRef is the reference to the type received from the stream. @@ -1164,24 +1172,28 @@ func initStreamData(data *MethodData, m *expr.MethodExpr, vname, rname, resultRe spayloadEx = m.StreamingPayload.Example(expr.Root.API.ExampleGenerator) } svrStream := &StreamData{ - Interface: vname + "ServerStream", - VarName: scope.Unique(codegen.Goify(m.Name, true), "ServerStream"), - EndpointStruct: vname + "EndpointInput", - Kind: m.Stream, - SendName: "Send", - SendDesc: fmt.Sprintf("Send streams instances of %q.", rname), - SendTypeName: rname, - SendTypeRef: resultRef, - MustClose: true, + Interface: vname + "ServerStream", + VarName: scope.Unique(codegen.Goify(m.Name, true), "ServerStream"), + EndpointStruct: vname + "EndpointInput", + Kind: m.Stream, + SendName: "Send", + SendDesc: fmt.Sprintf("Send streams instances of %q.", rname), + SendWithContextName: "SendWithContext", + SendWithContextDesc: fmt.Sprintf("SendWithContext streams instances of %q with context.", rname), + SendTypeName: rname, + SendTypeRef: resultRef, + MustClose: true, } cliStream := &StreamData{ - Interface: vname + "ClientStream", - VarName: scope.Unique(codegen.Goify(m.Name, true), "ClientStream"), - Kind: m.Stream, - RecvName: "Recv", - RecvDesc: fmt.Sprintf("Recv reads instances of %q from the stream.", rname), - RecvTypeName: rname, - RecvTypeRef: resultRef, + Interface: vname + "ClientStream", + VarName: scope.Unique(codegen.Goify(m.Name, true), "ClientStream"), + Kind: m.Stream, + RecvName: "Recv", + RecvDesc: fmt.Sprintf("Recv reads instances of %q from the stream.", rname), + RecvWithContextName: "RecvWithContext", + RecvWithContextDesc: fmt.Sprintf("RecvWithContext reads instances of %q from the stream with context.", rname), + RecvTypeName: rname, + RecvTypeRef: resultRef, } if m.Stream == expr.ClientStreamKind || m.Stream == expr.BidirectionalStreamKind { switch m.Stream { @@ -1189,9 +1201,13 @@ func initStreamData(data *MethodData, m *expr.MethodExpr, vname, rname, resultRe if resultRef != "" { svrStream.SendName = "SendAndClose" svrStream.SendDesc = fmt.Sprintf("SendAndClose streams instances of %q and closes the stream.", rname) + svrStream.SendWithContextName = "SendAndCloseWithContext" + svrStream.SendWithContextDesc = fmt.Sprintf("SendAndCloseWithContext streams instances of %q and closes the stream with context.", rname) svrStream.MustClose = false cliStream.RecvName = "CloseAndRecv" cliStream.RecvDesc = fmt.Sprintf("CloseAndRecv stops sending messages to the stream and reads instances of %q from the stream.", rname) + cliStream.RecvWithContextName = "CloseAndRecvWithContext" + cliStream.RecvWithContextDesc = fmt.Sprintf("CloseAndRecvWithContext stops sending messages to the stream and reads instances of %q from the stream with context.", rname) } else { cliStream.MustClose = true } @@ -1200,10 +1216,14 @@ func initStreamData(data *MethodData, m *expr.MethodExpr, vname, rname, resultRe } svrStream.RecvName = "Recv" svrStream.RecvDesc = fmt.Sprintf("Recv reads instances of %q from the stream.", spayloadName) + svrStream.RecvWithContextName = "RecvWithContext" + svrStream.RecvWithContextDesc = fmt.Sprintf("RecvWithContext reads instances of %q from the stream with context.", spayloadName) svrStream.RecvTypeName = spayloadName svrStream.RecvTypeRef = spayloadRef cliStream.SendName = "Send" cliStream.SendDesc = fmt.Sprintf("Send streams instances of %q.", spayloadName) + cliStream.SendWithContextName = "SendWithContext" + cliStream.SendWithContextDesc = fmt.Sprintf("SendWithContext streams instances of %q with context.", spayloadName) cliStream.SendTypeName = spayloadName cliStream.SendTypeRef = spayloadRef } diff --git a/codegen/service/templates/service.go.tpl b/codegen/service/templates/service.go.tpl index 5164c62016..6a3334a5bd 100644 --- a/codegen/service/templates/service.go.tpl +++ b/codegen/service/templates/service.go.tpl @@ -64,10 +64,14 @@ type {{ .Stream.Interface }} interface { {{- if .Stream.SendTypeRef }} {{ comment .Stream.SendDesc }} {{ .Stream.SendName }}({{ .Stream.SendTypeRef }}) error + {{ comment .Stream.SendWithContextDesc }} + {{ .Stream.SendWithContextName }}(context.Context, {{ .Stream.SendTypeRef }}) error {{- end }} {{- if .Stream.RecvTypeRef }} {{ comment .Stream.RecvDesc }} {{ .Stream.RecvName }}() ({{ .Stream.RecvTypeRef }}, error) + {{ comment .Stream.RecvWithContextDesc }} + {{ .Stream.RecvWithContextName }}(context.Context) ({{ .Stream.RecvTypeRef }}, error) {{- end }} {{- if .Stream.MustClose }} {{ comment "Close closes the stream." }} diff --git a/grpc/codegen/service_data.go b/grpc/codegen/service_data.go index dab2d28d15..e375aa9c3f 100644 --- a/grpc/codegen/service_data.go +++ b/grpc/codegen/service_data.go @@ -332,6 +332,10 @@ type ( SendName string // SendDesc is the description for the send function. SendDesc string + // SendWithContextName is the name of the send function with context. + SendWithContextName string + // SendWithContextDesc is the description for the send function with context. + SendWithContextDesc string // SendRef is the fully qualified reference to the type sent across the // stream. SendRef string @@ -347,6 +351,10 @@ type ( RecvName string // RecvDesc is the description for the recv function. RecvDesc string + // RecvWithContextName is the name of the receive function with context. + RecvWithContextName string + // RecvWithContextDesc is the description for the recv function with context. + RecvWithContextDesc string // RecvRef is the fully qualified reference to the type received from the // stream. RecvRef string @@ -393,7 +401,7 @@ func (d ServicesData) Get(name string) *ServiceData { return d[name] } -// Endpoint returns the endoint data for the endpoint with the given name, nil +// Endpoint returns the endpoint data for the endpoint with the given name, nil // if there isn't one. func (sd *ServiceData) Endpoint(name string) *EndpointData { for _, ed := range sd.Endpoints { @@ -779,7 +787,7 @@ func collectValidations(att *expr.AttributeExpr, attName string, ctx *codegen.At switch dt := att.Type.(type) { case expr.UserType: if expr.IsPrimitive(dt) { - // Alias type - validation is generatd inline in parent type validation code. + // Alias type - validation is generate inline in parent type validation code. return } vtx := protoBufTypeContext(sd.PkgName, sd.Scope, false) @@ -1151,19 +1159,23 @@ func buildErrorConvertData(ge *expr.GRPCErrorExpr, e *expr.GRPCEndpointExpr, sd // svr param indicates that the stream data is built for the server. func buildStreamData(e *expr.GRPCEndpointExpr, sd *ServiceData, svr bool) *StreamData { var ( - varn string - intName string - svcInt string - sendName string - sendDesc string - sendRef string - sendConvert *ConvertData - recvName string - recvDesc string - recvRef string - recvConvert *ConvertData - mustClose bool - typ string + varn string + intName string + svcInt string + sendName string + sendDesc string + sendWithContextName string + sendWithContextDesc string + sendRef string + sendConvert *ConvertData + recvName string + recvDesc string + recvWithContextName string + recvWithContextDesc string + recvRef string + recvConvert *ConvertData + mustClose bool + typ string svc = sd.Service ed = sd.Endpoint(e.Name()) @@ -1184,6 +1196,7 @@ func buildStreamData(e *expr.GRPCEndpointExpr, sd *ServiceData, svr bool) *Strea if e.MethodExpr.Result.Type != expr.Empty { sendName = md.ServerStream.SendName sendRef = ed.ResultRef + sendWithContextName = md.ServerStream.SendWithContextName sendConvert = &ConvertData{ SrcName: resCtx.Scope.Name(result, resCtx.Pkg(result), resCtx.Pointer, resCtx.UseDefault), SrcRef: resCtx.Scope.Ref(result, resCtx.Pkg(result)), @@ -1194,6 +1207,7 @@ func buildStreamData(e *expr.GRPCEndpointExpr, sd *ServiceData, svr bool) *Strea } if e.MethodExpr.StreamingPayload.Type != expr.Empty { recvName = md.ServerStream.RecvName + recvWithContextName = md.ServerStream.RecvWithContextName recvRef = svcCtx.Scope.Ref(e.MethodExpr.StreamingPayload, svcCtx.Pkg(e.MethodExpr.StreamingPayload)) recvConvert = &ConvertData{ SrcName: protoBufGoFullTypeName(e.StreamingRequest, sd.PkgName, sd.Scope), @@ -1212,6 +1226,7 @@ func buildStreamData(e *expr.GRPCEndpointExpr, sd *ServiceData, svr bool) *Strea svcInt = fmt.Sprintf("%s.%s", svc.PkgName, md.ClientStream.Interface) if e.MethodExpr.StreamingPayload.Type != expr.Empty { sendName = md.ClientStream.SendName + sendWithContextName = md.ClientStream.SendWithContextName sendRef = svcCtx.Scope.Ref(e.MethodExpr.StreamingPayload, svcCtx.Pkg(e.MethodExpr.StreamingPayload)) sendConvert = &ConvertData{ SrcName: svcCtx.Scope.Name(e.MethodExpr.StreamingPayload, svcCtx.Pkg(e.MethodExpr.StreamingPayload), svcCtx.Pointer, svcCtx.UseDefault), @@ -1223,6 +1238,7 @@ func buildStreamData(e *expr.GRPCEndpointExpr, sd *ServiceData, svr bool) *Strea } if e.MethodExpr.Result.Type != expr.Empty { recvName = md.ClientStream.RecvName + recvWithContextName = md.ClientStream.RecvWithContextName recvRef = ed.ResultRef recvConvert = &ConvertData{ SrcName: protoBufGoFullTypeName(e.Response.Message, sd.PkgName, sd.Scope), @@ -1237,26 +1253,32 @@ func buildStreamData(e *expr.GRPCEndpointExpr, sd *ServiceData, svr bool) *Strea } if sendConvert != nil { sendDesc = fmt.Sprintf("%s streams instances of %q to the %q endpoint gRPC stream.", sendName, sendConvert.TgtName, md.Name) + sendWithContextDesc = fmt.Sprintf("%s streams instances of %q to the %q endpoint gRPC stream with context.", sendWithContextName, sendConvert.TgtName, md.Name) } if recvConvert != nil { recvDesc = fmt.Sprintf("%s reads instances of %q from the %q endpoint gRPC stream.", recvName, recvConvert.SrcName, md.Name) + recvWithContextDesc = fmt.Sprintf("%s reads instances of %q from the %q endpoint gRPC stream with context.", recvWithContextName, recvConvert.SrcName, md.Name) } } return &StreamData{ - VarName: varn, - Type: typ, - Interface: intName, - ServiceInterface: svcInt, - Endpoint: ed, - SendName: sendName, - SendDesc: sendDesc, - SendRef: sendRef, - SendConvert: sendConvert, - RecvName: recvName, - RecvDesc: recvDesc, - RecvRef: recvRef, - RecvConvert: recvConvert, - MustClose: mustClose, + VarName: varn, + Type: typ, + Interface: intName, + ServiceInterface: svcInt, + Endpoint: ed, + SendName: sendName, + SendDesc: sendDesc, + SendWithContextName: sendWithContextName, + SendWithContextDesc: sendWithContextDesc, + SendRef: sendRef, + SendConvert: sendConvert, + RecvName: recvName, + RecvDesc: recvDesc, + RecvWithContextName: recvWithContextName, + RecvWithContextDesc: recvWithContextDesc, + RecvRef: recvRef, + RecvConvert: recvConvert, + MustClose: mustClose, } } diff --git a/grpc/codegen/templates/stream_recv.go.tpl b/grpc/codegen/templates/stream_recv.go.tpl index 593ce4de98..490bdf24f6 100644 --- a/grpc/codegen/templates/stream_recv.go.tpl +++ b/grpc/codegen/templates/stream_recv.go.tpl @@ -21,3 +21,8 @@ func (s *{{ .VarName }}) {{ .RecvName }}() ({{ .RecvRef }}, error) { return {{ .RecvConvert.Init.Name }}({{ range .RecvConvert.Init.Args }}{{ .Name }}, {{ end }}), nil {{- end }} } + +{{ comment .RecvWithContextDesc }} +func (s *{{ .VarName }}) {{ .RecvWithContextName }}(_ context.Context) ({{ .RecvRef }}, error) { + return s.{{ .RecvName }}() +} diff --git a/grpc/codegen/templates/stream_send.go.tpl b/grpc/codegen/templates/stream_send.go.tpl index 7a66cea3d1..503e2087fd 100644 --- a/grpc/codegen/templates/stream_send.go.tpl +++ b/grpc/codegen/templates/stream_send.go.tpl @@ -10,3 +10,8 @@ func (s *{{ .VarName }}) {{ .SendName }}(res {{ .SendRef }}) error { v := {{ .SendConvert.Init.Name }}({{ if and .Endpoint.Method.ViewedResult (eq .Type "server") }}vres.Projected{{ else }}res{{ end }}) return s.stream.{{ .SendName }}(v) } + +{{ comment .SendWithContextDesc }} +func (s *{{ .VarName }}) {{ .SendWithContextName }}(_ context.Context, res {{ .SendRef }}) error { + return s.{{ .SendName }}(res) +} diff --git a/http/codegen/templates/websocket_recv.go.tpl b/http/codegen/templates/websocket_recv.go.tpl index ee9e732b72..4f94d981fb 100644 --- a/http/codegen/templates/websocket_recv.go.tpl +++ b/http/codegen/templates/websocket_recv.go.tpl @@ -83,3 +83,8 @@ func (s *{{ .VarName }}) {{ .RecvName }}() ({{ .RecvTypeRef }}, error) { {{- end }} {{- end }} } + +{{ comment .RecvWithContextDesc }} +func (s *{{ .VarName }}) {{ .RecvWithContextName }}(_ context.Context) ({{ .RecvTypeRef }}, error) { + return s.{{ .RecvName }}() +} diff --git a/http/codegen/templates/websocket_send.go.tpl b/http/codegen/templates/websocket_send.go.tpl index d47846bc95..7fee3762c5 100644 --- a/http/codegen/templates/websocket_send.go.tpl +++ b/http/codegen/templates/websocket_send.go.tpl @@ -52,3 +52,8 @@ func (s *{{ .VarName }}) {{ .SendName }}(v {{ .SendTypeRef }}) error { {{- end }} {{- end }} } + +{{ comment .SendWithContextDesc }} +func (s *{{ .VarName }}) {{ .SendWithContextName }}(_ context.Context, v {{ .SendTypeRef }}) error { + return s.{{ .SendName }}(v) +} diff --git a/http/codegen/websocket.go b/http/codegen/websocket.go index 59f52f7b10..1c60fa1624 100644 --- a/http/codegen/websocket.go +++ b/http/codegen/websocket.go @@ -32,6 +32,10 @@ type ( SendName string // SendDesc is the description for the send function. SendDesc string + // SendWithContextName is the name of the send function with context. + SendWithContextName string + // SendWithContextDesc is the description for the send function with context. + SendWithContextDesc string // SendTypeName is the fully qualified type name sent through // the stream. SendTypeName string @@ -42,6 +46,10 @@ type ( RecvName string // RecvDesc is the description for the recv function. RecvDesc string + // RecvWithContextName is the name of the receive function with context. + RecvWithContextName string + // RecvWithContextDesc is the description for the recv function with context. + RecvWithContextDesc string // RecvTypeName is the fully qualified type name received from // the stream. RecvTypeName string @@ -67,16 +75,20 @@ type ( // initWebSocketData initializes the WebSocket related data in ed. func initWebSocketData(ed *EndpointData, e *expr.HTTPEndpointExpr, sd *ServiceData) { var ( - svrSendTypeName string - svrSendTypeRef string - svrRecvTypeName string - svrRecvTypeRef string - svrSendDesc string - svrRecvDesc string - svrPayload *TypeData - cliSendDesc string - cliRecvDesc string - cliPayload *TypeData + svrSendTypeName string + svrSendTypeRef string + svrRecvTypeName string + svrRecvTypeRef string + svrSendDesc string + svrSendWithContextDesc string + svrRecvDesc string + svrRecvWithContextDesc string + svrPayload *TypeData + cliSendDesc string + cliSendWithContextDesc string + cliRecvDesc string + cliRecvWithContextDesc string + cliPayload *TypeData md = ed.Method svc = sd.Service @@ -86,7 +98,9 @@ func initWebSocketData(ed *EndpointData, e *expr.HTTPEndpointExpr, sd *ServiceDa svrSendTypeName = ed.Result.Name svrSendTypeRef = ed.Result.Ref svrSendDesc = fmt.Sprintf("%s streams instances of %q to the %q endpoint websocket connection.", md.ServerStream.SendName, svrSendTypeName, md.Name) + svrSendWithContextDesc = fmt.Sprintf("%s streams instances of %q to the %q endpoint websocket connection with context.", md.ServerStream.SendWithContextName, svrSendTypeName, md.Name) cliRecvDesc = fmt.Sprintf("%s reads instances of %q from the %q endpoint websocket connection.", md.ClientStream.RecvName, svrSendTypeName, md.Name) + cliRecvWithContextDesc = fmt.Sprintf("%s reads instances of %q from the %q endpoint websocket connection with context.", md.ClientStream.RecvWithContextName, svrSendTypeName, md.Name) if e.MethodExpr.Stream == expr.ClientStreamKind || e.MethodExpr.Stream == expr.BidirectionalStreamKind { svrRecvTypeName = sd.Scope.GoFullTypeName(e.MethodExpr.StreamingPayload, svc.PkgName) svrRecvTypeRef = sd.Scope.GoFullTypeRef(e.MethodExpr.StreamingPayload, svc.PkgName) @@ -175,50 +189,62 @@ func initWebSocketData(ed *EndpointData, e *expr.HTTPEndpointExpr, sd *ServiceDa } if e.MethodExpr.Stream == expr.ClientStreamKind { svrSendDesc = fmt.Sprintf("%s streams instances of %q to the %q endpoint websocket connection and closes the connection.", md.ServerStream.SendName, svrSendTypeName, md.Name) + svrSendWithContextDesc = fmt.Sprintf("%s streams instances of %q to the %q endpoint websocket connection with context and closes the connection.", md.ServerStream.SendWithContextName, svrSendTypeName, md.Name) cliRecvDesc = fmt.Sprintf("%s stops sending messages to the %q endpoint websocket connection and reads instances of %q from the connection.", md.ClientStream.RecvName, md.Name, svrSendTypeName) + cliRecvWithContextDesc = fmt.Sprintf("%s stops sending messages to the %q endpoint websocket connection with context and reads instances of %q from the connection.", md.ClientStream.RecvWithContextName, md.Name, svrSendTypeName) } svrRecvDesc = fmt.Sprintf("%s reads instances of %q from the %q endpoint websocket connection.", md.ServerStream.RecvName, svrRecvTypeName, md.Name) + svrRecvWithContextDesc = fmt.Sprintf("%s reads instances of %q from the %q endpoint websocket connection with context.", md.ServerStream.RecvWithContextName, svrRecvTypeName, md.Name) cliSendDesc = fmt.Sprintf("%s streams instances of %q to the %q endpoint websocket connection.", md.ClientStream.SendName, svrRecvTypeName, md.Name) + cliSendWithContextDesc = fmt.Sprintf("%s streams instances of %q to the %q endpoint websocket connection with context.", md.ClientStream.SendWithContextName, svrRecvTypeName, md.Name) } } ed.ServerWebSocket = &WebSocketData{ - VarName: md.ServerStream.VarName, - Interface: fmt.Sprintf("%s.%s", svc.PkgName, md.ServerStream.Interface), - Endpoint: ed, - Payload: svrPayload, - Response: ed.Result.Responses[0], - PkgName: svc.PkgName, - Type: "server", - Kind: md.ServerStream.Kind, - SendName: md.ServerStream.SendName, - SendDesc: svrSendDesc, - SendTypeName: svrSendTypeName, - SendTypeRef: svrSendTypeRef, - RecvName: md.ServerStream.RecvName, - RecvDesc: svrRecvDesc, - RecvTypeName: svrRecvTypeName, - RecvTypeRef: svrRecvTypeRef, - RecvTypeIsPointer: expr.IsArray(e.MethodExpr.StreamingPayload.Type) || expr.IsMap(e.MethodExpr.StreamingPayload.Type), - MustClose: md.ServerStream.MustClose, + VarName: md.ServerStream.VarName, + Interface: fmt.Sprintf("%s.%s", svc.PkgName, md.ServerStream.Interface), + Endpoint: ed, + Payload: svrPayload, + Response: ed.Result.Responses[0], + PkgName: svc.PkgName, + Type: "server", + Kind: md.ServerStream.Kind, + SendName: md.ServerStream.SendName, + SendDesc: svrSendDesc, + SendWithContextName: md.ServerStream.SendWithContextName, + SendWithContextDesc: svrSendWithContextDesc, + SendTypeName: svrSendTypeName, + SendTypeRef: svrSendTypeRef, + RecvName: md.ServerStream.RecvName, + RecvDesc: svrRecvDesc, + RecvWithContextName: md.ServerStream.RecvWithContextName, + RecvWithContextDesc: svrRecvWithContextDesc, + RecvTypeName: svrRecvTypeName, + RecvTypeRef: svrRecvTypeRef, + RecvTypeIsPointer: expr.IsArray(e.MethodExpr.StreamingPayload.Type) || expr.IsMap(e.MethodExpr.StreamingPayload.Type), + MustClose: md.ServerStream.MustClose, } ed.ClientWebSocket = &WebSocketData{ - VarName: md.ClientStream.VarName, - Interface: fmt.Sprintf("%s.%s", svc.PkgName, md.ClientStream.Interface), - Endpoint: ed, - Payload: cliPayload, - Response: ed.Result.Responses[0], - PkgName: svc.PkgName, - Type: "client", - Kind: md.ClientStream.Kind, - SendName: md.ClientStream.SendName, - SendDesc: cliSendDesc, - SendTypeName: svrRecvTypeName, - SendTypeRef: svrRecvTypeRef, - RecvName: md.ClientStream.RecvName, - RecvDesc: cliRecvDesc, - RecvTypeName: svrSendTypeName, - RecvTypeRef: svrSendTypeRef, - MustClose: md.ClientStream.MustClose, + VarName: md.ClientStream.VarName, + Interface: fmt.Sprintf("%s.%s", svc.PkgName, md.ClientStream.Interface), + Endpoint: ed, + Payload: cliPayload, + Response: ed.Result.Responses[0], + PkgName: svc.PkgName, + Type: "client", + Kind: md.ClientStream.Kind, + SendName: md.ClientStream.SendName, + SendDesc: cliSendDesc, + SendWithContextName: md.ClientStream.SendWithContextName, + SendWithContextDesc: cliSendWithContextDesc, + SendTypeName: svrRecvTypeName, + SendTypeRef: svrRecvTypeRef, + RecvName: md.ClientStream.RecvName, + RecvDesc: cliRecvDesc, + RecvWithContextName: md.ClientStream.RecvWithContextName, + RecvWithContextDesc: cliRecvWithContextDesc, + RecvTypeName: svrSendTypeName, + RecvTypeRef: svrSendTypeRef, + MustClose: md.ClientStream.MustClose, } } From 59059581530ab7a25c6ef41255da0f4440973441 Mon Sep 17 00:00:00 2001 From: Douglas Thrift Date: Wed, 29 Jan 2025 17:43:19 -0800 Subject: [PATCH 08/23] Progress on wrapping streams with interceptors --- codegen/service/interceptors.go | 36 +++++++- codegen/service/service_data.go | 77 +++++++++++----- .../client_interceptor_wrappers.go.tpl | 77 ++++++++++++++-- .../server_interceptor_wrappers.go.tpl | 90 +++++++++++++++++++ ...nterceptors_interceptor_wrappers.go.golden | 32 +++++-- 5 files changed, 273 insertions(+), 39 deletions(-) diff --git a/codegen/service/interceptors.go b/codegen/service/interceptors.go index 011b05eb00..67a7021d3b 100644 --- a/codegen/service/interceptors.go +++ b/codegen/service/interceptors.go @@ -146,8 +146,9 @@ func wrapperFile(svc *Data) *codegen.File { Name: "server-interceptor-wrappers", Source: readTemplate("server_interceptor_wrappers"), Data: map[string]interface{}{ - "Service": svc.Name, - "ServerInterceptors": svc.ServerInterceptors, + "Service": svc.Name, + "ServerInterceptors": svc.ServerInterceptors, + "WrappedServerStreams": collectWrappedStreams(svc.ServerInterceptors, true), }, }) } @@ -156,8 +157,9 @@ func wrapperFile(svc *Data) *codegen.File { Name: "client-interceptor-wrappers", Source: readTemplate("client_interceptor_wrappers"), Data: map[string]interface{}{ - "Service": svc.Name, - "ClientInterceptors": svc.ClientInterceptors, + "Service": svc.Name, + "ClientInterceptors": svc.ClientInterceptors, + "WrappedClientStreams": collectWrappedStreams(svc.ClientInterceptors, false), }, }) } @@ -178,3 +180,29 @@ func hasPrivateImplementationTypes(interceptors []*InterceptorData) bool { } return false } + +// collectWrappedStreams returns a slice of streams to be wrapped by interceptor wrapper functions. +func collectWrappedStreams(interceptors []*InterceptorData, server bool) []*StreamInterceptorData { + var ( + streams []*StreamInterceptorData + streamNames = make(map[string]struct{}) + ) + for _, intr := range interceptors { + if intr.HasStreamingPayloadAccess || intr.HasStreamingResultAccess { + for _, method := range intr.Methods { + if server { + if _, ok := streamNames[method.ServerStream.Interface]; !ok { + streams = append(streams, method.ServerStream) + streamNames[method.ServerStream.Interface] = struct{}{} + } + } else { + if _, ok := streamNames[method.ClientStream.Interface]; !ok { + streams = append(streams, method.ClientStream) + streamNames[method.ClientStream.Interface] = struct{}{} + } + } + } + } + } + return streams +} diff --git a/codegen/service/service_data.go b/codegen/service/service_data.go index f8494d139c..8e68071499 100644 --- a/codegen/service/service_data.go +++ b/codegen/service/service_data.go @@ -320,12 +320,31 @@ type ( StreamingPayloadRef string // StreamingResultRef is the reference to the streaming result type. StreamingResultRef string - // ServerStreamInputStruct is the name of the server stream input - // struct if the endpoint defines a server stream. - ServerStreamInputStruct string - // ClientStreamInputStruct is the name of the client stream input - // struct if the endpoint defines a client stream. - ClientStreamInputStruct string + // ServerStream is the stream data if the endpoint defines a server stream. + ServerStream *StreamInterceptorData + // ClientStream is the stream data if the endpoint defines a client stream. + ClientStream *StreamInterceptorData + } + + // StreamInterceptorData is the stream data for an interceptor. + StreamInterceptorData struct { + // Interface is the name of the stream interface. + Interface string + // SendName is the name of the send function. + SendName string + // SendWithContextName is the name of the send function with context. + SendWithContextName string + // SendTypeRef is the reference to the type sent through the stream. + SendTypeRef string + // RecvName is the name of the recv function. + RecvName string + // RecvWithContextName is the name of the recv function with context. + RecvWithContextName string + // RecvTypeRef is the reference to the type received from the stream. + RecvTypeRef string + // MustClose indicates whether the stream should implement the Close() + // function. + MustClose bool } // AttributeData describes a single attribute. @@ -1306,12 +1325,30 @@ func buildInterceptorData(svc *expr.ServiceExpr, methods []*MethodData, i *expr. // buildInterceptorMethodData creates the data needed to generate interceptor // method code. func buildInterceptorMethodData(i *expr.InterceptorExpr, md *MethodData) *MethodInterceptorData { - var serverStream, clientStream string + var serverStream, clientStream *StreamInterceptorData if md.ServerStream != nil { - serverStream = md.ServerStream.VarName + serverStream = &StreamInterceptorData{ + Interface: md.ServerStream.Interface, + SendName: md.ServerStream.SendName, + SendWithContextName: md.ServerStream.SendWithContextName, + SendTypeRef: md.ServerStream.SendTypeRef, + RecvName: md.ServerStream.RecvName, + RecvWithContextName: md.ServerStream.RecvWithContextName, + RecvTypeRef: md.ServerStream.RecvTypeRef, + MustClose: md.ServerStream.MustClose, + } } if md.ClientStream != nil { - clientStream = md.ClientStream.VarName + clientStream = &StreamInterceptorData{ + Interface: md.ClientStream.Interface, + SendName: md.ClientStream.SendName, + SendWithContextName: md.ClientStream.SendWithContextName, + SendTypeRef: md.ClientStream.SendTypeRef, + RecvName: md.ClientStream.RecvName, + RecvWithContextName: md.ClientStream.RecvWithContextName, + RecvTypeRef: md.ClientStream.RecvTypeRef, + MustClose: md.ClientStream.MustClose, + } } var payloadAccess, resultAccess, streamingPayloadAccess, streamingResultAccess string if i.ReadPayload != nil || i.WritePayload != nil { @@ -1327,17 +1364,17 @@ func buildInterceptorMethodData(i *expr.InterceptorExpr, md *MethodData) *Method streamingResultAccess = codegen.Goify(i.Name, false) + md.VarName + "StreamingResult" } return &MethodInterceptorData{ - MethodName: md.VarName, - PayloadAccess: payloadAccess, - ResultAccess: resultAccess, - PayloadRef: md.PayloadRef, - ResultRef: md.ResultRef, - StreamingPayloadAccess: streamingPayloadAccess, - StreamingPayloadRef: md.StreamingPayloadRef, - StreamingResultAccess: streamingResultAccess, - StreamingResultRef: md.ResultRef, - ClientStreamInputStruct: clientStream, - ServerStreamInputStruct: serverStream, + MethodName: md.VarName, + PayloadAccess: payloadAccess, + ResultAccess: resultAccess, + PayloadRef: md.PayloadRef, + ResultRef: md.ResultRef, + StreamingPayloadAccess: streamingPayloadAccess, + StreamingPayloadRef: md.StreamingPayloadRef, + StreamingResultAccess: streamingResultAccess, + StreamingResultRef: md.ResultRef, + ClientStream: clientStream, + ServerStream: serverStream, } } diff --git a/codegen/service/templates/client_interceptor_wrappers.go.tpl b/codegen/service/templates/client_interceptor_wrappers.go.tpl index 4b53b4e4ab..74f8fb0122 100644 --- a/codegen/service/templates/client_interceptor_wrappers.go.tpl +++ b/codegen/service/templates/client_interceptor_wrappers.go.tpl @@ -4,15 +4,74 @@ {{ comment (printf "wrapClient%s%s applies the %s client interceptor to endpoints." $interceptor.Name .MethodName $interceptor.DesignName) }} func wrapClient{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { - return func(ctx context.Context, req any) (any, error) { - info := &{{ $interceptor.Name }}Info{ - Service: "{{ $.Service }}", - Method: "{{ .MethodName }}", - Endpoint: endpoint, - RawPayload: req, - } - return i.{{ $interceptor.Name }}(ctx, info, endpoint) - } + return func(ctx context.Context, req any) (any, error) { + {{- if or $interceptor.HasStreamingPayloadAccess $interceptor.HasStreamingResultAccess }} + {{- if $interceptor.HasPayloadAccess }} + info := &{{ $interceptor.Name }}Info{ + Service: "{{ $.Service }}", + Method: "{{ .MethodName }}", + Endpoint: endpoint, + RawPayload: req, + } + res, err := i.{{ $interceptor.Name }}(ctx, info, endpoint) + {{- else }} + res, err := endpoint(ctx, req) + {{- end }} + if err != nil { + return nil, err + } + stream := res.({{ .ClientStream.Interface }}) + return &wrapped{{ .ClientStream.Interface }}{ + ctx: ctx, + {{- if $interceptor.HasStreamingPayloadAccess }} + sendEndpoint: func(ctx context.Context, req any) (any, error) { + info := &{{ $interceptor.Name }}Info{ + Service: "{{ $.Service }}", + Method: "{{ .MethodName }}.{{ .ClientStream.SendWithContextName }}", + Endpoint: endpoint, + RawPayload: req, + } + return i.{{ $interceptor.Name }}(ctx, info, endpoint) + }, + {{- end }} + {{- if $interceptor.HasStreamingResultAccess }} + recvEndpoint: func(ctx context.Context, req any) (any, error) { + info := &{{ $interceptor.Name }}Info{ + Service: "{{ $.Service }}", + Method: "{{ .MethodName }}.{{ .ClientStream.RecvWithContextName }}", + Endpoint: endpoint, + RawPayload: req, + } + return i.{{ $interceptor.Name }}(ctx, info, endpoint) + }, + {{- end }} + stream: stream, + }, nil + {{- else }} + info := &{{ $interceptor.Name }}Info{ + Service: "{{ $.Service }}", + Method: "{{ .MethodName }}", + Endpoint: endpoint, + RawPayload: req, + } + return i.{{ $interceptor.Name }}(ctx, info, endpoint) + {{- end }} + } +} +{{ end }} +{{- end }} +{{- range .WrappedClientStreams }} + +{{ comment (printf "wrapped%s is a client interceptor wrapper for the %s stream." .Interface .Interface) }} +type wrapped{{ .Interface }} struct { + ctx context.Context + sendEndpoint, recvEndpoint goa.Endpoint + stream {{ .Interface }} +} + +{{ if .MustClose }} +func (w *wrapped{{ .Interface }}) Close() error { + return w.stream.Close() } {{ end }} {{- end }} diff --git a/codegen/service/templates/server_interceptor_wrappers.go.tpl b/codegen/service/templates/server_interceptor_wrappers.go.tpl index 6e45db7afe..d6e57c233e 100644 --- a/codegen/service/templates/server_interceptor_wrappers.go.tpl +++ b/codegen/service/templates/server_interceptor_wrappers.go.tpl @@ -5,6 +5,49 @@ {{ comment (printf "wrap%s%s applies the %s server interceptor to endpoints." $interceptor.Name .MethodName $interceptor.DesignName) }} func wrap{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { return func(ctx context.Context, req any) (any, error) { + {{- if or $interceptor.HasStreamingPayloadAccess $interceptor.HasStreamingResultAccess }} + {{- if $interceptor.HasPayloadAccess }} + info := &{{ $interceptor.Name }}Info{ + Service: "{{ $.Service }}", + Method: "{{ .MethodName }}", + Endpoint: endpoint, + RawPayload: req, + } + res, err := i.{{ $interceptor.Name }}(ctx, info, endpoint) + {{- else }} + res, err := endpoint(ctx, req) + {{- end }} + if err != nil { + return nil, err + } + stream := res.({{ .ServerStream.Interface }}) + return &wrapped{{ .ServerStream.Interface }}{ + ctx: ctx, + {{- if $interceptor.HasStreamingResultAccess }} + sendEndpoint: func(ctx context.Context, req any) (any, error) { + info := &{{ $interceptor.Name }}Info{ + Service: "{{ $.Service }}", + Method: "{{ .MethodName }}.{{ .ServerStream.SendWithContextName }}", + Endpoint: endpoint, + RawPayload: req, + } + return i.{{ $interceptor.Name }}(ctx, info, endpoint) + }, + {{- end }} + {{- if $interceptor.HasStreamingPayloadAccess }} + recvEndpoint: func(ctx context.Context, req any) (any, error) { + info := &{{ $interceptor.Name }}Info{ + Service: "{{ $.Service }}", + Method: "{{ .MethodName }}.{{ .ServerStream.RecvWithContextName }}", + Endpoint: endpoint, + RawPayload: req, + } + return i.{{ $interceptor.Name }}(ctx, info, endpoint) + }, + {{- end }} + stream: stream, + }, nil + {{- else }} info := &{{ $interceptor.Name }}Info{ Service: "{{ $.Service }}", Method: "{{ .MethodName }}", @@ -12,7 +55,54 @@ func wrap{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i Serve RawPayload: req, } return i.{{ $interceptor.Name }}(ctx, info, endpoint) + {{- end }} + } +} +{{- end }} +{{- end }} +{{- range .WrappedServerStreams }} + +{{ comment (printf "wrapped%s is a server interceptor wrapper for the %s stream." .Interface .Interface) }} +type wrapped{{ .Interface }} struct { + ctx context.Context + sendEndpoint, recvEndpoint goa.Endpoint + stream {{ .Interface }} +} +{{- if ne .SendWithContextName "" }} + +func (w *wrapped{{ .Interface }}) {{ .SendName }}(res {{ .SendTypeRef }}) error { + return w.SendWithContext(w.ctx, res) +} + +func (w *wrapped{{ .Interface }}) {{ .SendWithContextName }}(ctx context.Context, res {{ .SendTypeRef }}) error { + if w.sendEndpoint == nil { + return w.stream.{{ .SendWithContextName }}(ctx, res) } + _, err := w.sendEndpoint(ctx, res) + return err +} +{{- end }} +{{- if ne .RecvWithContextName "" }} + +func (w *wrapped{{ .Interface }}) {{ .RecvName }}() ({{ .RecvTypeRef }}, error) { + return w.RecvWithContext(w.ctx) +} + +func (w *wrapped{{ .Interface }}) {{ .RecvWithContextName }}(ctx context.Context) ({{ .RecvTypeRef }}, error) { + if w.recvEndpoint == nil { + return w.stream.{{ .RecvWithContextName }}(ctx) + } + res, err := w.recvEndpoint(ctx, nil) + if err != nil { + return nil, err + } + return res.({{ .RecvTypeRef }}), nil +} +{{- end }} +{{- if .MustClose }} + +func (w *wrapped{{ .Interface }}) Close() error { + return w.stream.Close() } {{- end }} {{- end }} diff --git a/codegen/service/testdata/interceptors/streaming-interceptors_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors_interceptor_wrappers.go.golden index e42932575b..8475c33ba6 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors_interceptor_wrappers.go.golden @@ -3,12 +3,32 @@ // wrapLoggingMethod applies the logging server interceptor to endpoints. func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { return func(ctx context.Context, req any) (any, error) { - info := &LoggingInfo{ - Service: "StreamingInterceptors", - Method: "Method", - Endpoint: endpoint, - RawPayload: req, + res, err := endpoint(ctx, req) + if err != nil { + return nil, err } - return i.Logging(ctx, info, endpoint) + stream := res.(MethodServerStream) + return &wrappedMethodServerStream{ + ctx: ctx, + sendEndpoint: func(ctx context.Context, req any) (any, error) { + info := &LoggingInfo{ + Service: "StreamingInterceptors", + Method: "Method.SendWithContext", + Endpoint: endpoint, + RawPayload: req, + } + return i.Logging(ctx, info, endpoint) + }, + recvEndpoint: func(ctx context.Context) (any, error) { + info := &LoggingInfo{ + Service: "StreamingInterceptors", + Method: "Method.RecvWithContext", + Endpoint: endpoint, + RawPayload: nil, + } + return i.Logging(ctx, info, endpoint) + }, + stream: stream, + }, nil } } From 6e8e7465fa1445207fdbe2b6a6d8736dcd18eccc Mon Sep 17 00:00:00 2001 From: Douglas Thrift Date: Thu, 30 Jan 2025 16:17:39 -0800 Subject: [PATCH 09/23] Finish generating the stream wrapping for interceptors; remove the Endpoint field from goa.InterceptorInfo struct since it is redundant with the next goa.Endpoint parameter sent to interceptors --- .../client_interceptor_wrappers.go.tpl | 62 +++++++++++++++---- .../server_interceptor_wrappers.go.tpl | 59 ++++++++++-------- codegen/service/templates/service.go.tpl | 4 +- grpc/codegen/templates/stream_recv.go.tpl | 5 +- grpc/codegen/templates/stream_send.go.tpl | 4 +- http/codegen/templates/websocket_recv.go.tpl | 5 +- http/codegen/templates/websocket_send.go.tpl | 4 +- pkg/interceptor.go | 2 - 8 files changed, 97 insertions(+), 48 deletions(-) diff --git a/codegen/service/templates/client_interceptor_wrappers.go.tpl b/codegen/service/templates/client_interceptor_wrappers.go.tpl index 74f8fb0122..b8418282e8 100644 --- a/codegen/service/templates/client_interceptor_wrappers.go.tpl +++ b/codegen/service/templates/client_interceptor_wrappers.go.tpl @@ -10,7 +10,6 @@ func wrapClient{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i info := &{{ $interceptor.Name }}Info{ Service: "{{ $.Service }}", Method: "{{ .MethodName }}", - Endpoint: endpoint, RawPayload: req, } res, err := i.{{ $interceptor.Name }}(ctx, info, endpoint) @@ -24,25 +23,38 @@ func wrapClient{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i return &wrapped{{ .ClientStream.Interface }}{ ctx: ctx, {{- if $interceptor.HasStreamingPayloadAccess }} - sendEndpoint: func(ctx context.Context, req any) (any, error) { + sendWithContext: func(ctx context.Context, req {{ .ClientStream.SendTypeRef }}) (context.Context, error) { info := &{{ $interceptor.Name }}Info{ Service: "{{ $.Service }}", Method: "{{ .MethodName }}.{{ .ClientStream.SendWithContextName }}", - Endpoint: endpoint, RawPayload: req, } - return i.{{ $interceptor.Name }}(ctx, info, endpoint) + var rCtx context.Context + _, err := i.{{ $interceptor.Name }}(ctx, info, func(ctx context.Context, req any) (any, error) { + var err error + rCtx, err = stream.{{ .ClientStream.SendWithContextName }}(ctx, req.({{ .ClientStream.SendTypeRef }})) + return nil, err + }) + return rCtx, err }, {{- end }} {{- if $interceptor.HasStreamingResultAccess }} - recvEndpoint: func(ctx context.Context, req any) (any, error) { + recvWithContext: func(ctx context.Context) ({{ .ClientStream.RecvTypeRef }}, context.Context, error) { info := &{{ $interceptor.Name }}Info{ Service: "{{ $.Service }}", Method: "{{ .MethodName }}.{{ .ClientStream.RecvWithContextName }}", - Endpoint: endpoint, RawPayload: req, } - return i.{{ $interceptor.Name }}(ctx, info, endpoint) + var rCtx context.Context + res, err := i.{{ $interceptor.Name }}(ctx, info, func(ctx context.Context, req any) (any, error) { + var ( + res {{ .ClientStream.RecvTypeRef }} + err error + ) + res, rCtx, err = stream.{{ .ClientStream.RecvWithContextName }}(ctx) + return res, err + }) + return res.({{ .ClientStream.RecvTypeRef }}), rCtx, err }, {{- end }} stream: stream, @@ -51,7 +63,6 @@ func wrapClient{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i info := &{{ $interceptor.Name }}Info{ Service: "{{ $.Service }}", Method: "{{ .MethodName }}", - Endpoint: endpoint, RawPayload: req, } return i.{{ $interceptor.Name }}(ctx, info, endpoint) @@ -65,13 +76,42 @@ func wrapClient{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i {{ comment (printf "wrapped%s is a client interceptor wrapper for the %s stream." .Interface .Interface) }} type wrapped{{ .Interface }} struct { ctx context.Context - sendEndpoint, recvEndpoint goa.Endpoint + sendWithContext func(context.Context, {{ .SendTypeRef }}) (context.Context, error) + recvWithContext func(context.Context) ({{ .RecvTypeRef }}, context.Context, error) stream {{ .Interface }} } +{{- if ne .SendWithContextName "" }} + +func (w *wrapped{{ .Interface }}) {{ .SendName }}(v {{ .SendTypeRef }}) error { + _, err := w.SendWithContext(w.ctx, v) + return err +} + +func (w *wrapped{{ .Interface }}) {{ .SendWithContextName }}(ctx context.Context, v {{ .SendTypeRef }}) (context.Context, error) { + if w.sendWithContext == nil { + return w.stream.{{ .SendWithContextName }}(ctx, v) + } + return w.sendWithContext(ctx, v) +} +{{- end }} +{{- if ne .RecvWithContextName "" }} + +func (w *wrapped{{ .Interface }}) {{ .RecvName }}() ({{ .RecvTypeRef }}, error) { + res, _, err := w.RecvWithContext(w.ctx) + return res, err +} + +func (w *wrapped{{ .Interface }}) {{ .RecvWithContextName }}(ctx context.Context) ({{ .RecvTypeRef }}, context.Context, error) { + if w.recvWithContext == nil { + return w.stream.{{ .RecvWithContextName }}(ctx) + } + return w.recvWithContext(ctx) +} +{{- end }} +{{- if .MustClose }} -{{ if .MustClose }} func (w *wrapped{{ .Interface }}) Close() error { return w.stream.Close() } -{{ end }} +{{- end }} {{- end }} diff --git a/codegen/service/templates/server_interceptor_wrappers.go.tpl b/codegen/service/templates/server_interceptor_wrappers.go.tpl index d6e57c233e..68902f0bce 100644 --- a/codegen/service/templates/server_interceptor_wrappers.go.tpl +++ b/codegen/service/templates/server_interceptor_wrappers.go.tpl @@ -10,7 +10,6 @@ func wrap{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i Serve info := &{{ $interceptor.Name }}Info{ Service: "{{ $.Service }}", Method: "{{ .MethodName }}", - Endpoint: endpoint, RawPayload: req, } res, err := i.{{ $interceptor.Name }}(ctx, info, endpoint) @@ -22,27 +21,40 @@ func wrap{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i Serve } stream := res.({{ .ServerStream.Interface }}) return &wrapped{{ .ServerStream.Interface }}{ - ctx: ctx, + ctx: ctx, {{- if $interceptor.HasStreamingResultAccess }} - sendEndpoint: func(ctx context.Context, req any) (any, error) { + sendWithContext: func(ctx context.Context, req {{ .ServerStream.SendTypeRef }}) (context.Context, error) { info := &{{ $interceptor.Name }}Info{ Service: "{{ $.Service }}", Method: "{{ .MethodName }}.{{ .ServerStream.SendWithContextName }}", - Endpoint: endpoint, RawPayload: req, } - return i.{{ $interceptor.Name }}(ctx, info, endpoint) + var rCtx context.Context + _, err := i.{{ $interceptor.Name }}(ctx, info, func(ctx context.Context, req any) (any, error) { + var err error + rCtx, err = stream.{{ .ServerStream.SendWithContextName }}(ctx, req.({{ .ServerStream.SendTypeRef }})) + return nil, err + }) + return rCtx, err }, {{- end }} {{- if $interceptor.HasStreamingPayloadAccess }} - recvEndpoint: func(ctx context.Context, req any) (any, error) { + recvWithContext: func(ctx context.Context) ({{ .ServerStream.RecvTypeRef }}, context.Context, error) { info := &{{ $interceptor.Name }}Info{ Service: "{{ $.Service }}", Method: "{{ .MethodName }}.{{ .ServerStream.RecvWithContextName }}", - Endpoint: endpoint, RawPayload: req, } - return i.{{ $interceptor.Name }}(ctx, info, endpoint) + var rCtx context.Context + res, err := i.{{ $interceptor.Name }}(ctx, info, func(ctx context.Context, req any) (any, error) { + var ( + res {{ .ServerStream.RecvTypeRef }} + err error + ) + res, rCtx, err = stream.{{ .ServerStream.RecvWithContextName }}(ctx) + return res, err + }) + return res.({{ .ServerStream.RecvTypeRef }}), rCtx, err }, {{- end }} stream: stream, @@ -51,7 +63,6 @@ func wrap{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i Serve info := &{{ $interceptor.Name }}Info{ Service: "{{ $.Service }}", Method: "{{ .MethodName }}", - Endpoint: endpoint, RawPayload: req, } return i.{{ $interceptor.Name }}(ctx, info, endpoint) @@ -65,38 +76,36 @@ func wrap{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i Serve {{ comment (printf "wrapped%s is a server interceptor wrapper for the %s stream." .Interface .Interface) }} type wrapped{{ .Interface }} struct { ctx context.Context - sendEndpoint, recvEndpoint goa.Endpoint + sendWithContext func(context.Context, {{ .SendTypeRef }}) (context.Context, error) + recvWithContext func(context.Context) ({{ .RecvTypeRef }}, context.Context, error) stream {{ .Interface }} } {{- if ne .SendWithContextName "" }} -func (w *wrapped{{ .Interface }}) {{ .SendName }}(res {{ .SendTypeRef }}) error { - return w.SendWithContext(w.ctx, res) +func (w *wrapped{{ .Interface }}) {{ .SendName }}(v {{ .SendTypeRef }}) error { + _, err := w.SendWithContext(w.ctx, v) + return err } -func (w *wrapped{{ .Interface }}) {{ .SendWithContextName }}(ctx context.Context, res {{ .SendTypeRef }}) error { - if w.sendEndpoint == nil { - return w.stream.{{ .SendWithContextName }}(ctx, res) +func (w *wrapped{{ .Interface }}) {{ .SendWithContextName }}(ctx context.Context, v {{ .SendTypeRef }}) (context.Context, error) { + if w.sendWithContext == nil { + return w.stream.{{ .SendWithContextName }}(ctx, v) } - _, err := w.sendEndpoint(ctx, res) - return err + return w.sendWithContext(ctx, v) } {{- end }} {{- if ne .RecvWithContextName "" }} func (w *wrapped{{ .Interface }}) {{ .RecvName }}() ({{ .RecvTypeRef }}, error) { - return w.RecvWithContext(w.ctx) + res, _, err := w.RecvWithContext(w.ctx) + return res, err } -func (w *wrapped{{ .Interface }}) {{ .RecvWithContextName }}(ctx context.Context) ({{ .RecvTypeRef }}, error) { - if w.recvEndpoint == nil { +func (w *wrapped{{ .Interface }}) {{ .RecvWithContextName }}(ctx context.Context) ({{ .RecvTypeRef }}, context.Context, error) { + if w.recvWithContext == nil { return w.stream.{{ .RecvWithContextName }}(ctx) } - res, err := w.recvEndpoint(ctx, nil) - if err != nil { - return nil, err - } - return res.({{ .RecvTypeRef }}), nil + return w.recvWithContext(ctx) } {{- end }} {{- if .MustClose }} diff --git a/codegen/service/templates/service.go.tpl b/codegen/service/templates/service.go.tpl index 6a3334a5bd..431769507e 100644 --- a/codegen/service/templates/service.go.tpl +++ b/codegen/service/templates/service.go.tpl @@ -65,13 +65,13 @@ type {{ .Stream.Interface }} interface { {{ comment .Stream.SendDesc }} {{ .Stream.SendName }}({{ .Stream.SendTypeRef }}) error {{ comment .Stream.SendWithContextDesc }} - {{ .Stream.SendWithContextName }}(context.Context, {{ .Stream.SendTypeRef }}) error + {{ .Stream.SendWithContextName }}(context.Context, {{ .Stream.SendTypeRef }}) (context.Context, error) {{- end }} {{- if .Stream.RecvTypeRef }} {{ comment .Stream.RecvDesc }} {{ .Stream.RecvName }}() ({{ .Stream.RecvTypeRef }}, error) {{ comment .Stream.RecvWithContextDesc }} - {{ .Stream.RecvWithContextName }}(context.Context) ({{ .Stream.RecvTypeRef }}, error) + {{ .Stream.RecvWithContextName }}(context.Context) ({{ .Stream.RecvTypeRef }}, context.Context, error) {{- end }} {{- if .Stream.MustClose }} {{ comment "Close closes the stream." }} diff --git a/grpc/codegen/templates/stream_recv.go.tpl b/grpc/codegen/templates/stream_recv.go.tpl index 490bdf24f6..89b1c0cc81 100644 --- a/grpc/codegen/templates/stream_recv.go.tpl +++ b/grpc/codegen/templates/stream_recv.go.tpl @@ -23,6 +23,7 @@ func (s *{{ .VarName }}) {{ .RecvName }}() ({{ .RecvRef }}, error) { } {{ comment .RecvWithContextDesc }} -func (s *{{ .VarName }}) {{ .RecvWithContextName }}(_ context.Context) ({{ .RecvRef }}, error) { - return s.{{ .RecvName }}() +func (s *{{ .VarName }}) {{ .RecvWithContextName }}(ctx context.Context) ({{ .RecvRef }}, context.Context, error) { + res, err := s.{{ .RecvName }}() + return res, ctx, err } diff --git a/grpc/codegen/templates/stream_send.go.tpl b/grpc/codegen/templates/stream_send.go.tpl index 503e2087fd..f723057d96 100644 --- a/grpc/codegen/templates/stream_send.go.tpl +++ b/grpc/codegen/templates/stream_send.go.tpl @@ -12,6 +12,6 @@ func (s *{{ .VarName }}) {{ .SendName }}(res {{ .SendRef }}) error { } {{ comment .SendWithContextDesc }} -func (s *{{ .VarName }}) {{ .SendWithContextName }}(_ context.Context, res {{ .SendRef }}) error { - return s.{{ .SendName }}(res) +func (s *{{ .VarName }}) {{ .SendWithContextName }}(ctx context.Context, res {{ .SendRef }}) (context.Context, error) { + return ctx, s.{{ .SendName }}(res) } diff --git a/http/codegen/templates/websocket_recv.go.tpl b/http/codegen/templates/websocket_recv.go.tpl index 4f94d981fb..5096dd791c 100644 --- a/http/codegen/templates/websocket_recv.go.tpl +++ b/http/codegen/templates/websocket_recv.go.tpl @@ -85,6 +85,7 @@ func (s *{{ .VarName }}) {{ .RecvName }}() ({{ .RecvTypeRef }}, error) { } {{ comment .RecvWithContextDesc }} -func (s *{{ .VarName }}) {{ .RecvWithContextName }}(_ context.Context) ({{ .RecvTypeRef }}, error) { - return s.{{ .RecvName }}() +func (s *{{ .VarName }}) {{ .RecvWithContextName }}(ctx context.Context) ({{ .RecvTypeRef }}, context.Context, error) { + res, err := s.{{ .RecvName }}() + return res, ctx, err } diff --git a/http/codegen/templates/websocket_send.go.tpl b/http/codegen/templates/websocket_send.go.tpl index 7fee3762c5..6272150830 100644 --- a/http/codegen/templates/websocket_send.go.tpl +++ b/http/codegen/templates/websocket_send.go.tpl @@ -54,6 +54,6 @@ func (s *{{ .VarName }}) {{ .SendName }}(v {{ .SendTypeRef }}) error { } {{ comment .SendWithContextDesc }} -func (s *{{ .VarName }}) {{ .SendWithContextName }}(_ context.Context, v {{ .SendTypeRef }}) error { - return s.{{ .SendName }}(v) +func (s *{{ .VarName }}) {{ .SendWithContextName }}(ctx context.Context, v {{ .SendTypeRef }}) (context.Context, error) { + return ctx, s.{{ .SendName }}(v) } diff --git a/pkg/interceptor.go b/pkg/interceptor.go index c784f14b88..269c4e9844 100644 --- a/pkg/interceptor.go +++ b/pkg/interceptor.go @@ -9,8 +9,6 @@ type ( Service string // Name of method handling request Method string - // Endpoint of request, can be used for retrying - Endpoint Endpoint // Payload of request RawPayload any } From 3826f709e6faaeb0f0b4013f849b575914ad5d06 Mon Sep 17 00:00:00 2001 From: Douglas Thrift Date: Thu, 30 Jan 2025 17:46:58 -0800 Subject: [PATCH 10/23] Progress on adding comments and fixing tests; fix a bug where refs were defs --- codegen/service/service_data.go | 2 +- .../client_interceptor_wrappers.go.tpl | 5 + .../server_interceptor_wrappers.go.tpl | 5 + ...ead-payload_interceptor_wrappers.go.golden | 2 - ...read-result_interceptor_wrappers.go.golden | 2 - ...ite-payload_interceptor_wrappers.go.golden | 2 - ...rite-result_interceptor_wrappers.go.golden | 2 - ...ite-payload_interceptor_wrappers.go.golden | 2 - ...rite-result_interceptor_wrappers.go.golden | 2 - ...nterceptors_interceptor_wrappers.go.golden | 4 - ...interceptor_interceptor_wrappers.go.golden | 2 - ...interceptor_interceptor_wrappers.go.golden | 1 - ...interceptor_interceptor_wrappers.go.golden | 1 - ...interceptor_interceptor_wrappers.go.golden | 2 - ...ead-payload_interceptor_wrappers.go.golden | 1 - ...read-result_interceptor_wrappers.go.golden | 1 - ...nterceptors_interceptor_wrappers.go.golden | 73 ++++++++++++-- ...nterceptors_service_interceptors.go.golden | 8 +- codegen/service/testdata/service_code.go | 96 +++++++++++++++++++ http/codegen/testdata/streaming_code.go | 35 +++++++ 20 files changed, 210 insertions(+), 38 deletions(-) diff --git a/codegen/service/service_data.go b/codegen/service/service_data.go index 8e68071499..195722f7bd 100644 --- a/codegen/service/service_data.go +++ b/codegen/service/service_data.go @@ -1250,7 +1250,7 @@ func initStreamData(data *MethodData, m *expr.MethodExpr, vname, rname, resultRe data.ServerStream = svrStream data.StreamingPayload = spayloadName data.StreamingPayloadDef = spayloadDef - data.StreamingPayloadRef = spayloadDef + data.StreamingPayloadRef = spayloadRef data.StreamingPayloadDesc = spayloadDesc data.StreamingPayloadEx = spayloadEx } diff --git a/codegen/service/templates/client_interceptor_wrappers.go.tpl b/codegen/service/templates/client_interceptor_wrappers.go.tpl index b8418282e8..8f7ef06bfd 100644 --- a/codegen/service/templates/client_interceptor_wrappers.go.tpl +++ b/codegen/service/templates/client_interceptor_wrappers.go.tpl @@ -82,11 +82,13 @@ type wrapped{{ .Interface }} struct { } {{- if ne .SendWithContextName "" }} +{{ comment (printf "%s streams instances of \"%s\" after executing the applied interceptor." .SendName .Interface) }} func (w *wrapped{{ .Interface }}) {{ .SendName }}(v {{ .SendTypeRef }}) error { _, err := w.SendWithContext(w.ctx, v) return err } +{{ comment (printf "%s streams instances of \"%s\" after executing the applied interceptor with context." .SendWithContextName .Interface) }} func (w *wrapped{{ .Interface }}) {{ .SendWithContextName }}(ctx context.Context, v {{ .SendTypeRef }}) (context.Context, error) { if w.sendWithContext == nil { return w.stream.{{ .SendWithContextName }}(ctx, v) @@ -96,11 +98,13 @@ func (w *wrapped{{ .Interface }}) {{ .SendWithContextName }}(ctx context.Context {{- end }} {{- if ne .RecvWithContextName "" }} +{{ comment (printf "%s reads instances of \"%s\" from the stream after executing the applied interceptor." .RecvName .Interface) }} func (w *wrapped{{ .Interface }}) {{ .RecvName }}() ({{ .RecvTypeRef }}, error) { res, _, err := w.RecvWithContext(w.ctx) return res, err } +{{ comment (printf "%s reads instances of \"%s\" from the stream after executing the applied interceptor with context." .RecvWithContextName .Interface) }} func (w *wrapped{{ .Interface }}) {{ .RecvWithContextName }}(ctx context.Context) ({{ .RecvTypeRef }}, context.Context, error) { if w.recvWithContext == nil { return w.stream.{{ .RecvWithContextName }}(ctx) @@ -110,6 +114,7 @@ func (w *wrapped{{ .Interface }}) {{ .RecvWithContextName }}(ctx context.Context {{- end }} {{- if .MustClose }} +// Close closes the stream. func (w *wrapped{{ .Interface }}) Close() error { return w.stream.Close() } diff --git a/codegen/service/templates/server_interceptor_wrappers.go.tpl b/codegen/service/templates/server_interceptor_wrappers.go.tpl index 68902f0bce..2e34f3b2e8 100644 --- a/codegen/service/templates/server_interceptor_wrappers.go.tpl +++ b/codegen/service/templates/server_interceptor_wrappers.go.tpl @@ -82,11 +82,13 @@ type wrapped{{ .Interface }} struct { } {{- if ne .SendWithContextName "" }} +{{ comment (printf "%s streams instances of \"%s\" after executing the applied interceptor." .SendName .Interface) }} func (w *wrapped{{ .Interface }}) {{ .SendName }}(v {{ .SendTypeRef }}) error { _, err := w.SendWithContext(w.ctx, v) return err } +{{ comment (printf "%s streams instances of \"%s\" after executing the applied interceptor with context." .SendWithContextName .Interface) }} func (w *wrapped{{ .Interface }}) {{ .SendWithContextName }}(ctx context.Context, v {{ .SendTypeRef }}) (context.Context, error) { if w.sendWithContext == nil { return w.stream.{{ .SendWithContextName }}(ctx, v) @@ -96,11 +98,13 @@ func (w *wrapped{{ .Interface }}) {{ .SendWithContextName }}(ctx context.Context {{- end }} {{- if ne .RecvWithContextName "" }} +{{ comment (printf "%s reads instances of \"%s\" from the stream after executing the applied interceptor." .RecvName .Interface) }} func (w *wrapped{{ .Interface }}) {{ .RecvName }}() ({{ .RecvTypeRef }}, error) { res, _, err := w.RecvWithContext(w.ctx) return res, err } +{{ comment (printf "%s reads instances of \"%s\" from the stream after executing the applied interceptor with context." .RecvWithContextName .Interface) }} func (w *wrapped{{ .Interface }}) {{ .RecvWithContextName }}(ctx context.Context) ({{ .RecvTypeRef }}, context.Context, error) { if w.recvWithContext == nil { return w.stream.{{ .RecvWithContextName }}(ctx) @@ -110,6 +114,7 @@ func (w *wrapped{{ .Interface }}) {{ .RecvWithContextName }}(ctx context.Context {{- end }} {{- if .MustClose }} +// Close closes the stream. func (w *wrapped{{ .Interface }}) Close() error { return w.stream.Close() } diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-payload_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-payload_interceptor_wrappers.go.golden index 1f4ac6ebd3..1f3ce8ae1e 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-payload_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-payload_interceptor_wrappers.go.golden @@ -6,7 +6,6 @@ func wrapMethodValidation(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpo info := &ValidationInfo{ Service: "InterceptorWithReadPayload", Method: "Method", - Endpoint: endpoint, RawPayload: req, } return i.Validation(ctx, info, endpoint) @@ -20,7 +19,6 @@ func wrapClientMethodValidation(endpoint goa.Endpoint, i ClientInterceptors) goa info := &ValidationInfo{ Service: "InterceptorWithReadPayload", Method: "Method", - Endpoint: endpoint, RawPayload: req, } return i.Validation(ctx, info, endpoint) diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-result_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-result_interceptor_wrappers.go.golden index 5f86fe8455..691697a6ee 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-result_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-result_interceptor_wrappers.go.golden @@ -6,7 +6,6 @@ func wrapMethodCaching(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint info := &CachingInfo{ Service: "InterceptorWithReadResult", Method: "Method", - Endpoint: endpoint, RawPayload: req, } return i.Caching(ctx, info, endpoint) @@ -19,7 +18,6 @@ func wrapClientMethodCaching(endpoint goa.Endpoint, i ClientInterceptors) goa.En info := &CachingInfo{ Service: "InterceptorWithReadResult", Method: "Method", - Endpoint: endpoint, RawPayload: req, } return i.Caching(ctx, info, endpoint) diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_interceptor_wrappers.go.golden index f628ed5e05..9c26266c7b 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_interceptor_wrappers.go.golden @@ -6,7 +6,6 @@ func wrapMethodValidation(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpo info := &ValidationInfo{ Service: "InterceptorWithReadWritePayload", Method: "Method", - Endpoint: endpoint, RawPayload: req, } return i.Validation(ctx, info, endpoint) @@ -20,7 +19,6 @@ func wrapClientMethodValidation(endpoint goa.Endpoint, i ClientInterceptors) goa info := &ValidationInfo{ Service: "InterceptorWithReadWritePayload", Method: "Method", - Endpoint: endpoint, RawPayload: req, } return i.Validation(ctx, info, endpoint) diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-write-result_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-write-result_interceptor_wrappers.go.golden index 1e5ab9536e..03a814570c 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-write-result_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-write-result_interceptor_wrappers.go.golden @@ -6,7 +6,6 @@ func wrapMethodCaching(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint info := &CachingInfo{ Service: "InterceptorWithReadWriteResult", Method: "Method", - Endpoint: endpoint, RawPayload: req, } return i.Caching(ctx, info, endpoint) @@ -19,7 +18,6 @@ func wrapClientMethodCaching(endpoint goa.Endpoint, i ClientInterceptors) goa.En info := &CachingInfo{ Service: "InterceptorWithReadWriteResult", Method: "Method", - Endpoint: endpoint, RawPayload: req, } return i.Caching(ctx, info, endpoint) diff --git a/codegen/service/testdata/interceptors/interceptor-with-write-payload_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/interceptor-with-write-payload_interceptor_wrappers.go.golden index 70657d6eef..8a89a016f5 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-write-payload_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-write-payload_interceptor_wrappers.go.golden @@ -6,7 +6,6 @@ func wrapMethodValidation(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpo info := &ValidationInfo{ Service: "InterceptorWithWritePayload", Method: "Method", - Endpoint: endpoint, RawPayload: req, } return i.Validation(ctx, info, endpoint) @@ -20,7 +19,6 @@ func wrapClientMethodValidation(endpoint goa.Endpoint, i ClientInterceptors) goa info := &ValidationInfo{ Service: "InterceptorWithWritePayload", Method: "Method", - Endpoint: endpoint, RawPayload: req, } return i.Validation(ctx, info, endpoint) diff --git a/codegen/service/testdata/interceptors/interceptor-with-write-result_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/interceptor-with-write-result_interceptor_wrappers.go.golden index bfcca2ab0c..565d208e84 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-write-result_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-write-result_interceptor_wrappers.go.golden @@ -6,7 +6,6 @@ func wrapMethodCaching(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint info := &CachingInfo{ Service: "InterceptorWithWriteResult", Method: "Method", - Endpoint: endpoint, RawPayload: req, } return i.Caching(ctx, info, endpoint) @@ -19,7 +18,6 @@ func wrapClientMethodCaching(endpoint goa.Endpoint, i ClientInterceptors) goa.En info := &CachingInfo{ Service: "InterceptorWithWriteResult", Method: "Method", - Endpoint: endpoint, RawPayload: req, } return i.Caching(ctx, info, endpoint) diff --git a/codegen/service/testdata/interceptors/multiple-interceptors_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/multiple-interceptors_interceptor_wrappers.go.golden index f23c4d7171..1f5f64208e 100644 --- a/codegen/service/testdata/interceptors/multiple-interceptors_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/multiple-interceptors_interceptor_wrappers.go.golden @@ -6,7 +6,6 @@ func wrapMethodTest(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { info := &TestInfo{ Service: "MultipleInterceptorsService", Method: "Method", - Endpoint: endpoint, RawPayload: req, } return i.Test(ctx, info, endpoint) @@ -19,7 +18,6 @@ func wrapMethodTest3(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { info := &Test3Info{ Service: "MultipleInterceptorsService", Method: "Method", - Endpoint: endpoint, RawPayload: req, } return i.Test3(ctx, info, endpoint) @@ -32,7 +30,6 @@ func wrapClientMethodTest2(endpoint goa.Endpoint, i ClientInterceptors) goa.Endp info := &Test2Info{ Service: "MultipleInterceptorsService", Method: "Method", - Endpoint: endpoint, RawPayload: req, } return i.Test2(ctx, info, endpoint) @@ -45,7 +42,6 @@ func wrapClientMethodTest4(endpoint goa.Endpoint, i ClientInterceptors) goa.Endp info := &Test4Info{ Service: "MultipleInterceptorsService", Method: "Method", - Endpoint: endpoint, RawPayload: req, } return i.Test4(ctx, info, endpoint) diff --git a/codegen/service/testdata/interceptors/single-api-server-interceptor_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/single-api-server-interceptor_interceptor_wrappers.go.golden index 7c9edb4592..98088d5ac2 100644 --- a/codegen/service/testdata/interceptors/single-api-server-interceptor_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/single-api-server-interceptor_interceptor_wrappers.go.golden @@ -6,7 +6,6 @@ func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint info := &LoggingInfo{ Service: "SingleAPIServerInterceptor", Method: "Method", - Endpoint: endpoint, RawPayload: req, } return i.Logging(ctx, info, endpoint) @@ -19,7 +18,6 @@ func wrapMethod2Logging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoin info := &LoggingInfo{ Service: "SingleAPIServerInterceptor", Method: "Method2", - Endpoint: endpoint, RawPayload: req, } return i.Logging(ctx, info, endpoint) diff --git a/codegen/service/testdata/interceptors/single-client-interceptor_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/single-client-interceptor_interceptor_wrappers.go.golden index b05666e31d..dda05a49b5 100644 --- a/codegen/service/testdata/interceptors/single-client-interceptor_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/single-client-interceptor_interceptor_wrappers.go.golden @@ -6,7 +6,6 @@ func wrapClientMethodTracing(endpoint goa.Endpoint, i ClientInterceptors) goa.En info := &TracingInfo{ Service: "SingleClientInterceptor", Method: "Method", - Endpoint: endpoint, RawPayload: req, } return i.Tracing(ctx, info, endpoint) diff --git a/codegen/service/testdata/interceptors/single-method-server-interceptor_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/single-method-server-interceptor_interceptor_wrappers.go.golden index 1a2f722b8a..94a6d97091 100644 --- a/codegen/service/testdata/interceptors/single-method-server-interceptor_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/single-method-server-interceptor_interceptor_wrappers.go.golden @@ -6,7 +6,6 @@ func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint info := &LoggingInfo{ Service: "SingleMethodServerInterceptor", Method: "Method", - Endpoint: endpoint, RawPayload: req, } return i.Logging(ctx, info, endpoint) diff --git a/codegen/service/testdata/interceptors/single-service-server-interceptor_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/single-service-server-interceptor_interceptor_wrappers.go.golden index 06731b4ed6..3e8a292f16 100644 --- a/codegen/service/testdata/interceptors/single-service-server-interceptor_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/single-service-server-interceptor_interceptor_wrappers.go.golden @@ -6,7 +6,6 @@ func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint info := &LoggingInfo{ Service: "SingleServerInterceptor", Method: "Method", - Endpoint: endpoint, RawPayload: req, } return i.Logging(ctx, info, endpoint) @@ -19,7 +18,6 @@ func wrapMethod2Logging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoin info := &LoggingInfo{ Service: "SingleServerInterceptor", Method: "Method2", - Endpoint: endpoint, RawPayload: req, } return i.Logging(ctx, info, endpoint) diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_interceptor_wrappers.go.golden index 4eaf97ae32..9064fc0803 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_interceptor_wrappers.go.golden @@ -6,7 +6,6 @@ func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint info := &LoggingInfo{ Service: "StreamingInterceptorsWithReadPayload", Method: "Method", - Endpoint: endpoint, RawPayload: req, } return i.Logging(ctx, info, endpoint) diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_interceptor_wrappers.go.golden index 61fffb56af..e55620d86d 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_interceptor_wrappers.go.golden @@ -6,7 +6,6 @@ func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint info := &LoggingInfo{ Service: "StreamingInterceptorsWithReadResult", Method: "Method", - Endpoint: endpoint, RawPayload: req, } return i.Logging(ctx, info, endpoint) diff --git a/codegen/service/testdata/interceptors/streaming-interceptors_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors_interceptor_wrappers.go.golden index 8475c33ba6..1bece78f85 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors_interceptor_wrappers.go.golden @@ -10,25 +10,84 @@ func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint stream := res.(MethodServerStream) return &wrappedMethodServerStream{ ctx: ctx, - sendEndpoint: func(ctx context.Context, req any) (any, error) { + sendWithContext: func(ctx context.Context, req *MethodResult) (context.Context, error) { info := &LoggingInfo{ Service: "StreamingInterceptors", Method: "Method.SendWithContext", - Endpoint: endpoint, RawPayload: req, } - return i.Logging(ctx, info, endpoint) + var rCtx context.Context + _, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, error) { + var err error + rCtx, err = stream.SendWithContext(ctx, req.(*MethodResult)) + return nil, err + }) + return rCtx, err }, - recvEndpoint: func(ctx context.Context) (any, error) { + recvWithContext: func(ctx context.Context) (*MethodStreamingPayload, context.Context, error) { info := &LoggingInfo{ Service: "StreamingInterceptors", Method: "Method.RecvWithContext", - Endpoint: endpoint, - RawPayload: nil, + RawPayload: req, } - return i.Logging(ctx, info, endpoint) + var rCtx context.Context + res, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, error) { + var ( + res *MethodStreamingPayload + err error + ) + res, rCtx, err = stream.RecvWithContext(ctx) + return res, err + }) + return res.(*MethodStreamingPayload), rCtx, err }, stream: stream, }, nil } } + +// wrappedMethodServerStream is a server interceptor wrapper for the +// MethodServerStream stream. +type wrappedMethodServerStream struct { + ctx context.Context + sendWithContext func(context.Context, *MethodResult) (context.Context, error) + recvWithContext func(context.Context) (*MethodStreamingPayload, context.Context, error) + stream MethodServerStream +} + +// Send streams instances of "MethodServerStream" after executing the applied +// interceptor. +func (w *wrappedMethodServerStream) Send(v *MethodResult) error { + _, err := w.SendWithContext(w.ctx, v) + return err +} + +// SendWithContext streams instances of "MethodServerStream" after executing +// the applied interceptor with context. +func (w *wrappedMethodServerStream) SendWithContext(ctx context.Context, v *MethodResult) (context.Context, error) { + if w.sendWithContext == nil { + return w.stream.SendWithContext(ctx, v) + } + return w.sendWithContext(ctx, v) +} + +// Recv reads instances of "MethodServerStream" from the stream after executing +// the applied interceptor. +func (w *wrappedMethodServerStream) Recv() (*MethodStreamingPayload, error) { + res, _, err := w.RecvWithContext(w.ctx) + return res, err +} + +// RecvWithContext reads instances of "MethodServerStream" from the stream +// after executing the applied interceptor with context. +func (w *wrappedMethodServerStream) RecvWithContext(ctx context.Context) (*MethodStreamingPayload, context.Context, error) { + if w.recvWithContext == nil { + return w.stream.RecvWithContext(ctx) + } + return w.recvWithContext(ctx) +} + +// Close closes the stream. +func (w *wrappedMethodServerStream) Close() error { + return w.stream.Close() +} diff --git a/codegen/service/testdata/interceptors/streaming-interceptors_service_interceptors.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors_service_interceptors.go.golden index 52d08d6100..9c0c04c43b 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors_service_interceptors.go.golden @@ -32,9 +32,7 @@ type ( // Private implementation types type ( loggingMethodStreamingPayload struct { - payload struct { - Chunk *string - } + payload *MethodStreamingPayload } loggingMethodStreamingResult struct { result *MethodResult @@ -51,9 +49,7 @@ func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoin // Public accessor methods for Info types // StreamingPayload returns a type-safe accessor for the method streaming payload. func (info *LoggingInfo) StreamingPayload() LoggingStreamingPayload { - return &loggingMethodStreamingPayload{payload: info.RawPayload.(struct { - Chunk *string - })} + return &loggingMethodStreamingPayload{payload: info.RawPayload.(*MethodStreamingPayload)} } // StreamingResult returns a type-safe accessor for the method streaming result. diff --git a/codegen/service/testdata/service_code.go b/codegen/service/testdata/service_code.go index f6a9b5bf9a..ce22cd38d1 100644 --- a/codegen/service/testdata/service_code.go +++ b/codegen/service/testdata/service_code.go @@ -1814,6 +1814,8 @@ var MethodNames = [1]string{"StreamingResultMethod"} type StreamingResultMethodServerStream interface { // Send streams instances of "AResult". Send(*AResult) error + // SendWithContext streams instances of "AResult" with context. + SendWithContext(context.Context, *AResult) (context.Context, error) // Close closes the stream. Close() error } @@ -1823,6 +1825,8 @@ type StreamingResultMethodServerStream interface { type StreamingResultMethodClientStream interface { // Recv reads instances of "AResult" from the stream. Recv() (*AResult, error) + // RecvWithContext reads instances of "AResult" from the stream with context. + RecvWithContext(context.Context) (*AResult, context.Context, error) } // APayload is the payload type of the StreamingResultService service @@ -1877,6 +1881,8 @@ var MethodNames = [1]string{"StreamingResultWithViewsMethod"} type StreamingResultWithViewsMethodServerStream interface { // Send streams instances of "MultipleViews". Send(*MultipleViews) error + // SendWithContext streams instances of "MultipleViews" with context. + SendWithContext(context.Context, *MultipleViews) (context.Context, error) // Close closes the stream. Close() error // SetView sets the view used to render the result before streaming. @@ -1888,6 +1894,9 @@ type StreamingResultWithViewsMethodServerStream interface { type StreamingResultWithViewsMethodClientStream interface { // Recv reads instances of "MultipleViews" from the stream. Recv() (*MultipleViews, error) + // RecvWithContext reads instances of "MultipleViews" from the stream with + // context. + RecvWithContext(context.Context) (*MultipleViews, context.Context, error) } // MultipleViews is the result type of the StreamingResultWithViewsService @@ -1993,6 +2002,8 @@ var MethodNames = [1]string{"StreamingResultWithExplicitViewMethod"} type StreamingResultWithExplicitViewMethodServerStream interface { // Send streams instances of "MultipleViews". Send(*MultipleViews) error + // SendWithContext streams instances of "MultipleViews" with context. + SendWithContext(context.Context, *MultipleViews) (context.Context, error) // Close closes the stream. Close() error } @@ -2002,6 +2013,9 @@ type StreamingResultWithExplicitViewMethodServerStream interface { type StreamingResultWithExplicitViewMethodClientStream interface { // Recv reads instances of "MultipleViews" from the stream. Recv() (*MultipleViews, error) + // RecvWithContext reads instances of "MultipleViews" from the stream with + // context. + RecvWithContext(context.Context) (*MultipleViews, context.Context, error) } // MultipleViews is the result type of the @@ -2107,6 +2121,8 @@ var MethodNames = [1]string{"StreamingResultNoPayloadMethod"} type StreamingResultNoPayloadMethodServerStream interface { // Send streams instances of "AResult". Send(*AResult) error + // SendWithContext streams instances of "AResult" with context. + SendWithContext(context.Context, *AResult) (context.Context, error) // Close closes the stream. Close() error } @@ -2116,6 +2132,8 @@ type StreamingResultNoPayloadMethodServerStream interface { type StreamingResultNoPayloadMethodClientStream interface { // Recv reads instances of "AResult" from the stream. Recv() (*AResult, error) + // RecvWithContext reads instances of "AResult" from the stream with context. + RecvWithContext(context.Context) (*AResult, context.Context, error) } // AResult is the result type of the StreamingResultNoPayloadService service @@ -2157,8 +2175,13 @@ var MethodNames = [1]string{"StreamingPayloadMethod"} type StreamingPayloadMethodServerStream interface { // SendAndClose streams instances of "AResult" and closes the stream. SendAndClose(*AResult) error + // SendAndCloseWithContext streams instances of "AResult" and closes the stream + // with context. + SendAndCloseWithContext(context.Context, *AResult) (context.Context, error) // Recv reads instances of "APayload" from the stream. Recv() (*APayload, error) + // RecvWithContext reads instances of "APayload" from the stream with context. + RecvWithContext(context.Context) (*APayload, context.Context, error) } // StreamingPayloadMethodClientStream is the interface a @@ -2166,9 +2189,14 @@ type StreamingPayloadMethodServerStream interface { type StreamingPayloadMethodClientStream interface { // Send streams instances of "APayload". Send(*APayload) error + // SendWithContext streams instances of "APayload" with context. + SendWithContext(context.Context, *APayload) (context.Context, error) // CloseAndRecv stops sending messages to the stream and reads instances of // "AResult" from the stream. CloseAndRecv() (*AResult, error) + // CloseAndRecvWithContext stops sending messages to the stream and reads + // instances of "AResult" from the stream with context. + CloseAndRecvWithContext(context.Context) (*AResult, context.Context, error) } // APayload is the streaming payload type of the StreamingPayloadService @@ -2240,8 +2268,13 @@ var MethodNames = [1]string{"StreamingPayloadNoPayloadMethod"} type StreamingPayloadNoPayloadMethodServerStream interface { // SendAndClose streams instances of "string" and closes the stream. SendAndClose(string) error + // SendAndCloseWithContext streams instances of "string" and closes the stream + // with context. + SendAndCloseWithContext(context.Context, string) (context.Context, error) // Recv reads instances of "any" from the stream. Recv() (any, error) + // RecvWithContext reads instances of "any" from the stream with context. + RecvWithContext(context.Context) (any, context.Context, error) } // StreamingPayloadNoPayloadMethodClientStream is the interface a @@ -2249,9 +2282,14 @@ type StreamingPayloadNoPayloadMethodServerStream interface { type StreamingPayloadNoPayloadMethodClientStream interface { // Send streams instances of "any". Send(any) error + // SendWithContext streams instances of "any" with context. + SendWithContext(context.Context, any) (context.Context, error) // CloseAndRecv stops sending messages to the stream and reads instances of // "string" from the stream. CloseAndRecv() (string, error) + // CloseAndRecvWithContext stops sending messages to the stream and reads + // instances of "string" from the stream with context. + CloseAndRecvWithContext(context.Context) (string, context.Context, error) } ` @@ -2283,6 +2321,8 @@ var MethodNames = [1]string{"StreamingPayloadNoResultMethod"} type StreamingPayloadNoResultMethodServerStream interface { // Recv reads instances of "int" from the stream. Recv() (int, error) + // RecvWithContext reads instances of "int" from the stream with context. + RecvWithContext(context.Context) (int, context.Context, error) // Close closes the stream. Close() error } @@ -2292,6 +2332,8 @@ type StreamingPayloadNoResultMethodServerStream interface { type StreamingPayloadNoResultMethodClientStream interface { // Send streams instances of "int". Send(int) error + // SendWithContext streams instances of "int" with context. + SendWithContext(context.Context, int) (context.Context, error) // Close closes the stream. Close() error } @@ -2329,8 +2371,13 @@ var MethodNames = [1]string{"StreamingPayloadResultWithViewsMethod"} type StreamingPayloadResultWithViewsMethodServerStream interface { // SendAndClose streams instances of "MultipleViews" and closes the stream. SendAndClose(*MultipleViews) error + // SendAndCloseWithContext streams instances of "MultipleViews" and closes the + // stream with context. + SendAndCloseWithContext(context.Context, *MultipleViews) (context.Context, error) // Recv reads instances of "APayload" from the stream. Recv() (*APayload, error) + // RecvWithContext reads instances of "APayload" from the stream with context. + RecvWithContext(context.Context) (*APayload, context.Context, error) // SetView sets the view used to render the result before streaming. SetView(view string) } @@ -2340,9 +2387,14 @@ type StreamingPayloadResultWithViewsMethodServerStream interface { type StreamingPayloadResultWithViewsMethodClientStream interface { // Send streams instances of "APayload". Send(*APayload) error + // SendWithContext streams instances of "APayload" with context. + SendWithContext(context.Context, *APayload) (context.Context, error) // CloseAndRecv stops sending messages to the stream and reads instances of // "MultipleViews" from the stream. CloseAndRecv() (*MultipleViews, error) + // CloseAndRecvWithContext stops sending messages to the stream and reads + // instances of "MultipleViews" from the stream with context. + CloseAndRecvWithContext(context.Context) (*MultipleViews, context.Context, error) } // APayload is the streaming payload type of the @@ -2462,8 +2514,13 @@ var MethodNames = [1]string{"StreamingPayloadResultWithExplicitViewMethod"} type StreamingPayloadResultWithExplicitViewMethodServerStream interface { // SendAndClose streams instances of "MultipleViews" and closes the stream. SendAndClose(*MultipleViews) error + // SendAndCloseWithContext streams instances of "MultipleViews" and closes the + // stream with context. + SendAndCloseWithContext(context.Context, *MultipleViews) (context.Context, error) // Recv reads instances of "[]string" from the stream. Recv() ([]string, error) + // RecvWithContext reads instances of "[]string" from the stream with context. + RecvWithContext(context.Context) ([]string, context.Context, error) } // StreamingPayloadResultWithExplicitViewMethodClientStream is the interface a @@ -2472,9 +2529,14 @@ type StreamingPayloadResultWithExplicitViewMethodServerStream interface { type StreamingPayloadResultWithExplicitViewMethodClientStream interface { // Send streams instances of "[]string". Send([]string) error + // SendWithContext streams instances of "[]string" with context. + SendWithContext(context.Context, []string) (context.Context, error) // CloseAndRecv stops sending messages to the stream and reads instances of // "MultipleViews" from the stream. CloseAndRecv() (*MultipleViews, error) + // CloseAndRecvWithContext stops sending messages to the stream and reads + // instances of "MultipleViews" from the stream with context. + CloseAndRecvWithContext(context.Context) (*MultipleViews, context.Context, error) } // MultipleViews is the result type of the @@ -2580,8 +2642,12 @@ var MethodNames = [1]string{"BidirectionalStreamingMethod"} type BidirectionalStreamingMethodServerStream interface { // Send streams instances of "AResult". Send(*AResult) error + // SendWithContext streams instances of "AResult" with context. + SendWithContext(context.Context, *AResult) (context.Context, error) // Recv reads instances of "APayload" from the stream. Recv() (*APayload, error) + // RecvWithContext reads instances of "APayload" from the stream with context. + RecvWithContext(context.Context) (*APayload, context.Context, error) // Close closes the stream. Close() error } @@ -2591,8 +2657,12 @@ type BidirectionalStreamingMethodServerStream interface { type BidirectionalStreamingMethodClientStream interface { // Send streams instances of "APayload". Send(*APayload) error + // SendWithContext streams instances of "APayload" with context. + SendWithContext(context.Context, *APayload) (context.Context, error) // Recv reads instances of "AResult" from the stream. Recv() (*AResult, error) + // RecvWithContext reads instances of "AResult" from the stream with context. + RecvWithContext(context.Context) (*AResult, context.Context, error) // Close closes the stream. Close() error } @@ -2667,8 +2737,12 @@ var MethodNames = [1]string{"BidirectionalStreamingNoPayloadMethod"} type BidirectionalStreamingNoPayloadMethodServerStream interface { // Send streams instances of "int". Send(int) error + // SendWithContext streams instances of "int" with context. + SendWithContext(context.Context, int) (context.Context, error) // Recv reads instances of "string" from the stream. Recv() (string, error) + // RecvWithContext reads instances of "string" from the stream with context. + RecvWithContext(context.Context) (string, context.Context, error) // Close closes the stream. Close() error } @@ -2678,8 +2752,12 @@ type BidirectionalStreamingNoPayloadMethodServerStream interface { type BidirectionalStreamingNoPayloadMethodClientStream interface { // Send streams instances of "string". Send(string) error + // SendWithContext streams instances of "string" with context. + SendWithContext(context.Context, string) (context.Context, error) // Recv reads instances of "int" from the stream. Recv() (int, error) + // RecvWithContext reads instances of "int" from the stream with context. + RecvWithContext(context.Context) (int, context.Context, error) // Close closes the stream. Close() error } @@ -2719,8 +2797,12 @@ var MethodNames = [1]string{"BidirectionalStreamingResultWithViewsMethod"} type BidirectionalStreamingResultWithViewsMethodServerStream interface { // Send streams instances of "MultipleViews". Send(*MultipleViews) error + // SendWithContext streams instances of "MultipleViews" with context. + SendWithContext(context.Context, *MultipleViews) (context.Context, error) // Recv reads instances of "APayload" from the stream. Recv() (*APayload, error) + // RecvWithContext reads instances of "APayload" from the stream with context. + RecvWithContext(context.Context) (*APayload, context.Context, error) // Close closes the stream. Close() error // SetView sets the view used to render the result before streaming. @@ -2733,8 +2815,13 @@ type BidirectionalStreamingResultWithViewsMethodServerStream interface { type BidirectionalStreamingResultWithViewsMethodClientStream interface { // Send streams instances of "APayload". Send(*APayload) error + // SendWithContext streams instances of "APayload" with context. + SendWithContext(context.Context, *APayload) (context.Context, error) // Recv reads instances of "MultipleViews" from the stream. Recv() (*MultipleViews, error) + // RecvWithContext reads instances of "MultipleViews" from the stream with + // context. + RecvWithContext(context.Context) (*MultipleViews, context.Context, error) // Close closes the stream. Close() error } @@ -2856,8 +2943,12 @@ var MethodNames = [1]string{"BidirectionalStreamingResultWithExplicitViewMethod" type BidirectionalStreamingResultWithExplicitViewMethodServerStream interface { // Send streams instances of "MultipleViews". Send(*MultipleViews) error + // SendWithContext streams instances of "MultipleViews" with context. + SendWithContext(context.Context, *MultipleViews) (context.Context, error) // Recv reads instances of "[][]byte" from the stream. Recv() ([][]byte, error) + // RecvWithContext reads instances of "[][]byte" from the stream with context. + RecvWithContext(context.Context) ([][]byte, context.Context, error) // Close closes the stream. Close() error } @@ -2868,8 +2959,13 @@ type BidirectionalStreamingResultWithExplicitViewMethodServerStream interface { type BidirectionalStreamingResultWithExplicitViewMethodClientStream interface { // Send streams instances of "[][]byte". Send([][]byte) error + // SendWithContext streams instances of "[][]byte" with context. + SendWithContext(context.Context, [][]byte) (context.Context, error) // Recv reads instances of "MultipleViews" from the stream. Recv() (*MultipleViews, error) + // RecvWithContext reads instances of "MultipleViews" from the stream with + // context. + RecvWithContext(context.Context) (*MultipleViews, context.Context, error) // Close closes the stream. Close() error } diff --git a/http/codegen/testdata/streaming_code.go b/http/codegen/testdata/streaming_code.go index e31536f882..ec15701833 100644 --- a/http/codegen/testdata/streaming_code.go +++ b/http/codegen/testdata/streaming_code.go @@ -3249,6 +3249,15 @@ func (s *BidirectionalStreamingUserTypeMapMethodServerStream) Send(v map[string] body := NewBidirectionalStreamingUserTypeMapMethodResponseBody(res) return s.conn.WriteJSON(body) } + +// RecvWithContext reads instances of +// "map[string]*bidirectionalstreamingusertypemapservice.RequestType" from the +// "BidirectionalStreamingUserTypeMapMethod" endpoint websocket connection with +// context. +func (s *BidirectionalStreamingUserTypeMapMethodServerStream) RecvWithContext(ctx context.Context) (map[string]*bidirectionalstreamingusertypemapservice.RequestType, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var BidirectionalStreamingUserTypeMapServerStreamRecvCode = `// Recv reads instances of @@ -3285,6 +3294,15 @@ func (s *BidirectionalStreamingUserTypeMapMethodServerStream) Recv() (map[string } return NewBidirectionalStreamingUserTypeMapMethodMap(body), nil } + +// RecvWithContext reads instances of +// "map[string]*bidirectionalstreamingusertypemapservice.RequestType" from the +// "BidirectionalStreamingUserTypeMapMethod" endpoint websocket connection with +// context. +func (s *BidirectionalStreamingUserTypeMapMethodServerStream) RecvWithContext(ctx context.Context) (map[string]*bidirectionalstreamingusertypemapservice.RequestType, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var BidirectionalStreamingUserTypeMapClientStreamSendCode = `// Send streams instances of @@ -3294,6 +3312,14 @@ func (s *BidirectionalStreamingUserTypeMapMethodClientStream) Send(v map[string] body := NewMapStringRequestType(v) return s.conn.WriteJSON(body) } + +// SendWithContext streams instances of +// "map[string]*bidirectionalstreamingusertypemapservice.RequestType" to the +// "BidirectionalStreamingUserTypeMapMethod" endpoint websocket connection with +// context. +func (s *BidirectionalStreamingUserTypeMapMethodClientStream) SendWithContext(ctx context.Context, v map[string]*bidirectionalstreamingusertypemapservice.RequestType) (context.Context, error) { + return ctx, s.Send(v) +} ` var BidirectionalStreamingUserTypeMapClientStreamRecvCode = `// Recv reads instances of @@ -3315,4 +3341,13 @@ func (s *BidirectionalStreamingUserTypeMapMethodClientStream) Recv() (map[string res := NewBidirectionalStreamingUserTypeMapMethodMapStringResultTypeOK(body) return res, nil } + +// RecvWithContext reads instances of +// "map[string]*bidirectionalstreamingusertypemapservice.ResultType" from the +// "BidirectionalStreamingUserTypeMapMethod" endpoint websocket connection with +// context. +func (s *BidirectionalStreamingUserTypeMapMethodClientStream) RecvWithContext(ctx context.Context) (map[string]*bidirectionalstreamingusertypemapservice.ResultType, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` From 0261a0c426b7e2da21dd5e976ad4b79596253852 Mon Sep 17 00:00:00 2001 From: Douglas Thrift Date: Fri, 31 Jan 2025 16:31:26 -0800 Subject: [PATCH 11/23] Finish fixing tests --- grpc/codegen/testdata/streaming_code.go | 170 +++++ http/codegen/testdata/streaming_code.go | 805 +++++++++++++++++++++++- http/codegen/websocket.go | 2 +- 3 files changed, 970 insertions(+), 7 deletions(-) diff --git a/grpc/codegen/testdata/streaming_code.go b/grpc/codegen/testdata/streaming_code.go index ae871c393d..3ce5baef9b 100644 --- a/grpc/codegen/testdata/streaming_code.go +++ b/grpc/codegen/testdata/streaming_code.go @@ -15,6 +15,13 @@ func (s *MethodServerStreamingUserTypeRPCServerStream) Send(res *serviceserverst v := NewProtoUserTypeMethodServerStreamingUserTypeRPCResponse(res) return s.stream.Send(v) } + +// SendWithContext streams instances of +// "service_server_streaming_user_type_rpcpb.MethodServerStreamingUserTypeRPCResponse" +// to the "MethodServerStreamingUserTypeRPC" endpoint gRPC stream with context. +func (s *MethodServerStreamingUserTypeRPCServerStream) SendWithContext(ctx context.Context, res *serviceserverstreamingusertyperpc.UserType) (context.Context, error) { + return ctx, s.Send(res) +} ` var ServerStreamingServerCloseCode = `func (s *MethodServerStreamingUserTypeRPCServerStream) Close() error { @@ -42,6 +49,15 @@ func (s *MethodServerStreamingUserTypeRPCClientStream) Recv() (*serviceserverstr } return NewMethodServerStreamingUserTypeRPCResponseUserType(v), nil } + +// RecvWithContext reads instances of +// "service_server_streaming_user_type_rpcpb.MethodServerStreamingUserTypeRPCResponse" +// from the "MethodServerStreamingUserTypeRPC" endpoint gRPC stream with +// context. +func (s *MethodServerStreamingUserTypeRPCClientStream) RecvWithContext(ctx context.Context) (*serviceserverstreamingusertyperpc.UserType, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var ServerStreamingResultWithViewsServerStructCode = `// MethodServerStreamingUserTypeRPCServerStream implements the @@ -61,6 +77,13 @@ func (s *MethodServerStreamingUserTypeRPCServerStream) Send(res *serviceserverst v := NewProtoResultTypeViewMethodServerStreamingUserTypeRPCResponse(vres.Projected) return s.stream.Send(v) } + +// SendWithContext streams instances of +// "service_server_streaming_user_type_rpcpb.MethodServerStreamingUserTypeRPCResponse" +// to the "MethodServerStreamingUserTypeRPC" endpoint gRPC stream with context. +func (s *MethodServerStreamingUserTypeRPCServerStream) SendWithContext(ctx context.Context, res *serviceserverstreamingusertyperpc.ResultType) (context.Context, error) { + return ctx, s.Send(res) +} ` var ServerStreamingResultWithViewsServerSetViewCode = `// SetView sets the view. @@ -94,6 +117,15 @@ func (s *MethodServerStreamingUserTypeRPCClientStream) Recv() (*serviceserverstr } return serviceserverstreamingusertyperpc.NewResultType(vres), nil } + +// RecvWithContext reads instances of +// "service_server_streaming_user_type_rpcpb.MethodServerStreamingUserTypeRPCResponse" +// from the "MethodServerStreamingUserTypeRPC" endpoint gRPC stream with +// context. +func (s *MethodServerStreamingUserTypeRPCClientStream) RecvWithContext(ctx context.Context) (*serviceserverstreamingusertyperpc.ResultType, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var ServerStreamingResultWithViewsClientSetViewCode = `// SetView sets the view. @@ -111,6 +143,14 @@ func (s *MethodServerStreamingResultTypeCollectionWithExplicitViewServerStream) v := NewProtoResultTypeCollectionViewResultTypeCollection(vres.Projected) return s.stream.Send(v) } + +// SendWithContext streams instances of +// "service_server_streaming_result_type_collection_with_explicit_viewpb.ResultTypeCollection" +// to the "MethodServerStreamingResultTypeCollectionWithExplicitView" endpoint +// gRPC stream with context. +func (s *MethodServerStreamingResultTypeCollectionWithExplicitViewServerStream) SendWithContext(ctx context.Context, res serviceserverstreamingresulttypecollectionwithexplicitview.ResultTypeCollection) (context.Context, error) { + return ctx, s.Send(res) +} ` var ServerStreamingResultCollectionWithExplicitViewClientRecvCode = `// Recv reads instances of @@ -130,6 +170,15 @@ func (s *MethodServerStreamingResultTypeCollectionWithExplicitViewClientStream) } return serviceserverstreamingresulttypecollectionwithexplicitview.NewResultTypeCollection(vres), nil } + +// RecvWithContext reads instances of +// "service_server_streaming_result_type_collection_with_explicit_viewpb.ResultTypeCollection" +// from the "MethodServerStreamingResultTypeCollectionWithExplicitView" +// endpoint gRPC stream with context. +func (s *MethodServerStreamingResultTypeCollectionWithExplicitViewClientStream) RecvWithContext(ctx context.Context) (serviceserverstreamingresulttypecollectionwithexplicitview.ResultTypeCollection, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var ServerStreamingPrimitiveServerSendCode = `// Send streams instances of @@ -139,6 +188,13 @@ func (s *MethodServerStreamingRPCServerStream) Send(res string) error { v := NewProtoMethodServerStreamingRPCResponse(res) return s.stream.Send(v) } + +// SendWithContext streams instances of +// "service_server_streaming_rpcpb.MethodServerStreamingRPCResponse" to the +// "MethodServerStreamingRPC" endpoint gRPC stream with context. +func (s *MethodServerStreamingRPCServerStream) SendWithContext(ctx context.Context, res string) (context.Context, error) { + return ctx, s.Send(res) +} ` var ServerStreamingPrimitiveClientRecvCode = `// Recv reads instances of @@ -152,6 +208,14 @@ func (s *MethodServerStreamingRPCClientStream) Recv() (string, error) { } return NewMethodServerStreamingRPCResponseMethodServerStreamingRPCResponse(v), nil } + +// RecvWithContext reads instances of +// "service_server_streaming_rpcpb.MethodServerStreamingRPCResponse" from the +// "MethodServerStreamingRPC" endpoint gRPC stream with context. +func (s *MethodServerStreamingRPCClientStream) RecvWithContext(ctx context.Context) (string, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var ServerStreamingArrayServerSendCode = `// Send streams instances of @@ -161,6 +225,13 @@ func (s *MethodServerStreamingArrayServerStream) Send(res []int) error { v := NewProtoMethodServerStreamingArrayResponse(res) return s.stream.Send(v) } + +// SendWithContext streams instances of +// "service_server_streaming_arraypb.MethodServerStreamingArrayResponse" to the +// "MethodServerStreamingArray" endpoint gRPC stream with context. +func (s *MethodServerStreamingArrayServerStream) SendWithContext(ctx context.Context, res []int) (context.Context, error) { + return ctx, s.Send(res) +} ` var ServerStreamingArrayClientRecvCode = `// Recv reads instances of @@ -174,6 +245,14 @@ func (s *MethodServerStreamingArrayClientStream) Recv() ([]int, error) { } return NewMethodServerStreamingArrayResponseMethodServerStreamingArrayResponse(v), nil } + +// RecvWithContext reads instances of +// "service_server_streaming_arraypb.MethodServerStreamingArrayResponse" from +// the "MethodServerStreamingArray" endpoint gRPC stream with context. +func (s *MethodServerStreamingArrayClientStream) RecvWithContext(ctx context.Context) ([]int, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var ServerStreamingMapServerSendCode = `// Send streams instances of @@ -183,6 +262,13 @@ func (s *MethodServerStreamingMapServerStream) Send(res map[string]*serviceserve v := NewProtoMethodServerStreamingMapResponse(res) return s.stream.Send(v) } + +// SendWithContext streams instances of +// "service_server_streaming_mappb.MethodServerStreamingMapResponse" to the +// "MethodServerStreamingMap" endpoint gRPC stream with context. +func (s *MethodServerStreamingMapServerStream) SendWithContext(ctx context.Context, res map[string]*serviceserverstreamingmap.UserType) (context.Context, error) { + return ctx, s.Send(res) +} ` var ServerStreamingMapClientRecvCode = `// Recv reads instances of @@ -196,6 +282,14 @@ func (s *MethodServerStreamingMapClientStream) Recv() (map[string]*serviceserver } return NewMethodServerStreamingMapResponseMethodServerStreamingMapResponse(v), nil } + +// RecvWithContext reads instances of +// "service_server_streaming_mappb.MethodServerStreamingMapResponse" from the +// "MethodServerStreamingMap" endpoint gRPC stream with context. +func (s *MethodServerStreamingMapClientStream) RecvWithContext(ctx context.Context) (map[string]*serviceserverstreamingmap.UserType, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var ServerStreamingServerRPCSharedResultRecvCode = `// Recv reads instances of @@ -210,6 +304,14 @@ func (s *MethodServerStreamingRPCClientStream) Recv() (*serviceserverstreamingrp return NewMethodServerStreamingRPCResponseUserType(v), nil } +// RecvWithContext reads instances of +// "service_server_streaming_rpcpb.MethodServerStreamingRPCResponse" from the +// "MethodServerStreamingRPC" endpoint gRPC stream with context. +func (s *MethodServerStreamingRPCClientStream) RecvWithContext(ctx context.Context) (*serviceserverstreamingrpc.UserType, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} + // Recv reads instances of // "service_server_streaming_rpcpb.OtherMethodServerStreamingRPCResponse" from // the "OtherMethodServerStreamingRPC" endpoint gRPC stream. @@ -221,6 +323,14 @@ func (s *OtherMethodServerStreamingRPCClientStream) Recv() (*serviceserverstream } return NewOtherMethodServerStreamingRPCResponseUserType(v), nil } + +// RecvWithContext reads instances of +// "service_server_streaming_rpcpb.OtherMethodServerStreamingRPCResponse" from +// the "OtherMethodServerStreamingRPC" endpoint gRPC stream with context. +func (s *OtherMethodServerStreamingRPCClientStream) RecvWithContext(ctx context.Context) (*serviceserverstreamingrpc.UserType, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var ClientStreamingServerStructCode = `// MethodClientStreamingRPCServerStream implements the @@ -237,6 +347,13 @@ func (s *MethodClientStreamingRPCServerStream) SendAndClose(res string) error { v := NewProtoMethodClientStreamingRPCResponse(res) return s.stream.SendAndClose(v) } + +// SendAndCloseWithContext streams instances of +// "service_client_streaming_rpcpb.MethodClientStreamingRPCResponse" to the +// "MethodClientStreamingRPC" endpoint gRPC stream with context. +func (s *MethodClientStreamingRPCServerStream) SendAndCloseWithContext(ctx context.Context, res string) (context.Context, error) { + return ctx, s.SendAndClose(res) +} ` var ClientStreamingServerRecvCode = `// Recv reads instances of @@ -250,6 +367,14 @@ func (s *MethodClientStreamingRPCServerStream) Recv() (int, error) { } return NewMethodClientStreamingRPCStreamingRequestMethodClientStreamingRPCStreamingRequest(v), nil } + +// RecvWithContext reads instances of +// "service_client_streaming_rpcpb.MethodClientStreamingRPCStreamingRequest" +// from the "MethodClientStreamingRPC" endpoint gRPC stream with context. +func (s *MethodClientStreamingRPCServerStream) RecvWithContext(ctx context.Context) (int, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var ClientStreamingClientStructCode = `// MethodClientStreamingRPCClientStream implements the @@ -266,6 +391,13 @@ func (s *MethodClientStreamingRPCClientStream) Send(res int) error { v := NewProtoMethodClientStreamingRPCStreamingRequest(res) return s.stream.Send(v) } + +// SendWithContext streams instances of +// "service_client_streaming_rpcpb.MethodClientStreamingRPCStreamingRequest" to +// the "MethodClientStreamingRPC" endpoint gRPC stream with context. +func (s *MethodClientStreamingRPCClientStream) SendWithContext(ctx context.Context, res int) (context.Context, error) { + return ctx, s.Send(res) +} ` var ClientStreamingClientRecvCode = `// CloseAndRecv reads instances of @@ -279,6 +411,14 @@ func (s *MethodClientStreamingRPCClientStream) CloseAndRecv() (string, error) { } return NewMethodClientStreamingRPCResponseMethodClientStreamingRPCResponse(v), nil } + +// CloseAndRecvWithContext reads instances of +// "service_client_streaming_rpcpb.MethodClientStreamingRPCResponse" from the +// "MethodClientStreamingRPC" endpoint gRPC stream with context. +func (s *MethodClientStreamingRPCClientStream) CloseAndRecvWithContext(ctx context.Context) (string, context.Context, error) { + res, err := s.CloseAndRecv() + return res, ctx, err +} ` var ClientStreamingServerNoResultCloseCode = `func (s *MethodClientStreamingNoResultServerStream) Close() error { @@ -311,6 +451,13 @@ func (s *MethodBidirectionalStreamingRPCServerStream) Send(res *servicebidirecti v := NewProtoIDViewMethodBidirectionalStreamingRPCResponse(vres.Projected) return s.stream.Send(v) } + +// SendWithContext streams instances of +// "service_bidirectional_streaming_rpcpb.MethodBidirectionalStreamingRPCResponse" +// to the "MethodBidirectionalStreamingRPC" endpoint gRPC stream with context. +func (s *MethodBidirectionalStreamingRPCServerStream) SendWithContext(ctx context.Context, res *servicebidirectionalstreamingrpc.ID) (context.Context, error) { + return ctx, s.Send(res) +} ` var BidirectionalStreamingServerRecvCode = `// Recv reads instances of @@ -324,6 +471,14 @@ func (s *MethodBidirectionalStreamingRPCServerStream) Recv() (int, error) { } return NewMethodBidirectionalStreamingRPCStreamingRequestMethodBidirectionalStreamingRPCStreamingRequest(v), nil } + +// RecvWithContext reads instances of +// "service_bidirectional_streaming_rpcpb.MethodBidirectionalStreamingRPCStreamingRequest" +// from the "MethodBidirectionalStreamingRPC" endpoint gRPC stream with context. +func (s *MethodBidirectionalStreamingRPCServerStream) RecvWithContext(ctx context.Context) (int, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var BidirectionalStreamingServerCloseCode = `func (s *MethodBidirectionalStreamingRPCServerStream) Close() error { @@ -348,6 +503,13 @@ func (s *MethodBidirectionalStreamingRPCClientStream) Send(res int) error { v := NewProtoMethodBidirectionalStreamingRPCStreamingRequest(res) return s.stream.Send(v) } + +// SendWithContext streams instances of +// "service_bidirectional_streaming_rpcpb.MethodBidirectionalStreamingRPCStreamingRequest" +// to the "MethodBidirectionalStreamingRPC" endpoint gRPC stream with context. +func (s *MethodBidirectionalStreamingRPCClientStream) SendWithContext(ctx context.Context, res int) (context.Context, error) { + return ctx, s.Send(res) +} ` var BidirectionalStreamingClientRecvCode = `// Recv reads instances of @@ -366,6 +528,14 @@ func (s *MethodBidirectionalStreamingRPCClientStream) Recv() (*servicebidirectio } return servicebidirectionalstreamingrpc.NewID(vres), nil } + +// RecvWithContext reads instances of +// "service_bidirectional_streaming_rpcpb.MethodBidirectionalStreamingRPCResponse" +// from the "MethodBidirectionalStreamingRPC" endpoint gRPC stream with context. +func (s *MethodBidirectionalStreamingRPCClientStream) RecvWithContext(ctx context.Context) (*servicebidirectionalstreamingrpc.ID, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var BidirectionalStreamingClientCloseCode = `func (s *MethodBidirectionalStreamingRPCClientStream) Close() error { diff --git a/http/codegen/testdata/streaming_code.go b/http/codegen/testdata/streaming_code.go index ec15701833..fe0431bc2a 100644 --- a/http/codegen/testdata/streaming_code.go +++ b/http/codegen/testdata/streaming_code.go @@ -97,6 +97,12 @@ func (s *StreamingResultMethodServerStream) Send(v *streamingresultservice.UserT body := NewStreamingResultMethodResponseBody(res) return s.conn.WriteJSON(body) } + +// SendWithContext streams instances of "streamingresultservice.UserType" to +// the "StreamingResultMethod" endpoint websocket connection with context. +func (s *StreamingResultMethodServerStream) SendWithContext(ctx context.Context, v *streamingresultservice.UserType) (context.Context, error) { + return ctx, s.Send(v) +} ` var StreamingResultServerStreamCloseCode = `// Close closes the "StreamingResultMethod" endpoint websocket connection. @@ -151,6 +157,13 @@ func (s *StreamingResultWithViewsMethodServerStream) Send(v *streamingresultwith } return s.conn.WriteJSON(body) } + +// SendWithContext streams instances of +// "streamingresultwithviewsservice.Usertype" to the +// "StreamingResultWithViewsMethod" endpoint websocket connection with context. +func (s *StreamingResultWithViewsMethodServerStream) SendWithContext(ctx context.Context, v *streamingresultwithviewsservice.Usertype) (context.Context, error) { + return ctx, s.Send(v) +} ` var StreamingResultWithViewsServerStreamSetViewCode = `// SetView sets the view to render the streamingresultwithviewsservice.Usertype @@ -284,6 +297,13 @@ func (s *StreamingResultMethodClientStream) Recv() (*streamingresultservice.User res := NewStreamingResultMethodUserTypeOK(&body) return res, nil } + +// RecvWithContext reads instances of "streamingresultservice.UserType" from +// the "StreamingResultMethod" endpoint websocket connection with context. +func (s *StreamingResultMethodClientStream) RecvWithContext(ctx context.Context) (*streamingresultservice.UserType, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var StreamingResultWithViewsClientEndpointCode = `// StreamingResultWithViewsMethod returns an endpoint that makes HTTP requests @@ -350,6 +370,14 @@ func (s *StreamingResultWithViewsMethodClientStream) Recv() (*streamingresultwit } return streamingresultwithviewsservice.NewUsertype(vres), nil } + +// RecvWithContext reads instances of +// "streamingresultwithviewsservice.Usertype" from the +// "StreamingResultWithViewsMethod" endpoint websocket connection with context. +func (s *StreamingResultWithViewsMethodClientStream) RecvWithContext(ctx context.Context) (*streamingresultwithviewsservice.Usertype, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var StreamingResultWithViewsClientStreamSetViewCode = `// SetView sets the view to render the type before sending to the @@ -422,6 +450,15 @@ func (s *StreamingResultWithExplicitViewMethodClientStream) Recv() (*streamingre } return streamingresultwithexplicitviewservice.NewUsertype(vres), nil } + +// RecvWithContext reads instances of +// "streamingresultwithexplicitviewservice.Usertype" from the +// "StreamingResultWithExplicitViewMethod" endpoint websocket connection with +// context. +func (s *StreamingResultWithExplicitViewMethodClientStream) RecvWithContext(ctx context.Context) (*streamingresultwithexplicitviewservice.Usertype, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var StreamingResultWithExplicitViewServerStreamSendCode = `// Send streams instances of "streamingresultwithexplicitviewservice.Usertype" @@ -449,6 +486,14 @@ func (s *StreamingResultWithExplicitViewMethodServerStream) Send(v *streamingres body := NewStreamingResultWithExplicitViewMethodResponseBodyExtended(res.Projected) return s.conn.WriteJSON(body) } + +// SendWithContext streams instances of +// "streamingresultwithexplicitviewservice.Usertype" to the +// "StreamingResultWithExplicitViewMethod" endpoint websocket connection with +// context. +func (s *StreamingResultWithExplicitViewMethodServerStream) SendWithContext(ctx context.Context, v *streamingresultwithexplicitviewservice.Usertype) (context.Context, error) { + return ctx, s.Send(v) +} ` var StreamingResultCollectionWithViewsServerStreamSendCode = `// Send streams instances of @@ -487,6 +532,14 @@ func (s *StreamingResultCollectionWithViewsMethodServerStream) Send(v streamingr } return s.conn.WriteJSON(body) } + +// SendWithContext streams instances of +// "streamingresultcollectionwithviewsservice.UsertypeCollection" to the +// "StreamingResultCollectionWithViewsMethod" endpoint websocket connection +// with context. +func (s *StreamingResultCollectionWithViewsMethodServerStream) SendWithContext(ctx context.Context, v streamingresultcollectionwithviewsservice.UsertypeCollection) (context.Context, error) { + return ctx, s.Send(v) +} ` var StreamingResultCollectionWithViewsServerStreamSetViewCode = `// SetView sets the view to render the @@ -522,6 +575,15 @@ func (s *StreamingResultCollectionWithViewsMethodClientStream) Recv() (streaming } return streamingresultcollectionwithviewsservice.NewUsertypeCollection(vres), nil } + +// RecvWithContext reads instances of +// "streamingresultcollectionwithviewsservice.UsertypeCollection" from the +// "StreamingResultCollectionWithViewsMethod" endpoint websocket connection +// with context. +func (s *StreamingResultCollectionWithViewsMethodClientStream) RecvWithContext(ctx context.Context) (streamingresultcollectionwithviewsservice.UsertypeCollection, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var StreamingResultCollectionWithViewsClientStreamSetViewCode = `// SetView sets the view to render the type before sending to the @@ -558,8 +620,15 @@ func (s *StreamingResultCollectionWithExplicitViewMethodServerStream) Send(v str body := NewUsertypeResponseTinyCollection(res.Projected) return s.conn.WriteJSON(body) } -` +// SendWithContext streams instances of +// "streamingresultcollectionwithexplicitviewservice.UsertypeCollection" to the +// "StreamingResultCollectionWithExplicitViewMethod" endpoint websocket +// connection with context. +func (s *StreamingResultCollectionWithExplicitViewMethodServerStream) SendWithContext(ctx context.Context, v streamingresultcollectionwithexplicitviewservice.UsertypeCollection) (context.Context, error) { + return ctx, s.Send(v) +} +` var StreamingResultCollectionWithExplicitViewClientEndpointCode = `// StreamingResultCollectionWithExplicitViewMethod returns an endpoint that // makes HTTP requests to the StreamingResultCollectionWithExplicitViewService // service StreamingResultCollectionWithExplicitViewMethod server. @@ -624,6 +693,15 @@ func (s *StreamingResultCollectionWithExplicitViewMethodClientStream) Recv() (st } return streamingresultcollectionwithexplicitviewservice.NewUsertypeCollection(vres), nil } + +// RecvWithContext reads instances of +// "streamingresultcollectionwithexplicitviewservice.UsertypeCollection" from +// the "StreamingResultCollectionWithExplicitViewMethod" endpoint websocket +// connection with context. +func (s *StreamingResultCollectionWithExplicitViewMethodClientStream) RecvWithContext(ctx context.Context) (streamingresultcollectionwithexplicitviewservice.UsertypeCollection, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var StreamingResultPrimitiveServerStreamSendCode = `// Send streams instances of "string" to the "StreamingResultPrimitiveMethod" @@ -650,6 +728,12 @@ func (s *StreamingResultPrimitiveMethodServerStream) Send(v string) error { res := v return s.conn.WriteJSON(res) } + +// SendWithContext streams instances of "string" to the +// "StreamingResultPrimitiveMethod" endpoint websocket connection with context. +func (s *StreamingResultPrimitiveMethodServerStream) SendWithContext(ctx context.Context, v string) (context.Context, error) { + return ctx, s.Send(v) +} ` var StreamingResultPrimitiveClientStreamRecvCode = `// Recv reads instances of "string" from the "StreamingResultPrimitiveMethod" @@ -670,6 +754,13 @@ func (s *StreamingResultPrimitiveMethodClientStream) Recv() (string, error) { } return body, nil } + +// RecvWithContext reads instances of "string" from the +// "StreamingResultPrimitiveMethod" endpoint websocket connection with context. +func (s *StreamingResultPrimitiveMethodClientStream) RecvWithContext(ctx context.Context) (string, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var StreamingResultPrimitiveArrayServerStreamSendCode = `// Send streams instances of "[]int32" to the @@ -696,6 +787,13 @@ func (s *StreamingResultPrimitiveArrayMethodServerStream) Send(v []int32) error res := v return s.conn.WriteJSON(res) } + +// SendWithContext streams instances of "[]int32" to the +// "StreamingResultPrimitiveArrayMethod" endpoint websocket connection with +// context. +func (s *StreamingResultPrimitiveArrayMethodServerStream) SendWithContext(ctx context.Context, v []int32) (context.Context, error) { + return ctx, s.Send(v) +} ` var StreamingResultPrimitiveArrayClientStreamRecvCode = `// Recv reads instances of "[]int32" from the @@ -716,6 +814,14 @@ func (s *StreamingResultPrimitiveArrayMethodClientStream) Recv() ([]int32, error } return body, nil } + +// RecvWithContext reads instances of "[]int32" from the +// "StreamingResultPrimitiveArrayMethod" endpoint websocket connection with +// context. +func (s *StreamingResultPrimitiveArrayMethodClientStream) RecvWithContext(ctx context.Context) ([]int32, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var StreamingResultPrimitiveMapServerStreamSendCode = `// Send streams instances of "map[int32]string" to the @@ -742,6 +848,13 @@ func (s *StreamingResultPrimitiveMapMethodServerStream) Send(v map[int32]string) res := v return s.conn.WriteJSON(res) } + +// SendWithContext streams instances of "map[int32]string" to the +// "StreamingResultPrimitiveMapMethod" endpoint websocket connection with +// context. +func (s *StreamingResultPrimitiveMapMethodServerStream) SendWithContext(ctx context.Context, v map[int32]string) (context.Context, error) { + return ctx, s.Send(v) +} ` var StreamingResultPrimitiveMapClientStreamRecvCode = `// Recv reads instances of "map[int32]string" from the @@ -762,6 +875,14 @@ func (s *StreamingResultPrimitiveMapMethodClientStream) Recv() (map[int32]string } return body, nil } + +// RecvWithContext reads instances of "map[int32]string" from the +// "StreamingResultPrimitiveMapMethod" endpoint websocket connection with +// context. +func (s *StreamingResultPrimitiveMapMethodClientStream) RecvWithContext(ctx context.Context) (map[int32]string, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var StreamingResultUserTypeArrayServerStreamSendCode = `// Send streams instances of "[]*streamingresultusertypearrayservice.UserType" @@ -789,6 +910,14 @@ func (s *StreamingResultUserTypeArrayMethodServerStream) Send(v []*streamingresu body := NewStreamingResultUserTypeArrayMethodResponseBody(res) return s.conn.WriteJSON(body) } + +// SendWithContext streams instances of +// "[]*streamingresultusertypearrayservice.UserType" to the +// "StreamingResultUserTypeArrayMethod" endpoint websocket connection with +// context. +func (s *StreamingResultUserTypeArrayMethodServerStream) SendWithContext(ctx context.Context, v []*streamingresultusertypearrayservice.UserType) (context.Context, error) { + return ctx, s.Send(v) +} ` var StreamingResultUserTypeArrayClientStreamRecvCode = `// Recv reads instances of "[]*streamingresultusertypearrayservice.UserType" @@ -810,6 +939,15 @@ func (s *StreamingResultUserTypeArrayMethodClientStream) Recv() ([]*streamingres res := NewStreamingResultUserTypeArrayMethodUserTypeOK(body) return res, nil } + +// RecvWithContext reads instances of +// "[]*streamingresultusertypearrayservice.UserType" from the +// "StreamingResultUserTypeArrayMethod" endpoint websocket connection with +// context. +func (s *StreamingResultUserTypeArrayMethodClientStream) RecvWithContext(ctx context.Context) ([]*streamingresultusertypearrayservice.UserType, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var StreamingResultUserTypeMapServerStreamSendCode = `// Send streams instances of @@ -838,6 +976,14 @@ func (s *StreamingResultUserTypeMapMethodServerStream) Send(v map[string]*stream body := NewStreamingResultUserTypeMapMethodResponseBody(res) return s.conn.WriteJSON(body) } + +// SendWithContext streams instances of +// "map[string]*streamingresultusertypemapservice.UserType" to the +// "StreamingResultUserTypeMapMethod" endpoint websocket connection with +// context. +func (s *StreamingResultUserTypeMapMethodServerStream) SendWithContext(ctx context.Context, v map[string]*streamingresultusertypemapservice.UserType) (context.Context, error) { + return ctx, s.Send(v) +} ` var StreamingResultUserTypeMapClientStreamRecvCode = `// Recv reads instances of @@ -860,6 +1006,15 @@ func (s *StreamingResultUserTypeMapMethodClientStream) Recv() (map[string]*strea res := NewStreamingResultUserTypeMapMethodMapStringUserTypeOK(body) return res, nil } + +// RecvWithContext reads instances of +// "map[string]*streamingresultusertypemapservice.UserType" from the +// "StreamingResultUserTypeMapMethod" endpoint websocket connection with +// context. +func (s *StreamingResultUserTypeMapMethodClientStream) RecvWithContext(ctx context.Context) (map[string]*streamingresultusertypemapservice.UserType, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var StreamingResultNoPayloadClientEndpointCode = `// StreamingResultNoPayloadMethod returns an endpoint that makes HTTP requests @@ -966,6 +1121,13 @@ func (s *StreamingPayloadMethodServerStream) SendAndClose(v *streamingpayloadser body := NewStreamingPayloadMethodResponseBody(res) return s.conn.WriteJSON(body) } + +// SendAndCloseWithContext streams instances of +// "streamingpayloadservice.UserType" to the "StreamingPayloadMethod" endpoint +// websocket connection with context and closes the connection. +func (s *StreamingPayloadMethodServerStream) SendAndCloseWithContext(ctx context.Context, v *streamingpayloadservice.UserType) (context.Context, error) { + return ctx, s.SendAndClose(v) +} ` var StreamingPayloadServerStreamRecvCode = `// Recv reads instances of "streamingpayloadservice.Request" from the @@ -1001,6 +1163,13 @@ func (s *StreamingPayloadMethodServerStream) Recv() (*streamingpayloadservice.Re } return NewStreamingPayloadMethodStreamingBody(msg), nil } + +// RecvWithContext reads instances of "streamingpayloadservice.Request" from +// the "StreamingPayloadMethod" endpoint websocket connection with context. +func (s *StreamingPayloadMethodServerStream) RecvWithContext(ctx context.Context) (*streamingpayloadservice.Request, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var StreamingPayloadClientEndpointCode = `// StreamingPayloadMethod returns an endpoint that makes HTTP requests to the @@ -1041,6 +1210,12 @@ func (s *StreamingPayloadMethodClientStream) Send(v *streamingpayloadservice.Req body := NewStreamingPayloadMethodStreamingBody(v) return s.conn.WriteJSON(body) } + +// SendWithContext streams instances of "streamingpayloadservice.Request" to +// the "StreamingPayloadMethod" endpoint websocket connection with context. +func (s *StreamingPayloadMethodClientStream) SendWithContext(ctx context.Context, v *streamingpayloadservice.Request) (context.Context, error) { + return ctx, s.Send(v) +} ` var StreamingPayloadClientStreamRecvCode = `// CloseAndRecv stops sending messages to the "StreamingPayloadMethod" endpoint @@ -1068,6 +1243,14 @@ func (s *StreamingPayloadMethodClientStream) CloseAndRecv() (*streamingpayloadse res := NewStreamingPayloadMethodUserTypeOK(&body) return res, nil } + +// CloseAndRecvWithContext stops sending messages to the +// "StreamingPayloadMethod" endpoint websocket connection and reads instances +// of "streamingpayloadservice.UserType" from the connection with context. +func (s *StreamingPayloadMethodClientStream) CloseAndRecvWithContext(ctx context.Context) (*streamingpayloadservice.UserType, context.Context, error) { + res, err := s.CloseAndRecv() + return res, ctx, err +} ` var StreamingPayloadNoPayloadServerHandlerInitCode = `// NewStreamingPayloadNoPayloadMethodHandler creates a HTTP handler which loads @@ -1152,6 +1335,13 @@ func (s *StreamingPayloadNoPayloadMethodClientStream) Send(v *streamingpayloadno body := NewStreamingPayloadNoPayloadMethodStreamingBody(v) return s.conn.WriteJSON(body) } + +// SendWithContext streams instances of +// "streamingpayloadnopayloadservice.Request" to the +// "StreamingPayloadNoPayloadMethod" endpoint websocket connection with context. +func (s *StreamingPayloadNoPayloadMethodClientStream) SendWithContext(ctx context.Context, v *streamingpayloadnopayloadservice.Request) (context.Context, error) { + return ctx, s.Send(v) +} ` var StreamingPayloadNoPayloadClientStreamRecvCode = `// CloseAndRecv stops sending messages to the "StreamingPayloadNoPayloadMethod" @@ -1179,6 +1369,15 @@ func (s *StreamingPayloadNoPayloadMethodClientStream) CloseAndRecv() (*streaming res := NewStreamingPayloadNoPayloadMethodUserTypeOK(&body) return res, nil } + +// CloseAndRecvWithContext stops sending messages to the +// "StreamingPayloadNoPayloadMethod" endpoint websocket connection and reads +// instances of "streamingpayloadnopayloadservice.UserType" from the connection +// with context. +func (s *StreamingPayloadNoPayloadMethodClientStream) CloseAndRecvWithContext(ctx context.Context) (*streamingpayloadnopayloadservice.UserType, context.Context, error) { + res, err := s.CloseAndRecv() + return res, ctx, err +} ` var StreamingPayloadNoResultServerStreamRecvCode = `// Recv reads instances of "string" from the "StreamingPayloadNoResultMethod" @@ -1214,6 +1413,13 @@ func (s *StreamingPayloadNoResultMethodServerStream) Recv() (string, error) { } return *msg, nil } + +// RecvWithContext reads instances of "string" from the +// "StreamingPayloadNoResultMethod" endpoint websocket connection with context. +func (s *StreamingPayloadNoResultMethodServerStream) RecvWithContext(ctx context.Context) (string, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var StreamingPayloadNoResultServerStreamCloseCode = `// Close closes the "StreamingPayloadNoResultMethod" endpoint websocket @@ -1239,6 +1445,12 @@ var StreamingPayloadNoResultClientStreamSendCode = `// Send streams instances of func (s *StreamingPayloadNoResultMethodClientStream) Send(v string) error { return s.conn.WriteJSON(v) } + +// SendWithContext streams instances of "string" to the +// "StreamingPayloadNoResultMethod" endpoint websocket connection with context. +func (s *StreamingPayloadNoResultMethodClientStream) SendWithContext(ctx context.Context, v string) (context.Context, error) { + return ctx, s.Send(v) +} ` var StreamingPayloadNoResultClientStreamCloseCode = `// Close closes the "StreamingPayloadNoResultMethod" endpoint websocket @@ -1271,6 +1483,14 @@ func (s *StreamingPayloadResultWithViewsMethodServerStream) SendAndClose(v *stre } return s.conn.WriteJSON(body) } + +// SendAndCloseWithContext streams instances of +// "streamingpayloadresultwithviewsservice.Usertype" to the +// "StreamingPayloadResultWithViewsMethod" endpoint websocket connection with +// context and closes the connection. +func (s *StreamingPayloadResultWithViewsMethodServerStream) SendAndCloseWithContext(ctx context.Context, v *streamingpayloadresultwithviewsservice.Usertype) (context.Context, error) { + return ctx, s.SendAndClose(v) +} ` var StreamingPayloadResultWithViewsServerStreamRecvCode = `// Recv reads instances of "float32" from the @@ -1306,6 +1526,14 @@ func (s *StreamingPayloadResultWithViewsMethodServerStream) Recv() (float32, err } return *msg, nil } + +// RecvWithContext reads instances of "float32" from the +// "StreamingPayloadResultWithViewsMethod" endpoint websocket connection with +// context. +func (s *StreamingPayloadResultWithViewsMethodServerStream) RecvWithContext(ctx context.Context) (float32, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var StreamingPayloadResultWithViewsServerStreamSetViewCode = `// SetView sets the view to render the @@ -1321,6 +1549,13 @@ var StreamingPayloadResultWithViewsClientStreamSendCode = `// Send streams insta func (s *StreamingPayloadResultWithViewsMethodClientStream) Send(v float32) error { return s.conn.WriteJSON(v) } + +// SendWithContext streams instances of "float32" to the +// "StreamingPayloadResultWithViewsMethod" endpoint websocket connection with +// context. +func (s *StreamingPayloadResultWithViewsMethodClientStream) SendWithContext(ctx context.Context, v float32) (context.Context, error) { + return ctx, s.Send(v) +} ` var StreamingPayloadResultWithViewsClientStreamRecvCode = `// CloseAndRecv stops sending messages to the @@ -1353,6 +1588,15 @@ func (s *StreamingPayloadResultWithViewsMethodClientStream) CloseAndRecv() (*str } return streamingpayloadresultwithviewsservice.NewUsertype(vres), nil } + +// CloseAndRecvWithContext stops sending messages to the +// "StreamingPayloadResultWithViewsMethod" endpoint websocket connection and +// reads instances of "streamingpayloadresultwithviewsservice.Usertype" from +// the connection with context. +func (s *StreamingPayloadResultWithViewsMethodClientStream) CloseAndRecvWithContext(ctx context.Context) (*streamingpayloadresultwithviewsservice.Usertype, context.Context, error) { + res, err := s.CloseAndRecv() + return res, ctx, err +} ` var StreamingPayloadResultWithViewsClientStreamSetViewCode = `// SetView sets the view to render the float32 type before sending to the @@ -1372,6 +1616,14 @@ func (s *StreamingPayloadResultWithExplicitViewMethodServerStream) SendAndClose( body := NewStreamingPayloadResultWithExplicitViewMethodResponseBodyExtended(res.Projected) return s.conn.WriteJSON(body) } + +// SendAndCloseWithContext streams instances of +// "streamingpayloadresultwithexplicitviewservice.Usertype" to the +// "StreamingPayloadResultWithExplicitViewMethod" endpoint websocket connection +// with context and closes the connection. +func (s *StreamingPayloadResultWithExplicitViewMethodServerStream) SendAndCloseWithContext(ctx context.Context, v *streamingpayloadresultwithexplicitviewservice.Usertype) (context.Context, error) { + return ctx, s.SendAndClose(v) +} ` var StreamingPayloadResultWithExplicitViewServerStreamRecvCode = `// Recv reads instances of "float32" from the @@ -1407,6 +1659,14 @@ func (s *StreamingPayloadResultWithExplicitViewMethodServerStream) Recv() (float } return *msg, nil } + +// RecvWithContext reads instances of "float32" from the +// "StreamingPayloadResultWithExplicitViewMethod" endpoint websocket connection +// with context. +func (s *StreamingPayloadResultWithExplicitViewMethodServerStream) RecvWithContext(ctx context.Context) (float32, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var StreamingPayloadResultWithExplicitViewClientStreamSendCode = `// Send streams instances of "float32" to the @@ -1414,6 +1674,13 @@ var StreamingPayloadResultWithExplicitViewClientStreamSendCode = `// Send stream func (s *StreamingPayloadResultWithExplicitViewMethodClientStream) Send(v float32) error { return s.conn.WriteJSON(v) } + +// SendWithContext streams instances of "float32" to the +// "StreamingPayloadResultWithExplicitViewMethod" endpoint websocket connection +// with context. +func (s *StreamingPayloadResultWithExplicitViewMethodClientStream) SendWithContext(ctx context.Context, v float32) (context.Context, error) { + return ctx, s.Send(v) +} ` var StreamingPayloadResultWithExplicitViewClientStreamRecvCode = `// CloseAndRecv stops sending messages to the @@ -1446,6 +1713,16 @@ func (s *StreamingPayloadResultWithExplicitViewMethodClientStream) CloseAndRecv( } return streamingpayloadresultwithexplicitviewservice.NewUsertype(vres), nil } + +// CloseAndRecvWithContext stops sending messages to the +// "StreamingPayloadResultWithExplicitViewMethod" endpoint websocket connection +// and reads instances of +// "streamingpayloadresultwithexplicitviewservice.Usertype" from the connection +// with context. +func (s *StreamingPayloadResultWithExplicitViewMethodClientStream) CloseAndRecvWithContext(ctx context.Context) (*streamingpayloadresultwithexplicitviewservice.Usertype, context.Context, error) { + res, err := s.CloseAndRecv() + return res, ctx, err +} ` var StreamingPayloadResultCollectionWithViewsServerStreamSendCode = `// SendAndClose streams instances of @@ -1466,6 +1743,14 @@ func (s *StreamingPayloadResultCollectionWithViewsMethodServerStream) SendAndClo } return s.conn.WriteJSON(body) } + +// SendAndCloseWithContext streams instances of +// "streamingpayloadresultcollectionwithviewsservice.UsertypeCollection" to the +// "StreamingPayloadResultCollectionWithViewsMethod" endpoint websocket +// connection with context and closes the connection. +func (s *StreamingPayloadResultCollectionWithViewsMethodServerStream) SendAndCloseWithContext(ctx context.Context, v streamingpayloadresultcollectionwithviewsservice.UsertypeCollection) (context.Context, error) { + return ctx, s.SendAndClose(v) +} ` var StreamingPayloadResultCollectionWithViewsServerStreamRecvCode = `// Recv reads instances of "any" from the @@ -1502,6 +1787,14 @@ func (s *StreamingPayloadResultCollectionWithViewsMethodServerStream) Recv() (an } return *msg, nil } + +// RecvWithContext reads instances of "any" from the +// "StreamingPayloadResultCollectionWithViewsMethod" endpoint websocket +// connection with context. +func (s *StreamingPayloadResultCollectionWithViewsMethodServerStream) RecvWithContext(ctx context.Context) (any, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var StreamingPayloadResultCollectionWithViewsServerStreamSetViewCode = `// SetView sets the view to render the @@ -1519,6 +1812,13 @@ var StreamingPayloadResultCollectionWithViewsClientStreamSendCode = `// Send str func (s *StreamingPayloadResultCollectionWithViewsMethodClientStream) Send(v any) error { return s.conn.WriteJSON(v) } + +// SendWithContext streams instances of "any" to the +// "StreamingPayloadResultCollectionWithViewsMethod" endpoint websocket +// connection with context. +func (s *StreamingPayloadResultCollectionWithViewsMethodClientStream) SendWithContext(ctx context.Context, v any) (context.Context, error) { + return ctx, s.Send(v) +} ` var StreamingPayloadResultCollectionWithViewsClientStreamRecvCode = `// CloseAndRecv stops sending messages to the @@ -1552,6 +1852,16 @@ func (s *StreamingPayloadResultCollectionWithViewsMethodClientStream) CloseAndRe } return streamingpayloadresultcollectionwithviewsservice.NewUsertypeCollection(vres), nil } + +// CloseAndRecvWithContext stops sending messages to the +// "StreamingPayloadResultCollectionWithViewsMethod" endpoint websocket +// connection and reads instances of +// "streamingpayloadresultcollectionwithviewsservice.UsertypeCollection" from +// the connection with context. +func (s *StreamingPayloadResultCollectionWithViewsMethodClientStream) CloseAndRecvWithContext(ctx context.Context) (streamingpayloadresultcollectionwithviewsservice.UsertypeCollection, context.Context, error) { + res, err := s.CloseAndRecv() + return res, ctx, err +} ` var StreamingPayloadResultCollectionWithViewsClientStreamSetViewCode = `// SetView sets the view to render the any type before sending to the @@ -1572,6 +1882,14 @@ func (s *StreamingPayloadResultCollectionWithExplicitViewMethodServerStream) Sen body := NewUsertypeResponseTinyCollection(res.Projected) return s.conn.WriteJSON(body) } + +// SendAndCloseWithContext streams instances of +// "streamingpayloadresultcollectionwithexplicitviewservice.UsertypeCollection" +// to the "StreamingPayloadResultCollectionWithExplicitViewMethod" endpoint +// websocket connection with context and closes the connection. +func (s *StreamingPayloadResultCollectionWithExplicitViewMethodServerStream) SendAndCloseWithContext(ctx context.Context, v streamingpayloadresultcollectionwithexplicitviewservice.UsertypeCollection) (context.Context, error) { + return ctx, s.SendAndClose(v) +} ` var StreamingPayloadResultCollectionWithExplicitViewServerStreamRecvCode = `// Recv reads instances of "any" from the @@ -1608,6 +1926,14 @@ func (s *StreamingPayloadResultCollectionWithExplicitViewMethodServerStream) Rec } return *msg, nil } + +// RecvWithContext reads instances of "any" from the +// "StreamingPayloadResultCollectionWithExplicitViewMethod" endpoint websocket +// connection with context. +func (s *StreamingPayloadResultCollectionWithExplicitViewMethodServerStream) RecvWithContext(ctx context.Context) (any, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var StreamingPayloadResultCollectionWithExplicitViewClientStreamSendCode = `// Send streams instances of "any" to the @@ -1616,6 +1942,13 @@ var StreamingPayloadResultCollectionWithExplicitViewClientStreamSendCode = `// S func (s *StreamingPayloadResultCollectionWithExplicitViewMethodClientStream) Send(v any) error { return s.conn.WriteJSON(v) } + +// SendWithContext streams instances of "any" to the +// "StreamingPayloadResultCollectionWithExplicitViewMethod" endpoint websocket +// connection with context. +func (s *StreamingPayloadResultCollectionWithExplicitViewMethodClientStream) SendWithContext(ctx context.Context, v any) (context.Context, error) { + return ctx, s.Send(v) +} ` var StreamingPayloadResultCollectionWithExplicitViewClientStreamRecvCode = `// CloseAndRecv stops sending messages to the @@ -1649,6 +1982,16 @@ func (s *StreamingPayloadResultCollectionWithExplicitViewMethodClientStream) Clo } return streamingpayloadresultcollectionwithexplicitviewservice.NewUsertypeCollection(vres), nil } + +// CloseAndRecvWithContext stops sending messages to the +// "StreamingPayloadResultCollectionWithExplicitViewMethod" endpoint websocket +// connection and reads instances of +// "streamingpayloadresultcollectionwithexplicitviewservice.UsertypeCollection" +// from the connection with context. +func (s *StreamingPayloadResultCollectionWithExplicitViewMethodClientStream) CloseAndRecvWithContext(ctx context.Context) (streamingpayloadresultcollectionwithexplicitviewservice.UsertypeCollection, context.Context, error) { + res, err := s.CloseAndRecv() + return res, ctx, err +} ` var StreamingPayloadPrimitiveServerStreamSendCode = `// SendAndClose streams instances of "string" to the @@ -1659,6 +2002,13 @@ func (s *StreamingPayloadPrimitiveMethodServerStream) SendAndClose(v string) err res := v return s.conn.WriteJSON(res) } + +// SendAndCloseWithContext streams instances of "string" to the +// "StreamingPayloadPrimitiveMethod" endpoint websocket connection with context +// and closes the connection. +func (s *StreamingPayloadPrimitiveMethodServerStream) SendAndCloseWithContext(ctx context.Context, v string) (context.Context, error) { + return ctx, s.SendAndClose(v) +} ` var StreamingPayloadPrimitiveServerStreamRecvCode = `// Recv reads instances of "string" from the "StreamingPayloadPrimitiveMethod" @@ -1694,6 +2044,13 @@ func (s *StreamingPayloadPrimitiveMethodServerStream) Recv() (string, error) { } return *msg, nil } + +// RecvWithContext reads instances of "string" from the +// "StreamingPayloadPrimitiveMethod" endpoint websocket connection with context. +func (s *StreamingPayloadPrimitiveMethodServerStream) RecvWithContext(ctx context.Context) (string, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var StreamingPayloadPrimitiveClientStreamSendCode = `// Send streams instances of "string" to the "StreamingPayloadPrimitiveMethod" @@ -1701,6 +2058,12 @@ var StreamingPayloadPrimitiveClientStreamSendCode = `// Send streams instances o func (s *StreamingPayloadPrimitiveMethodClientStream) Send(v string) error { return s.conn.WriteJSON(v) } + +// SendWithContext streams instances of "string" to the +// "StreamingPayloadPrimitiveMethod" endpoint websocket connection with context. +func (s *StreamingPayloadPrimitiveMethodClientStream) SendWithContext(ctx context.Context, v string) (context.Context, error) { + return ctx, s.Send(v) +} ` var StreamingPayloadPrimitiveClientStreamRecvCode = `// CloseAndRecv stops sending messages to the "StreamingPayloadPrimitiveMethod" @@ -1727,6 +2090,14 @@ func (s *StreamingPayloadPrimitiveMethodClientStream) CloseAndRecv() (string, er } return body, nil } + +// CloseAndRecvWithContext stops sending messages to the +// "StreamingPayloadPrimitiveMethod" endpoint websocket connection and reads +// instances of "string" from the connection with context. +func (s *StreamingPayloadPrimitiveMethodClientStream) CloseAndRecvWithContext(ctx context.Context) (string, context.Context, error) { + res, err := s.CloseAndRecv() + return res, ctx, err +} ` var StreamingPayloadPrimitiveArrayServerStreamSendCode = `// SendAndClose streams instances of "[]string" to the @@ -1737,6 +2108,13 @@ func (s *StreamingPayloadPrimitiveArrayMethodServerStream) SendAndClose(v []stri res := v return s.conn.WriteJSON(res) } + +// SendAndCloseWithContext streams instances of "[]string" to the +// "StreamingPayloadPrimitiveArrayMethod" endpoint websocket connection with +// context and closes the connection. +func (s *StreamingPayloadPrimitiveArrayMethodServerStream) SendAndCloseWithContext(ctx context.Context, v []string) (context.Context, error) { + return ctx, s.SendAndClose(v) +} ` var StreamingPayloadPrimitiveArrayServerStreamRecvCode = `// Recv reads instances of "[]int32" from the @@ -1772,6 +2150,14 @@ func (s *StreamingPayloadPrimitiveArrayMethodServerStream) Recv() ([]int32, erro } return body, nil } + +// RecvWithContext reads instances of "[]int32" from the +// "StreamingPayloadPrimitiveArrayMethod" endpoint websocket connection with +// context. +func (s *StreamingPayloadPrimitiveArrayMethodServerStream) RecvWithContext(ctx context.Context) ([]int32, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var StreamingPayloadPrimitiveArrayClientStreamSendCode = `// Send streams instances of "[]int32" to the @@ -1779,6 +2165,13 @@ var StreamingPayloadPrimitiveArrayClientStreamSendCode = `// Send streams instan func (s *StreamingPayloadPrimitiveArrayMethodClientStream) Send(v []int32) error { return s.conn.WriteJSON(v) } + +// SendWithContext streams instances of "[]int32" to the +// "StreamingPayloadPrimitiveArrayMethod" endpoint websocket connection with +// context. +func (s *StreamingPayloadPrimitiveArrayMethodClientStream) SendWithContext(ctx context.Context, v []int32) (context.Context, error) { + return ctx, s.Send(v) +} ` var StreamingPayloadPrimitiveArrayClientStreamRecvCode = `// CloseAndRecv stops sending messages to the @@ -1805,6 +2198,14 @@ func (s *StreamingPayloadPrimitiveArrayMethodClientStream) CloseAndRecv() ([]str } return body, nil } + +// CloseAndRecvWithContext stops sending messages to the +// "StreamingPayloadPrimitiveArrayMethod" endpoint websocket connection and +// reads instances of "[]string" from the connection with context. +func (s *StreamingPayloadPrimitiveArrayMethodClientStream) CloseAndRecvWithContext(ctx context.Context) ([]string, context.Context, error) { + res, err := s.CloseAndRecv() + return res, ctx, err +} ` var StreamingPayloadPrimitiveMapServerStreamSendCode = `// SendAndClose streams instances of "map[int]int" to the @@ -1815,6 +2216,13 @@ func (s *StreamingPayloadPrimitiveMapMethodServerStream) SendAndClose(v map[int] res := v return s.conn.WriteJSON(res) } + +// SendAndCloseWithContext streams instances of "map[int]int" to the +// "StreamingPayloadPrimitiveMapMethod" endpoint websocket connection with +// context and closes the connection. +func (s *StreamingPayloadPrimitiveMapMethodServerStream) SendAndCloseWithContext(ctx context.Context, v map[int]int) (context.Context, error) { + return ctx, s.SendAndClose(v) +} ` var StreamingPayloadPrimitiveMapServerStreamRecvCode = `// Recv reads instances of "map[string]int32" from the @@ -1850,6 +2258,14 @@ func (s *StreamingPayloadPrimitiveMapMethodServerStream) Recv() (map[string]int3 } return body, nil } + +// RecvWithContext reads instances of "map[string]int32" from the +// "StreamingPayloadPrimitiveMapMethod" endpoint websocket connection with +// context. +func (s *StreamingPayloadPrimitiveMapMethodServerStream) RecvWithContext(ctx context.Context) (map[string]int32, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var StreamingPayloadPrimitiveMapClientStreamSendCode = `// Send streams instances of "map[string]int32" to the @@ -1857,6 +2273,13 @@ var StreamingPayloadPrimitiveMapClientStreamSendCode = `// Send streams instance func (s *StreamingPayloadPrimitiveMapMethodClientStream) Send(v map[string]int32) error { return s.conn.WriteJSON(v) } + +// SendWithContext streams instances of "map[string]int32" to the +// "StreamingPayloadPrimitiveMapMethod" endpoint websocket connection with +// context. +func (s *StreamingPayloadPrimitiveMapMethodClientStream) SendWithContext(ctx context.Context, v map[string]int32) (context.Context, error) { + return ctx, s.Send(v) +} ` var StreamingPayloadPrimitiveMapClientStreamRecvCode = `// CloseAndRecv stops sending messages to the @@ -1883,6 +2306,14 @@ func (s *StreamingPayloadPrimitiveMapMethodClientStream) CloseAndRecv() (map[int } return body, nil } + +// CloseAndRecvWithContext stops sending messages to the +// "StreamingPayloadPrimitiveMapMethod" endpoint websocket connection and reads +// instances of "map[int]int" from the connection with context. +func (s *StreamingPayloadPrimitiveMapMethodClientStream) CloseAndRecvWithContext(ctx context.Context) (map[int]int, context.Context, error) { + res, err := s.CloseAndRecv() + return res, ctx, err +} ` var StreamingPayloadUserTypeArrayServerStreamSendCode = `// SendAndClose streams instances of "string" to the @@ -1893,6 +2324,13 @@ func (s *StreamingPayloadUserTypeArrayMethodServerStream) SendAndClose(v string) res := v return s.conn.WriteJSON(res) } + +// SendAndCloseWithContext streams instances of "string" to the +// "StreamingPayloadUserTypeArrayMethod" endpoint websocket connection with +// context and closes the connection. +func (s *StreamingPayloadUserTypeArrayMethodServerStream) SendAndCloseWithContext(ctx context.Context, v string) (context.Context, error) { + return ctx, s.SendAndClose(v) +} ` var StreamingPayloadUserTypeArrayServerStreamRecvCode = `// Recv reads instances of @@ -1929,6 +2367,15 @@ func (s *StreamingPayloadUserTypeArrayMethodServerStream) Recv() ([]*streamingpa } return NewStreamingPayloadUserTypeArrayMethodArray(body), nil } + +// RecvWithContext reads instances of +// "[]*streamingpayloadusertypearrayservice.RequestType" from the +// "StreamingPayloadUserTypeArrayMethod" endpoint websocket connection with +// context. +func (s *StreamingPayloadUserTypeArrayMethodServerStream) RecvWithContext(ctx context.Context) ([]*streamingpayloadusertypearrayservice.RequestType, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var StreamingPayloadUserTypeArrayClientStreamSendCode = `// Send streams instances of @@ -1938,6 +2385,14 @@ func (s *StreamingPayloadUserTypeArrayMethodClientStream) Send(v []*streamingpay body := NewRequestType(v) return s.conn.WriteJSON(body) } + +// SendWithContext streams instances of +// "[]*streamingpayloadusertypearrayservice.RequestType" to the +// "StreamingPayloadUserTypeArrayMethod" endpoint websocket connection with +// context. +func (s *StreamingPayloadUserTypeArrayMethodClientStream) SendWithContext(ctx context.Context, v []*streamingpayloadusertypearrayservice.RequestType) (context.Context, error) { + return ctx, s.Send(v) +} ` var StreamingPayloadUserTypeArrayClientStreamRecvCode = `// CloseAndRecv stops sending messages to the @@ -1964,6 +2419,14 @@ func (s *StreamingPayloadUserTypeArrayMethodClientStream) CloseAndRecv() (string } return body, nil } + +// CloseAndRecvWithContext stops sending messages to the +// "StreamingPayloadUserTypeArrayMethod" endpoint websocket connection and +// reads instances of "string" from the connection with context. +func (s *StreamingPayloadUserTypeArrayMethodClientStream) CloseAndRecvWithContext(ctx context.Context) (string, context.Context, error) { + res, err := s.CloseAndRecv() + return res, ctx, err +} ` var StreamingPayloadUserTypeMapServerStreamSendCode = `// SendAndClose streams instances of "[]string" to the @@ -1974,6 +2437,13 @@ func (s *StreamingPayloadUserTypeMapMethodServerStream) SendAndClose(v []string) res := v return s.conn.WriteJSON(res) } + +// SendAndCloseWithContext streams instances of "[]string" to the +// "StreamingPayloadUserTypeMapMethod" endpoint websocket connection with +// context and closes the connection. +func (s *StreamingPayloadUserTypeMapMethodServerStream) SendAndCloseWithContext(ctx context.Context, v []string) (context.Context, error) { + return ctx, s.SendAndClose(v) +} ` var StreamingPayloadUserTypeMapServerStreamRecvCode = `// Recv reads instances of @@ -2010,6 +2480,15 @@ func (s *StreamingPayloadUserTypeMapMethodServerStream) Recv() (map[string]*stre } return NewStreamingPayloadUserTypeMapMethodMap(body), nil } + +// RecvWithContext reads instances of +// "map[string]*streamingpayloadusertypemapservice.RequestType" from the +// "StreamingPayloadUserTypeMapMethod" endpoint websocket connection with +// context. +func (s *StreamingPayloadUserTypeMapMethodServerStream) RecvWithContext(ctx context.Context) (map[string]*streamingpayloadusertypemapservice.RequestType, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var StreamingPayloadUserTypeMapClientStreamSendCode = `// Send streams instances of @@ -2019,6 +2498,14 @@ func (s *StreamingPayloadUserTypeMapMethodClientStream) Send(v map[string]*strea body := NewMapStringRequestType(v) return s.conn.WriteJSON(body) } + +// SendWithContext streams instances of +// "map[string]*streamingpayloadusertypemapservice.RequestType" to the +// "StreamingPayloadUserTypeMapMethod" endpoint websocket connection with +// context. +func (s *StreamingPayloadUserTypeMapMethodClientStream) SendWithContext(ctx context.Context, v map[string]*streamingpayloadusertypemapservice.RequestType) (context.Context, error) { + return ctx, s.Send(v) +} ` var StreamingPayloadUserTypeMapClientStreamRecvCode = `// CloseAndRecv stops sending messages to the @@ -2045,6 +2532,14 @@ func (s *StreamingPayloadUserTypeMapMethodClientStream) CloseAndRecv() ([]string } return body, nil } + +// CloseAndRecvWithContext stops sending messages to the +// "StreamingPayloadUserTypeMapMethod" endpoint websocket connection and reads +// instances of "[]string" from the connection with context. +func (s *StreamingPayloadUserTypeMapMethodClientStream) CloseAndRecvWithContext(ctx context.Context) ([]string, context.Context, error) { + res, err := s.CloseAndRecv() + return res, ctx, err +} ` var BidirectionalStreamingServerHandlerInitCode = `// NewBidirectionalStreamingMethodHandler creates a HTTP handler which loads @@ -2128,6 +2623,13 @@ func (s *BidirectionalStreamingMethodServerStream) Send(v *bidirectionalstreamin body := NewBidirectionalStreamingMethodResponseBody(res) return s.conn.WriteJSON(body) } + +// SendWithContext streams instances of +// "bidirectionalstreamingservice.UserType" to the +// "BidirectionalStreamingMethod" endpoint websocket connection with context. +func (s *BidirectionalStreamingMethodServerStream) SendWithContext(ctx context.Context, v *bidirectionalstreamingservice.UserType) (context.Context, error) { + return ctx, s.Send(v) +} ` var BidirectionalStreamingServerStreamRecvCode = `// Recv reads instances of "bidirectionalstreamingservice.Request" from the @@ -2163,6 +2665,14 @@ func (s *BidirectionalStreamingMethodServerStream) Recv() (*bidirectionalstreami } return NewBidirectionalStreamingMethodStreamingBody(msg), nil } + +// RecvWithContext reads instances of "bidirectionalstreamingservice.Request" +// from the "BidirectionalStreamingMethod" endpoint websocket connection with +// context. +func (s *BidirectionalStreamingMethodServerStream) RecvWithContext(ctx context.Context) (*bidirectionalstreamingservice.Request, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var BidirectionalStreamingServerStreamCloseCode = `// Close closes the "BidirectionalStreamingMethod" endpoint websocket @@ -2222,6 +2732,13 @@ func (s *BidirectionalStreamingMethodClientStream) Send(v *bidirectionalstreamin body := NewBidirectionalStreamingMethodStreamingBody(v) return s.conn.WriteJSON(body) } + +// SendWithContext streams instances of "bidirectionalstreamingservice.Request" +// to the "BidirectionalStreamingMethod" endpoint websocket connection with +// context. +func (s *BidirectionalStreamingMethodClientStream) SendWithContext(ctx context.Context, v *bidirectionalstreamingservice.Request) (context.Context, error) { + return ctx, s.Send(v) +} ` var BidirectionalStreamingClientStreamRecvCode = `// Recv reads instances of "bidirectionalstreamingservice.UserType" from the @@ -2242,6 +2759,14 @@ func (s *BidirectionalStreamingMethodClientStream) Recv() (*bidirectionalstreami res := NewBidirectionalStreamingMethodUserTypeOK(&body) return res, nil } + +// RecvWithContext reads instances of "bidirectionalstreamingservice.UserType" +// from the "BidirectionalStreamingMethod" endpoint websocket connection with +// context. +func (s *BidirectionalStreamingMethodClientStream) RecvWithContext(ctx context.Context) (*bidirectionalstreamingservice.UserType, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var BidirectionalStreamingClientStreamCloseCode = `// Close closes the "BidirectionalStreamingMethod" endpoint websocket @@ -2357,6 +2882,14 @@ func (s *BidirectionalStreamingNoPayloadMethodClientStream) Send(v *bidirectiona body := NewBidirectionalStreamingNoPayloadMethodStreamingBody(v) return s.conn.WriteJSON(body) } + +// SendWithContext streams instances of +// "bidirectionalstreamingnopayloadservice.Request" to the +// "BidirectionalStreamingNoPayloadMethod" endpoint websocket connection with +// context. +func (s *BidirectionalStreamingNoPayloadMethodClientStream) SendWithContext(ctx context.Context, v *bidirectionalstreamingnopayloadservice.Request) (context.Context, error) { + return ctx, s.Send(v) +} ` var BidirectionalStreamingNoPayloadClientStreamRecvCode = `// Recv reads instances of "bidirectionalstreamingnopayloadservice.UserType" @@ -2378,6 +2911,15 @@ func (s *BidirectionalStreamingNoPayloadMethodClientStream) Recv() (*bidirection res := NewBidirectionalStreamingNoPayloadMethodUserTypeOK(&body) return res, nil } + +// RecvWithContext reads instances of +// "bidirectionalstreamingnopayloadservice.UserType" from the +// "BidirectionalStreamingNoPayloadMethod" endpoint websocket connection with +// context. +func (s *BidirectionalStreamingNoPayloadMethodClientStream) RecvWithContext(ctx context.Context) (*bidirectionalstreamingnopayloadservice.UserType, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var BidirectionalStreamingNoPayloadClientStreamCloseCode = `// Close closes the "BidirectionalStreamingNoPayloadMethod" endpoint websocket @@ -2428,6 +2970,14 @@ func (s *BidirectionalStreamingResultWithViewsMethodServerStream) Send(v *bidire } return s.conn.WriteJSON(body) } + +// SendWithContext streams instances of +// "bidirectionalstreamingresultwithviewsservice.Usertype" to the +// "BidirectionalStreamingResultWithViewsMethod" endpoint websocket connection +// with context. +func (s *BidirectionalStreamingResultWithViewsMethodServerStream) SendWithContext(ctx context.Context, v *bidirectionalstreamingresultwithviewsservice.Usertype) (context.Context, error) { + return ctx, s.Send(v) +} ` var BidirectionalStreamingResultWithViewsServerStreamRecvCode = `// Recv reads instances of "float32" from the @@ -2463,6 +3013,14 @@ func (s *BidirectionalStreamingResultWithViewsMethodServerStream) Recv() (float3 } return *msg, nil } + +// RecvWithContext reads instances of "float32" from the +// "BidirectionalStreamingResultWithViewsMethod" endpoint websocket connection +// with context. +func (s *BidirectionalStreamingResultWithViewsMethodServerStream) RecvWithContext(ctx context.Context) (float32, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var BidirectionalStreamingResultWithViewsServerStreamCloseCode = `// Close closes the "BidirectionalStreamingResultWithViewsMethod" endpoint @@ -2497,6 +3055,13 @@ var BidirectionalStreamingResultWithViewsClientStreamSendCode = `// Send streams func (s *BidirectionalStreamingResultWithViewsMethodClientStream) Send(v float32) error { return s.conn.WriteJSON(v) } + +// SendWithContext streams instances of "float32" to the +// "BidirectionalStreamingResultWithViewsMethod" endpoint websocket connection +// with context. +func (s *BidirectionalStreamingResultWithViewsMethodClientStream) SendWithContext(ctx context.Context, v float32) (context.Context, error) { + return ctx, s.Send(v) +} ` var BidirectionalStreamingResultWithViewsClientStreamRecvCode = `// Recv reads instances of @@ -2522,6 +3087,15 @@ func (s *BidirectionalStreamingResultWithViewsMethodClientStream) Recv() (*bidir } return bidirectionalstreamingresultwithviewsservice.NewUsertype(vres), nil } + +// RecvWithContext reads instances of +// "bidirectionalstreamingresultwithviewsservice.Usertype" from the +// "BidirectionalStreamingResultWithViewsMethod" endpoint websocket connection +// with context. +func (s *BidirectionalStreamingResultWithViewsMethodClientStream) RecvWithContext(ctx context.Context) (*bidirectionalstreamingresultwithviewsservice.Usertype, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var BidirectionalStreamingResultWithViewsClientStreamCloseCode = `// Close closes the "BidirectionalStreamingResultWithViewsMethod" endpoint @@ -2570,6 +3144,14 @@ func (s *BidirectionalStreamingResultWithExplicitViewMethodServerStream) Send(v body := NewBidirectionalStreamingResultWithExplicitViewMethodResponseBodyExtended(res.Projected) return s.conn.WriteJSON(body) } + +// SendWithContext streams instances of +// "bidirectionalstreamingresultwithexplicitviewservice.Usertype" to the +// "BidirectionalStreamingResultWithExplicitViewMethod" endpoint websocket +// connection with context. +func (s *BidirectionalStreamingResultWithExplicitViewMethodServerStream) SendWithContext(ctx context.Context, v *bidirectionalstreamingresultwithexplicitviewservice.Usertype) (context.Context, error) { + return ctx, s.Send(v) +} ` var BidirectionalStreamingResultWithExplicitViewServerStreamRecvCode = `// Recv reads instances of "float32" from the @@ -2606,6 +3188,14 @@ func (s *BidirectionalStreamingResultWithExplicitViewMethodServerStream) Recv() } return *msg, nil } + +// RecvWithContext reads instances of "float32" from the +// "BidirectionalStreamingResultWithExplicitViewMethod" endpoint websocket +// connection with context. +func (s *BidirectionalStreamingResultWithExplicitViewMethodServerStream) RecvWithContext(ctx context.Context) (float32, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var BidirectionalStreamingResultWithExplicitViewClientStreamSendCode = `// Send streams instances of "float32" to the @@ -2614,6 +3204,13 @@ var BidirectionalStreamingResultWithExplicitViewClientStreamSendCode = `// Send func (s *BidirectionalStreamingResultWithExplicitViewMethodClientStream) Send(v float32) error { return s.conn.WriteJSON(v) } + +// SendWithContext streams instances of "float32" to the +// "BidirectionalStreamingResultWithExplicitViewMethod" endpoint websocket +// connection with context. +func (s *BidirectionalStreamingResultWithExplicitViewMethodClientStream) SendWithContext(ctx context.Context, v float32) (context.Context, error) { + return ctx, s.Send(v) +} ` var BidirectionalStreamingResultWithExplicitViewClientStreamRecvCode = `// Recv reads instances of @@ -2640,6 +3237,15 @@ func (s *BidirectionalStreamingResultWithExplicitViewMethodClientStream) Recv() } return bidirectionalstreamingresultwithexplicitviewservice.NewUsertype(vres), nil } + +// RecvWithContext reads instances of +// "bidirectionalstreamingresultwithexplicitviewservice.Usertype" from the +// "BidirectionalStreamingResultWithExplicitViewMethod" endpoint websocket +// connection with context. +func (s *BidirectionalStreamingResultWithExplicitViewMethodClientStream) RecvWithContext(ctx context.Context) (*bidirectionalstreamingresultwithexplicitviewservice.Usertype, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var BidirectionalStreamingResultCollectionWithViewsServerStreamSendCode = `// Send streams instances of @@ -2679,6 +3285,14 @@ func (s *BidirectionalStreamingResultCollectionWithViewsMethodServerStream) Send } return s.conn.WriteJSON(body) } + +// SendWithContext streams instances of +// "bidirectionalstreamingresultcollectionwithviewsservice.UsertypeCollection" +// to the "BidirectionalStreamingResultCollectionWithViewsMethod" endpoint +// websocket connection with context. +func (s *BidirectionalStreamingResultCollectionWithViewsMethodServerStream) SendWithContext(ctx context.Context, v bidirectionalstreamingresultcollectionwithviewsservice.UsertypeCollection) (context.Context, error) { + return ctx, s.Send(v) +} ` var BidirectionalStreamingResultCollectionWithViewsServerStreamRecvCode = `// Recv reads instances of "any" from the @@ -2715,6 +3329,14 @@ func (s *BidirectionalStreamingResultCollectionWithViewsMethodServerStream) Recv } return *msg, nil } + +// RecvWithContext reads instances of "any" from the +// "BidirectionalStreamingResultCollectionWithViewsMethod" endpoint websocket +// connection with context. +func (s *BidirectionalStreamingResultCollectionWithViewsMethodServerStream) RecvWithContext(ctx context.Context) (any, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var BidirectionalStreamingResultCollectionWithViewsServerStreamSetViewCode = `// SetView sets the view to render the @@ -2733,6 +3355,13 @@ var BidirectionalStreamingResultCollectionWithViewsClientStreamSendCode = `// Se func (s *BidirectionalStreamingResultCollectionWithViewsMethodClientStream) Send(v any) error { return s.conn.WriteJSON(v) } + +// SendWithContext streams instances of "any" to the +// "BidirectionalStreamingResultCollectionWithViewsMethod" endpoint websocket +// connection with context. +func (s *BidirectionalStreamingResultCollectionWithViewsMethodClientStream) SendWithContext(ctx context.Context, v any) (context.Context, error) { + return ctx, s.Send(v) +} ` var BidirectionalStreamingResultCollectionWithViewsClientStreamRecvCode = `// Recv reads instances of @@ -2759,6 +3388,15 @@ func (s *BidirectionalStreamingResultCollectionWithViewsMethodClientStream) Recv } return bidirectionalstreamingresultcollectionwithviewsservice.NewUsertypeCollection(vres), nil } + +// RecvWithContext reads instances of +// "bidirectionalstreamingresultcollectionwithviewsservice.UsertypeCollection" +// from the "BidirectionalStreamingResultCollectionWithViewsMethod" endpoint +// websocket connection with context. +func (s *BidirectionalStreamingResultCollectionWithViewsMethodClientStream) RecvWithContext(ctx context.Context) (bidirectionalstreamingresultcollectionwithviewsservice.UsertypeCollection, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var BidirectionalStreamingResultCollectionWithViewsClientStreamSetViewCode = `// SetView sets the view to render the any type before sending to the @@ -2796,6 +3434,14 @@ func (s *BidirectionalStreamingResultCollectionWithExplicitViewMethodServerStrea body := NewUsertypeResponseTinyCollection(res.Projected) return s.conn.WriteJSON(body) } + +// SendWithContext streams instances of +// "bidirectionalstreamingresultcollectionwithexplicitviewservice.UsertypeCollection" +// to the "BidirectionalStreamingResultCollectionWithExplicitViewMethod" +// endpoint websocket connection with context. +func (s *BidirectionalStreamingResultCollectionWithExplicitViewMethodServerStream) SendWithContext(ctx context.Context, v bidirectionalstreamingresultcollectionwithexplicitviewservice.UsertypeCollection) (context.Context, error) { + return ctx, s.Send(v) +} ` var BidirectionalStreamingResultCollectionWithExplicitViewServerStreamRecvCode = `// Recv reads instances of "any" from the @@ -2832,6 +3478,14 @@ func (s *BidirectionalStreamingResultCollectionWithExplicitViewMethodServerStrea } return *msg, nil } + +// RecvWithContext reads instances of "any" from the +// "BidirectionalStreamingResultCollectionWithExplicitViewMethod" endpoint +// websocket connection with context. +func (s *BidirectionalStreamingResultCollectionWithExplicitViewMethodServerStream) RecvWithContext(ctx context.Context) (any, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var BidirectionalStreamingResultCollectionWithExplicitViewClientStreamSendCode = `// Send streams instances of "any" to the @@ -2840,6 +3494,13 @@ var BidirectionalStreamingResultCollectionWithExplicitViewClientStreamSendCode = func (s *BidirectionalStreamingResultCollectionWithExplicitViewMethodClientStream) Send(v any) error { return s.conn.WriteJSON(v) } + +// SendWithContext streams instances of "any" to the +// "BidirectionalStreamingResultCollectionWithExplicitViewMethod" endpoint +// websocket connection with context. +func (s *BidirectionalStreamingResultCollectionWithExplicitViewMethodClientStream) SendWithContext(ctx context.Context, v any) (context.Context, error) { + return ctx, s.Send(v) +} ` var BidirectionalStreamingResultCollectionWithExplicitViewClientStreamRecvCode = `// Recv reads instances of @@ -2866,6 +3527,15 @@ func (s *BidirectionalStreamingResultCollectionWithExplicitViewMethodClientStrea } return bidirectionalstreamingresultcollectionwithexplicitviewservice.NewUsertypeCollection(vres), nil } + +// RecvWithContext reads instances of +// "bidirectionalstreamingresultcollectionwithexplicitviewservice.UsertypeCollection" +// from the "BidirectionalStreamingResultCollectionWithExplicitViewMethod" +// endpoint websocket connection with context. +func (s *BidirectionalStreamingResultCollectionWithExplicitViewMethodClientStream) RecvWithContext(ctx context.Context) (bidirectionalstreamingresultcollectionwithexplicitviewservice.UsertypeCollection, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var BidirectionalStreamingPrimitiveServerStreamSendCode = `// Send streams instances of "string" to the @@ -2892,6 +3562,13 @@ func (s *BidirectionalStreamingPrimitiveMethodServerStream) Send(v string) error res := v return s.conn.WriteJSON(res) } + +// SendWithContext streams instances of "string" to the +// "BidirectionalStreamingPrimitiveMethod" endpoint websocket connection with +// context. +func (s *BidirectionalStreamingPrimitiveMethodServerStream) SendWithContext(ctx context.Context, v string) (context.Context, error) { + return ctx, s.Send(v) +} ` var BidirectionalStreamingPrimitiveServerStreamRecvCode = `// Recv reads instances of "string" from the @@ -2927,6 +3604,14 @@ func (s *BidirectionalStreamingPrimitiveMethodServerStream) Recv() (string, erro } return *msg, nil } + +// RecvWithContext reads instances of "string" from the +// "BidirectionalStreamingPrimitiveMethod" endpoint websocket connection with +// context. +func (s *BidirectionalStreamingPrimitiveMethodServerStream) RecvWithContext(ctx context.Context) (string, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var BidirectionalStreamingPrimitiveClientStreamSendCode = `// Send streams instances of "string" to the @@ -2934,6 +3619,13 @@ var BidirectionalStreamingPrimitiveClientStreamSendCode = `// Send streams insta func (s *BidirectionalStreamingPrimitiveMethodClientStream) Send(v string) error { return s.conn.WriteJSON(v) } + +// SendWithContext streams instances of "string" to the +// "BidirectionalStreamingPrimitiveMethod" endpoint websocket connection with +// context. +func (s *BidirectionalStreamingPrimitiveMethodClientStream) SendWithContext(ctx context.Context, v string) (context.Context, error) { + return ctx, s.Send(v) +} ` var BidirectionalStreamingPrimitiveClientStreamRecvCode = `// Recv reads instances of "string" from the @@ -2953,6 +3645,14 @@ func (s *BidirectionalStreamingPrimitiveMethodClientStream) Recv() (string, erro } return body, nil } + +// RecvWithContext reads instances of "string" from the +// "BidirectionalStreamingPrimitiveMethod" endpoint websocket connection with +// context. +func (s *BidirectionalStreamingPrimitiveMethodClientStream) RecvWithContext(ctx context.Context) (string, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var BidirectionalStreamingPrimitiveArrayServerStreamSendCode = `// Send streams instances of "[]string" to the @@ -2979,6 +3679,13 @@ func (s *BidirectionalStreamingPrimitiveArrayMethodServerStream) Send(v []string res := v return s.conn.WriteJSON(res) } + +// SendWithContext streams instances of "[]string" to the +// "BidirectionalStreamingPrimitiveArrayMethod" endpoint websocket connection +// with context. +func (s *BidirectionalStreamingPrimitiveArrayMethodServerStream) SendWithContext(ctx context.Context, v []string) (context.Context, error) { + return ctx, s.Send(v) +} ` var BidirectionalStreamingPrimitiveArrayServerStreamRecvCode = `// Recv reads instances of "[]int32" from the @@ -3014,6 +3721,14 @@ func (s *BidirectionalStreamingPrimitiveArrayMethodServerStream) Recv() ([]int32 } return body, nil } + +// RecvWithContext reads instances of "[]int32" from the +// "BidirectionalStreamingPrimitiveArrayMethod" endpoint websocket connection +// with context. +func (s *BidirectionalStreamingPrimitiveArrayMethodServerStream) RecvWithContext(ctx context.Context) ([]int32, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var BidirectionalStreamingPrimitiveArrayClientStreamSendCode = `// Send streams instances of "[]int32" to the @@ -3021,6 +3736,13 @@ var BidirectionalStreamingPrimitiveArrayClientStreamSendCode = `// Send streams func (s *BidirectionalStreamingPrimitiveArrayMethodClientStream) Send(v []int32) error { return s.conn.WriteJSON(v) } + +// SendWithContext streams instances of "[]int32" to the +// "BidirectionalStreamingPrimitiveArrayMethod" endpoint websocket connection +// with context. +func (s *BidirectionalStreamingPrimitiveArrayMethodClientStream) SendWithContext(ctx context.Context, v []int32) (context.Context, error) { + return ctx, s.Send(v) +} ` var BidirectionalStreamingPrimitiveArrayClientStreamRecvCode = `// Recv reads instances of "[]string" from the @@ -3040,6 +3762,14 @@ func (s *BidirectionalStreamingPrimitiveArrayMethodClientStream) Recv() ([]strin } return body, nil } + +// RecvWithContext reads instances of "[]string" from the +// "BidirectionalStreamingPrimitiveArrayMethod" endpoint websocket connection +// with context. +func (s *BidirectionalStreamingPrimitiveArrayMethodClientStream) RecvWithContext(ctx context.Context) ([]string, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var BidirectionalStreamingPrimitiveMapServerStreamSendCode = `// Send streams instances of "map[int]int" to the @@ -3066,6 +3796,13 @@ func (s *BidirectionalStreamingPrimitiveMapMethodServerStream) Send(v map[int]in res := v return s.conn.WriteJSON(res) } + +// SendWithContext streams instances of "map[int]int" to the +// "BidirectionalStreamingPrimitiveMapMethod" endpoint websocket connection +// with context. +func (s *BidirectionalStreamingPrimitiveMapMethodServerStream) SendWithContext(ctx context.Context, v map[int]int) (context.Context, error) { + return ctx, s.Send(v) +} ` var BidirectionalStreamingPrimitiveMapServerStreamRecvCode = `// Recv reads instances of "map[string]int32" from the @@ -3101,6 +3838,14 @@ func (s *BidirectionalStreamingPrimitiveMapMethodServerStream) Recv() (map[strin } return body, nil } + +// RecvWithContext reads instances of "map[string]int32" from the +// "BidirectionalStreamingPrimitiveMapMethod" endpoint websocket connection +// with context. +func (s *BidirectionalStreamingPrimitiveMapMethodServerStream) RecvWithContext(ctx context.Context) (map[string]int32, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var BidirectionalStreamingPrimitiveMapClientStreamSendCode = `// Send streams instances of "map[string]int32" to the @@ -3108,6 +3853,13 @@ var BidirectionalStreamingPrimitiveMapClientStreamSendCode = `// Send streams in func (s *BidirectionalStreamingPrimitiveMapMethodClientStream) Send(v map[string]int32) error { return s.conn.WriteJSON(v) } + +// SendWithContext streams instances of "map[string]int32" to the +// "BidirectionalStreamingPrimitiveMapMethod" endpoint websocket connection +// with context. +func (s *BidirectionalStreamingPrimitiveMapMethodClientStream) SendWithContext(ctx context.Context, v map[string]int32) (context.Context, error) { + return ctx, s.Send(v) +} ` var BidirectionalStreamingPrimitiveMapClientStreamRecvCode = `// Recv reads instances of "map[int]int" from the @@ -3127,6 +3879,14 @@ func (s *BidirectionalStreamingPrimitiveMapMethodClientStream) Recv() (map[int]i } return body, nil } + +// RecvWithContext reads instances of "map[int]int" from the +// "BidirectionalStreamingPrimitiveMapMethod" endpoint websocket connection +// with context. +func (s *BidirectionalStreamingPrimitiveMapMethodClientStream) RecvWithContext(ctx context.Context) (map[int]int, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var BidirectionalStreamingUserTypeArrayServerStreamSendCode = `// Send streams instances of @@ -3155,6 +3915,14 @@ func (s *BidirectionalStreamingUserTypeArrayMethodServerStream) Send(v []*bidire body := NewBidirectionalStreamingUserTypeArrayMethodResponseBody(res) return s.conn.WriteJSON(body) } + +// SendWithContext streams instances of +// "[]*bidirectionalstreamingusertypearrayservice.ResultType" to the +// "BidirectionalStreamingUserTypeArrayMethod" endpoint websocket connection +// with context. +func (s *BidirectionalStreamingUserTypeArrayMethodServerStream) SendWithContext(ctx context.Context, v []*bidirectionalstreamingusertypearrayservice.ResultType) (context.Context, error) { + return ctx, s.Send(v) +} ` var BidirectionalStreamingUserTypeArrayServerStreamRecvCode = `// Recv reads instances of @@ -3191,6 +3959,15 @@ func (s *BidirectionalStreamingUserTypeArrayMethodServerStream) Recv() ([]*bidir } return NewBidirectionalStreamingUserTypeArrayMethodArray(body), nil } + +// RecvWithContext reads instances of +// "[]*bidirectionalstreamingusertypearrayservice.RequestType" from the +// "BidirectionalStreamingUserTypeArrayMethod" endpoint websocket connection +// with context. +func (s *BidirectionalStreamingUserTypeArrayMethodServerStream) RecvWithContext(ctx context.Context) ([]*bidirectionalstreamingusertypearrayservice.RequestType, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var BidirectionalStreamingUserTypeArrayClientStreamSendCode = `// Send streams instances of @@ -3200,6 +3977,14 @@ func (s *BidirectionalStreamingUserTypeArrayMethodClientStream) Send(v []*bidire body := NewRequestType(v) return s.conn.WriteJSON(body) } + +// SendWithContext streams instances of +// "[]*bidirectionalstreamingusertypearrayservice.RequestType" to the +// "BidirectionalStreamingUserTypeArrayMethod" endpoint websocket connection +// with context. +func (s *BidirectionalStreamingUserTypeArrayMethodClientStream) SendWithContext(ctx context.Context, v []*bidirectionalstreamingusertypearrayservice.RequestType) (context.Context, error) { + return ctx, s.Send(v) +} ` var BidirectionalStreamingUserTypeArrayClientStreamRecvCode = `// Recv reads instances of @@ -3221,6 +4006,15 @@ func (s *BidirectionalStreamingUserTypeArrayMethodClientStream) Recv() ([]*bidir res := NewBidirectionalStreamingUserTypeArrayMethodResultTypeOK(body) return res, nil } + +// RecvWithContext reads instances of +// "[]*bidirectionalstreamingusertypearrayservice.ResultType" from the +// "BidirectionalStreamingUserTypeArrayMethod" endpoint websocket connection +// with context. +func (s *BidirectionalStreamingUserTypeArrayMethodClientStream) RecvWithContext(ctx context.Context) ([]*bidirectionalstreamingusertypearrayservice.ResultType, context.Context, error) { + res, err := s.Recv() + return res, ctx, err +} ` var BidirectionalStreamingUserTypeMapServerStreamSendCode = `// Send streams instances of @@ -3250,13 +4044,12 @@ func (s *BidirectionalStreamingUserTypeMapMethodServerStream) Send(v map[string] return s.conn.WriteJSON(body) } -// RecvWithContext reads instances of -// "map[string]*bidirectionalstreamingusertypemapservice.RequestType" from the +// SendWithContext streams instances of +// "map[string]*bidirectionalstreamingusertypemapservice.ResultType" to the // "BidirectionalStreamingUserTypeMapMethod" endpoint websocket connection with // context. -func (s *BidirectionalStreamingUserTypeMapMethodServerStream) RecvWithContext(ctx context.Context) (map[string]*bidirectionalstreamingusertypemapservice.RequestType, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *BidirectionalStreamingUserTypeMapMethodServerStream) SendWithContext(ctx context.Context, v map[string]*bidirectionalstreamingusertypemapservice.ResultType) (context.Context, error) { + return ctx, s.Send(v) } ` diff --git a/http/codegen/websocket.go b/http/codegen/websocket.go index 1c60fa1624..0439b81622 100644 --- a/http/codegen/websocket.go +++ b/http/codegen/websocket.go @@ -191,7 +191,7 @@ func initWebSocketData(ed *EndpointData, e *expr.HTTPEndpointExpr, sd *ServiceDa svrSendDesc = fmt.Sprintf("%s streams instances of %q to the %q endpoint websocket connection and closes the connection.", md.ServerStream.SendName, svrSendTypeName, md.Name) svrSendWithContextDesc = fmt.Sprintf("%s streams instances of %q to the %q endpoint websocket connection with context and closes the connection.", md.ServerStream.SendWithContextName, svrSendTypeName, md.Name) cliRecvDesc = fmt.Sprintf("%s stops sending messages to the %q endpoint websocket connection and reads instances of %q from the connection.", md.ClientStream.RecvName, md.Name, svrSendTypeName) - cliRecvWithContextDesc = fmt.Sprintf("%s stops sending messages to the %q endpoint websocket connection with context and reads instances of %q from the connection.", md.ClientStream.RecvWithContextName, md.Name, svrSendTypeName) + cliRecvWithContextDesc = fmt.Sprintf("%s stops sending messages to the %q endpoint websocket connection and reads instances of %q from the connection with context.", md.ClientStream.RecvWithContextName, md.Name, svrSendTypeName) } svrRecvDesc = fmt.Sprintf("%s reads instances of %q from the %q endpoint websocket connection.", md.ServerStream.RecvName, svrRecvTypeName, md.Name) svrRecvWithContextDesc = fmt.Sprintf("%s reads instances of %q from the %q endpoint websocket connection with context.", md.ServerStream.RecvWithContextName, svrRecvTypeName, md.Name) From 9c35929b9529d2d0c24de994c139b80769be8057 Mon Sep 17 00:00:00 2001 From: Douglas Thrift Date: Fri, 31 Jan 2025 17:18:47 -0800 Subject: [PATCH 12/23] Add more tests for streaming interceptor service codegen --- codegen/service/interceptors_test.go | 4 +- .../client_interceptor_wrappers.go.tpl | 22 +-- .../server_interceptor_wrappers.go.tpl | 22 +-- ...ming-payload_client_interceptors.go.golden | 14 ++ ...ing-payload_interceptor_wrappers.go.golden | 132 ++++++++++++++++++ ...ing-payload_service_interceptors.go.golden | 74 ++++++++++ ...aming-result_client_interceptors.go.golden | 14 ++ ...ming-result_interceptor_wrappers.go.golden | 117 ++++++++++++++++ ...ming-result_service_interceptors.go.golden | 51 +++++++ ...interceptors_client_interceptors.go.golden | 14 ++ ...nterceptors_interceptor_wrappers.go.golden | 100 ++++++++++++- codegen/service/testdata/interceptors_dsls.go | 43 ++++++ pkg/interceptor.go | 4 + 13 files changed, 592 insertions(+), 19 deletions(-) create mode 100644 codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_client_interceptors.go.golden create mode 100644 codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_interceptor_wrappers.go.golden create mode 100644 codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_service_interceptors.go.golden create mode 100644 codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_client_interceptors.go.golden create mode 100644 codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_interceptor_wrappers.go.golden create mode 100644 codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_service_interceptors.go.golden create mode 100644 codegen/service/testdata/interceptors/streaming-interceptors_client_interceptors.go.golden diff --git a/codegen/service/interceptors_test.go b/codegen/service/interceptors_test.go index 6fa7c3ab14..e20c1cc79f 100644 --- a/codegen/service/interceptors_test.go +++ b/codegen/service/interceptors_test.go @@ -42,7 +42,9 @@ func TestInterceptors(t *testing.T) { {"interceptor-with-read-result", testdata.InterceptorWithReadResultDSL, 3}, {"interceptor-with-write-result", testdata.InterceptorWithWriteResultDSL, 3}, {"interceptor-with-read-write-result", testdata.InterceptorWithReadWriteResultDSL, 3}, - {"streaming-interceptors", testdata.StreamingInterceptorsDSL, 2}, + {"streaming-interceptors", testdata.StreamingInterceptorsDSL, 3}, + {"streaming-interceptors-with-read-payload-and-read-streaming-payload", testdata.StreamingInterceptorsWithReadPayloadAndReadStreamingPayloadDSL, 3}, + {"streaming-interceptors-with-read-streaming-result", testdata.StreamingInterceptorsWithReadStreamingResultDSL, 3}, {"streaming-interceptors-with-read-payload", testdata.StreamingInterceptorsWithReadPayloadDSL, 2}, {"streaming-interceptors-with-read-result", testdata.StreamingInterceptorsWithReadResultDSL, 2}, } diff --git a/codegen/service/templates/client_interceptor_wrappers.go.tpl b/codegen/service/templates/client_interceptor_wrappers.go.tpl index 8f7ef06bfd..1e7310ec63 100644 --- a/codegen/service/templates/client_interceptor_wrappers.go.tpl +++ b/codegen/service/templates/client_interceptor_wrappers.go.tpl @@ -26,7 +26,8 @@ func wrapClient{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i sendWithContext: func(ctx context.Context, req {{ .ClientStream.SendTypeRef }}) (context.Context, error) { info := &{{ $interceptor.Name }}Info{ Service: "{{ $.Service }}", - Method: "{{ .MethodName }}.{{ .ClientStream.SendWithContextName }}", + Method: "{{ .MethodName }}", + Send: true, RawPayload: req, } var rCtx context.Context @@ -42,7 +43,8 @@ func wrapClient{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i recvWithContext: func(ctx context.Context) ({{ .ClientStream.RecvTypeRef }}, context.Context, error) { info := &{{ $interceptor.Name }}Info{ Service: "{{ $.Service }}", - Method: "{{ .MethodName }}.{{ .ClientStream.RecvWithContextName }}", + Method: "{{ .MethodName }}", + Recv: true, RawPayload: req, } var rCtx context.Context @@ -76,11 +78,15 @@ func wrapClient{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i {{ comment (printf "wrapped%s is a client interceptor wrapper for the %s stream." .Interface .Interface) }} type wrapped{{ .Interface }} struct { ctx context.Context + {{- if ne .SendTypeRef "" }} sendWithContext func(context.Context, {{ .SendTypeRef }}) (context.Context, error) + {{- end }} + {{- if ne .RecvTypeRef "" }} recvWithContext func(context.Context) ({{ .RecvTypeRef }}, context.Context, error) + {{- end }} stream {{ .Interface }} } -{{- if ne .SendWithContextName "" }} + {{- if ne .SendTypeRef "" }} {{ comment (printf "%s streams instances of \"%s\" after executing the applied interceptor." .SendName .Interface) }} func (w *wrapped{{ .Interface }}) {{ .SendName }}(v {{ .SendTypeRef }}) error { @@ -95,8 +101,8 @@ func (w *wrapped{{ .Interface }}) {{ .SendWithContextName }}(ctx context.Context } return w.sendWithContext(ctx, v) } -{{- end }} -{{- if ne .RecvWithContextName "" }} + {{- end }} + {{- if ne .RecvTypeRef "" }} {{ comment (printf "%s reads instances of \"%s\" from the stream after executing the applied interceptor." .RecvName .Interface) }} func (w *wrapped{{ .Interface }}) {{ .RecvName }}() ({{ .RecvTypeRef }}, error) { @@ -111,12 +117,12 @@ func (w *wrapped{{ .Interface }}) {{ .RecvWithContextName }}(ctx context.Context } return w.recvWithContext(ctx) } -{{- end }} -{{- if .MustClose }} + {{- end }} + {{- if .MustClose }} // Close closes the stream. func (w *wrapped{{ .Interface }}) Close() error { return w.stream.Close() } -{{- end }} + {{- end }} {{- end }} diff --git a/codegen/service/templates/server_interceptor_wrappers.go.tpl b/codegen/service/templates/server_interceptor_wrappers.go.tpl index 2e34f3b2e8..b5a3fc7a62 100644 --- a/codegen/service/templates/server_interceptor_wrappers.go.tpl +++ b/codegen/service/templates/server_interceptor_wrappers.go.tpl @@ -26,7 +26,8 @@ func wrap{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i Serve sendWithContext: func(ctx context.Context, req {{ .ServerStream.SendTypeRef }}) (context.Context, error) { info := &{{ $interceptor.Name }}Info{ Service: "{{ $.Service }}", - Method: "{{ .MethodName }}.{{ .ServerStream.SendWithContextName }}", + Method: "{{ .MethodName }}", + Send: true, RawPayload: req, } var rCtx context.Context @@ -42,7 +43,8 @@ func wrap{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i Serve recvWithContext: func(ctx context.Context) ({{ .ServerStream.RecvTypeRef }}, context.Context, error) { info := &{{ $interceptor.Name }}Info{ Service: "{{ $.Service }}", - Method: "{{ .MethodName }}.{{ .ServerStream.RecvWithContextName }}", + Method: "{{ .MethodName }}", + Recv: true, RawPayload: req, } var rCtx context.Context @@ -76,11 +78,15 @@ func wrap{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i Serve {{ comment (printf "wrapped%s is a server interceptor wrapper for the %s stream." .Interface .Interface) }} type wrapped{{ .Interface }} struct { ctx context.Context + {{- if ne .SendTypeRef "" }} sendWithContext func(context.Context, {{ .SendTypeRef }}) (context.Context, error) + {{- end }} + {{- if ne .RecvTypeRef "" }} recvWithContext func(context.Context) ({{ .RecvTypeRef }}, context.Context, error) + {{- end }} stream {{ .Interface }} } -{{- if ne .SendWithContextName "" }} + {{- if ne .SendTypeRef "" }} {{ comment (printf "%s streams instances of \"%s\" after executing the applied interceptor." .SendName .Interface) }} func (w *wrapped{{ .Interface }}) {{ .SendName }}(v {{ .SendTypeRef }}) error { @@ -95,8 +101,8 @@ func (w *wrapped{{ .Interface }}) {{ .SendWithContextName }}(ctx context.Context } return w.sendWithContext(ctx, v) } -{{- end }} -{{- if ne .RecvWithContextName "" }} + {{- end }} + {{- if ne .RecvTypeRef "" }} {{ comment (printf "%s reads instances of \"%s\" from the stream after executing the applied interceptor." .RecvName .Interface) }} func (w *wrapped{{ .Interface }}) {{ .RecvName }}() ({{ .RecvTypeRef }}, error) { @@ -111,12 +117,12 @@ func (w *wrapped{{ .Interface }}) {{ .RecvWithContextName }}(ctx context.Context } return w.recvWithContext(ctx) } -{{- end }} -{{- if .MustClose }} + {{- end }} + {{- if .MustClose }} // Close closes the stream. func (w *wrapped{{ .Interface }}) Close() error { return w.stream.Close() } -{{- end }} + {{- end }} {{- end }} diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_client_interceptors.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_client_interceptors.go.golden new file mode 100644 index 0000000000..3790fd8cde --- /dev/null +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_client_interceptors.go.golden @@ -0,0 +1,14 @@ +// ClientInterceptors defines the interface for all client-side interceptors. +// Client interceptors execute after the payload is encoded and before the request +// is sent to the server. The implementation is responsible for calling next to +// complete the request. +type ClientInterceptors interface { + Logging(ctx context.Context, info *LoggingInfo, next goa.Endpoint) (any, error) +} + +// WrapMethodClientEndpoint wraps the Method endpoint with the client +// interceptors defined in the design. +func WrapMethodClientEndpoint(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { + endpoint = wrapClientMethodlogging(endpoint, i) + return endpoint +} diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_interceptor_wrappers.go.golden new file mode 100644 index 0000000000..79a02f5c63 --- /dev/null +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_interceptor_wrappers.go.golden @@ -0,0 +1,132 @@ + + +// wrapLoggingMethod applies the logging server interceptor to endpoints. +func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { + return func(ctx context.Context, req any) (any, error) { + info := &LoggingInfo{ + Service: "StreamingInterceptorsWithReadPayloadAndReadStreamingPayload", + Method: "Method", + RawPayload: req, + } + res, err := i.Logging(ctx, info, endpoint) + if err != nil { + return nil, err + } + stream := res.(MethodServerStream) + return &wrappedMethodServerStream{ + ctx: ctx, + recvWithContext: func(ctx context.Context) (*MethodStreamingPayload, context.Context, error) { + info := &LoggingInfo{ + Service: "StreamingInterceptorsWithReadPayloadAndReadStreamingPayload", + Method: "Method", + Recv: true, + RawPayload: req, + } + var rCtx context.Context + res, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, error) { + var ( + res *MethodStreamingPayload + err error + ) + res, rCtx, err = stream.RecvWithContext(ctx) + return res, err + }) + return res.(*MethodStreamingPayload), rCtx, err + }, + stream: stream, + }, nil + } +} + +// wrappedMethodServerStream is a server interceptor wrapper for the +// MethodServerStream stream. +type wrappedMethodServerStream struct { + ctx context.Context + recvWithContext func(context.Context) (*MethodStreamingPayload, context.Context, error) + stream MethodServerStream +} + +// Recv reads instances of "MethodServerStream" from the stream after executing +// the applied interceptor. +func (w *wrappedMethodServerStream) Recv() (*MethodStreamingPayload, error) { + res, _, err := w.RecvWithContext(w.ctx) + return res, err +} + +// RecvWithContext reads instances of "MethodServerStream" from the stream +// after executing the applied interceptor with context. +func (w *wrappedMethodServerStream) RecvWithContext(ctx context.Context) (*MethodStreamingPayload, context.Context, error) { + if w.recvWithContext == nil { + return w.stream.RecvWithContext(ctx) + } + return w.recvWithContext(ctx) +} + +// Close closes the stream. +func (w *wrappedMethodServerStream) Close() error { + return w.stream.Close() +} + +// wrapClientLoggingMethod applies the logging client interceptor to endpoints. +func wrapClientMethodLogging(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { + return func(ctx context.Context, req any) (any, error) { + info := &LoggingInfo{ + Service: "StreamingInterceptorsWithReadPayloadAndReadStreamingPayload", + Method: "Method", + RawPayload: req, + } + res, err := i.Logging(ctx, info, endpoint) + if err != nil { + return nil, err + } + stream := res.(MethodClientStream) + return &wrappedMethodClientStream{ + ctx: ctx, + sendWithContext: func(ctx context.Context, req *MethodStreamingPayload) (context.Context, error) { + info := &LoggingInfo{ + Service: "StreamingInterceptorsWithReadPayloadAndReadStreamingPayload", + Method: "Method", + Send: true, + RawPayload: req, + } + var rCtx context.Context + _, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, error) { + var err error + rCtx, err = stream.SendWithContext(ctx, req.(*MethodStreamingPayload)) + return nil, err + }) + return rCtx, err + }, + stream: stream, + }, nil + } +} + +// wrappedMethodClientStream is a client interceptor wrapper for the +// MethodClientStream stream. +type wrappedMethodClientStream struct { + ctx context.Context + sendWithContext func(context.Context, *MethodStreamingPayload) (context.Context, error) + stream MethodClientStream +} + +// Send streams instances of "MethodClientStream" after executing the applied +// interceptor. +func (w *wrappedMethodClientStream) Send(v *MethodStreamingPayload) error { + _, err := w.SendWithContext(w.ctx, v) + return err +} + +// SendWithContext streams instances of "MethodClientStream" after executing +// the applied interceptor with context. +func (w *wrappedMethodClientStream) SendWithContext(ctx context.Context, v *MethodStreamingPayload) (context.Context, error) { + if w.sendWithContext == nil { + return w.stream.SendWithContext(ctx, v) + } + return w.sendWithContext(ctx, v) +} + +// Close closes the stream. +func (w *wrappedMethodClientStream) Close() error { + return w.stream.Close() +} diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_service_interceptors.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_service_interceptors.go.golden new file mode 100644 index 0000000000..a977525534 --- /dev/null +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_service_interceptors.go.golden @@ -0,0 +1,74 @@ +// ServerInterceptors defines the interface for all server-side interceptors. +// Server interceptors execute after the request is decoded and before the +// payload is sent to the service. The implementation is responsible for calling +// next to complete the request. +type ServerInterceptors interface { + Logging(ctx context.Context, info *LoggingInfo, next goa.Endpoint) (any, error) +} + +// Access interfaces for interceptor payloads and results +type ( + // LoggingInfo provides metadata about the current interception. + // It includes service name, method name, and access to the endpoint. + LoggingInfo goa.InterceptorInfo + + // LoggingPayload provides type-safe access to the method payload. + // It allows reading and writing specific fields of the payload as defined + // in the design. + LoggingPayload interface { + Chunk() string + } + + // LoggingStreamingPayload provides type-safe access to the method streaming payload. + // It allows reading and writing specific fields of the streaming payload as defined + // in the design. + LoggingStreamingPayload interface { + Chunk() string + } +) + +// Private implementation types +type ( + loggingMethodPayload struct { + payload *MethodPayload + } + loggingMethodStreamingPayload struct { + payload *MethodStreamingPayload + } +) + +// WrapMethodEndpoint wraps the Method endpoint with the server-side +// interceptors defined in the design. +func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { + endpoint = wrapMethodlogging(endpoint, i) + return endpoint +} + +// Public accessor methods for Info types + +// Payload returns a type-safe accessor for the method payload. +func (info *LoggingInfo) Payload() LoggingPayload { + return &loggingMethodPayload{payload: info.RawPayload.(*MethodPayload)} +} + +// StreamingPayload returns a type-safe accessor for the method streaming payload. +func (info *LoggingInfo) StreamingPayload() LoggingStreamingPayload { + return &loggingMethodStreamingPayload{payload: info.RawPayload.(*MethodStreamingPayload)} +} + +// Private implementation methods + +func (p *loggingMethodPayload) Chunk() string { + if p.payload.Chunk == nil { + var zero string + return zero + } + return *p.payload.Chunk +} +func (p *loggingMethodStreamingPayload) Chunk() string { + if p.payload.Chunk == nil { + var zero string + return zero + } + return *p.payload.Chunk +} diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_client_interceptors.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_client_interceptors.go.golden new file mode 100644 index 0000000000..3790fd8cde --- /dev/null +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_client_interceptors.go.golden @@ -0,0 +1,14 @@ +// ClientInterceptors defines the interface for all client-side interceptors. +// Client interceptors execute after the payload is encoded and before the request +// is sent to the server. The implementation is responsible for calling next to +// complete the request. +type ClientInterceptors interface { + Logging(ctx context.Context, info *LoggingInfo, next goa.Endpoint) (any, error) +} + +// WrapMethodClientEndpoint wraps the Method endpoint with the client +// interceptors defined in the design. +func WrapMethodClientEndpoint(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { + endpoint = wrapClientMethodlogging(endpoint, i) + return endpoint +} diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_interceptor_wrappers.go.golden new file mode 100644 index 0000000000..4ae7e348d1 --- /dev/null +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_interceptor_wrappers.go.golden @@ -0,0 +1,117 @@ + + +// wrapLoggingMethod applies the logging server interceptor to endpoints. +func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { + return func(ctx context.Context, req any) (any, error) { + res, err := endpoint(ctx, req) + if err != nil { + return nil, err + } + stream := res.(MethodServerStream) + return &wrappedMethodServerStream{ + ctx: ctx, + sendWithContext: func(ctx context.Context, req *MethodResult) (context.Context, error) { + info := &LoggingInfo{ + Service: "StreamingInterceptorsWithReadStreamingResult", + Method: "Method", + Send: true, + RawPayload: req, + } + var rCtx context.Context + _, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, error) { + var err error + rCtx, err = stream.SendWithContext(ctx, req.(*MethodResult)) + return nil, err + }) + return rCtx, err + }, + stream: stream, + }, nil + } +} + +// wrappedMethodServerStream is a server interceptor wrapper for the +// MethodServerStream stream. +type wrappedMethodServerStream struct { + ctx context.Context + sendWithContext func(context.Context, *MethodResult) (context.Context, error) + stream MethodServerStream +} + +// Send streams instances of "MethodServerStream" after executing the applied +// interceptor. +func (w *wrappedMethodServerStream) Send(v *MethodResult) error { + _, err := w.SendWithContext(w.ctx, v) + return err +} + +// SendWithContext streams instances of "MethodServerStream" after executing +// the applied interceptor with context. +func (w *wrappedMethodServerStream) SendWithContext(ctx context.Context, v *MethodResult) (context.Context, error) { + if w.sendWithContext == nil { + return w.stream.SendWithContext(ctx, v) + } + return w.sendWithContext(ctx, v) +} + +// Close closes the stream. +func (w *wrappedMethodServerStream) Close() error { + return w.stream.Close() +} + +// wrapClientLoggingMethod applies the logging client interceptor to endpoints. +func wrapClientMethodLogging(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { + return func(ctx context.Context, req any) (any, error) { + res, err := endpoint(ctx, req) + if err != nil { + return nil, err + } + stream := res.(MethodClientStream) + return &wrappedMethodClientStream{ + ctx: ctx, + recvWithContext: func(ctx context.Context) (*MethodResult, context.Context, error) { + info := &LoggingInfo{ + Service: "StreamingInterceptorsWithReadStreamingResult", + Method: "Method", + Recv: true, + RawPayload: req, + } + var rCtx context.Context + res, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, error) { + var ( + res *MethodResult + err error + ) + res, rCtx, err = stream.RecvWithContext(ctx) + return res, err + }) + return res.(*MethodResult), rCtx, err + }, + stream: stream, + }, nil + } +} + +// wrappedMethodClientStream is a client interceptor wrapper for the +// MethodClientStream stream. +type wrappedMethodClientStream struct { + ctx context.Context + recvWithContext func(context.Context) (*MethodResult, context.Context, error) + stream MethodClientStream +} + +// Recv reads instances of "MethodClientStream" from the stream after executing +// the applied interceptor. +func (w *wrappedMethodClientStream) Recv() (*MethodResult, error) { + res, _, err := w.RecvWithContext(w.ctx) + return res, err +} + +// RecvWithContext reads instances of "MethodClientStream" from the stream +// after executing the applied interceptor with context. +func (w *wrappedMethodClientStream) RecvWithContext(ctx context.Context) (*MethodResult, context.Context, error) { + if w.recvWithContext == nil { + return w.stream.RecvWithContext(ctx) + } + return w.recvWithContext(ctx) +} diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_service_interceptors.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_service_interceptors.go.golden new file mode 100644 index 0000000000..b65b74dc89 --- /dev/null +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_service_interceptors.go.golden @@ -0,0 +1,51 @@ +// ServerInterceptors defines the interface for all server-side interceptors. +// Server interceptors execute after the request is decoded and before the +// payload is sent to the service. The implementation is responsible for calling +// next to complete the request. +type ServerInterceptors interface { + Logging(ctx context.Context, info *LoggingInfo, next goa.Endpoint) (any, error) +} + +// Access interfaces for interceptor payloads and results +type ( + // LoggingInfo provides metadata about the current interception. + // It includes service name, method name, and access to the endpoint. + LoggingInfo goa.InterceptorInfo + + // LoggingStreamingResult provides type-safe access to the method streaming result. + // It allows reading and writing specific fields of the streaming result as defined + // in the design. + LoggingStreamingResult interface { + Data() string + } +) + +// Private implementation types +type ( + loggingMethodStreamingResult struct { + result *MethodResult + } +) + +// WrapMethodEndpoint wraps the Method endpoint with the server-side +// interceptors defined in the design. +func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { + endpoint = wrapMethodlogging(endpoint, i) + return endpoint +} + +// Public accessor methods for Info types +// StreamingResult returns a type-safe accessor for the method streaming result. +func (info *LoggingInfo) StreamingResult(res any) LoggingStreamingResult { + return &loggingMethodStreamingResult{result: res.(*MethodResult)} +} + +// Private implementation methods + +func (r *loggingMethodStreamingResult) Data() string { + if r.result.Data == nil { + var zero string + return zero + } + return *r.result.Data +} diff --git a/codegen/service/testdata/interceptors/streaming-interceptors_client_interceptors.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors_client_interceptors.go.golden new file mode 100644 index 0000000000..3790fd8cde --- /dev/null +++ b/codegen/service/testdata/interceptors/streaming-interceptors_client_interceptors.go.golden @@ -0,0 +1,14 @@ +// ClientInterceptors defines the interface for all client-side interceptors. +// Client interceptors execute after the payload is encoded and before the request +// is sent to the server. The implementation is responsible for calling next to +// complete the request. +type ClientInterceptors interface { + Logging(ctx context.Context, info *LoggingInfo, next goa.Endpoint) (any, error) +} + +// WrapMethodClientEndpoint wraps the Method endpoint with the client +// interceptors defined in the design. +func WrapMethodClientEndpoint(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { + endpoint = wrapClientMethodlogging(endpoint, i) + return endpoint +} diff --git a/codegen/service/testdata/interceptors/streaming-interceptors_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors_interceptor_wrappers.go.golden index 1bece78f85..07ae5e3cfe 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors_interceptor_wrappers.go.golden @@ -13,7 +13,8 @@ func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint sendWithContext: func(ctx context.Context, req *MethodResult) (context.Context, error) { info := &LoggingInfo{ Service: "StreamingInterceptors", - Method: "Method.SendWithContext", + Method: "Method", + Send: true, RawPayload: req, } var rCtx context.Context @@ -27,7 +28,8 @@ func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint recvWithContext: func(ctx context.Context) (*MethodStreamingPayload, context.Context, error) { info := &LoggingInfo{ Service: "StreamingInterceptors", - Method: "Method.RecvWithContext", + Method: "Method", + Recv: true, RawPayload: req, } var rCtx context.Context @@ -91,3 +93,97 @@ func (w *wrappedMethodServerStream) RecvWithContext(ctx context.Context) (*Metho func (w *wrappedMethodServerStream) Close() error { return w.stream.Close() } + +// wrapClientLoggingMethod applies the logging client interceptor to endpoints. +func wrapClientMethodLogging(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { + return func(ctx context.Context, req any) (any, error) { + res, err := endpoint(ctx, req) + if err != nil { + return nil, err + } + stream := res.(MethodClientStream) + return &wrappedMethodClientStream{ + ctx: ctx, + sendWithContext: func(ctx context.Context, req *MethodStreamingPayload) (context.Context, error) { + info := &LoggingInfo{ + Service: "StreamingInterceptors", + Method: "Method", + Send: true, + RawPayload: req, + } + var rCtx context.Context + _, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, error) { + var err error + rCtx, err = stream.SendWithContext(ctx, req.(*MethodStreamingPayload)) + return nil, err + }) + return rCtx, err + }, + recvWithContext: func(ctx context.Context) (*MethodResult, context.Context, error) { + info := &LoggingInfo{ + Service: "StreamingInterceptors", + Method: "Method", + Recv: true, + RawPayload: req, + } + var rCtx context.Context + res, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, error) { + var ( + res *MethodResult + err error + ) + res, rCtx, err = stream.RecvWithContext(ctx) + return res, err + }) + return res.(*MethodResult), rCtx, err + }, + stream: stream, + }, nil + } +} + +// wrappedMethodClientStream is a client interceptor wrapper for the +// MethodClientStream stream. +type wrappedMethodClientStream struct { + ctx context.Context + sendWithContext func(context.Context, *MethodStreamingPayload) (context.Context, error) + recvWithContext func(context.Context) (*MethodResult, context.Context, error) + stream MethodClientStream +} + +// Send streams instances of "MethodClientStream" after executing the applied +// interceptor. +func (w *wrappedMethodClientStream) Send(v *MethodStreamingPayload) error { + _, err := w.SendWithContext(w.ctx, v) + return err +} + +// SendWithContext streams instances of "MethodClientStream" after executing +// the applied interceptor with context. +func (w *wrappedMethodClientStream) SendWithContext(ctx context.Context, v *MethodStreamingPayload) (context.Context, error) { + if w.sendWithContext == nil { + return w.stream.SendWithContext(ctx, v) + } + return w.sendWithContext(ctx, v) +} + +// Recv reads instances of "MethodClientStream" from the stream after executing +// the applied interceptor. +func (w *wrappedMethodClientStream) Recv() (*MethodResult, error) { + res, _, err := w.RecvWithContext(w.ctx) + return res, err +} + +// RecvWithContext reads instances of "MethodClientStream" from the stream +// after executing the applied interceptor with context. +func (w *wrappedMethodClientStream) RecvWithContext(ctx context.Context) (*MethodResult, context.Context, error) { + if w.recvWithContext == nil { + return w.stream.RecvWithContext(ctx) + } + return w.recvWithContext(ctx) +} + +// Close closes the stream. +func (w *wrappedMethodClientStream) Close() error { + return w.stream.Close() +} diff --git a/codegen/service/testdata/interceptors_dsls.go b/codegen/service/testdata/interceptors_dsls.go index 3b1d8ba7a6..d901825e2c 100644 --- a/codegen/service/testdata/interceptors_dsls.go +++ b/codegen/service/testdata/interceptors_dsls.go @@ -230,6 +230,7 @@ var StreamingInterceptorsDSL = func() { }) Service("StreamingInterceptors", func() { ServerInterceptor("logging") + ClientInterceptor("logging") Method("Method", func() { StreamingPayload(func() { Attribute("chunk", String) @@ -242,6 +243,48 @@ var StreamingInterceptorsDSL = func() { }) } +var StreamingInterceptorsWithReadPayloadAndReadStreamingPayloadDSL = func() { + Interceptor("logging", func() { + ReadPayload(func() { + Attribute("chunk") + }) + ReadStreamingPayload(func() { + Attribute("chunk") + }) + }) + Service("StreamingInterceptorsWithReadPayloadAndReadStreamingPayload", func() { + ServerInterceptor("logging") + ClientInterceptor("logging") + Method("Method", func() { + Payload(func() { + Field(1, "chunk", String) + }) + StreamingPayload(func() { + Field(1, "chunk", String) + }) + GRPC(func() {}) + }) + }) +} + +var StreamingInterceptorsWithReadStreamingResultDSL = func() { + Interceptor("logging", func() { + ReadStreamingResult(func() { + Attribute("data") + }) + }) + Service("StreamingInterceptorsWithReadStreamingResult", func() { + ServerInterceptor("logging") + ClientInterceptor("logging") + Method("Method", func() { + StreamingResult(func() { + Field(1, "data", String) + }) + GRPC(func() {}) + }) + }) +} + var StreamingInterceptorsWithReadPayloadDSL = func() { Interceptor("logging", func() { ReadPayload(func() { diff --git a/pkg/interceptor.go b/pkg/interceptor.go index 269c4e9844..0d2b3703b7 100644 --- a/pkg/interceptor.go +++ b/pkg/interceptor.go @@ -9,6 +9,10 @@ type ( Service string // Name of method handling request Method string + // Send is true if the request is a streaming Send + Send bool + // Recv is true if the request is a streaming Recv + Recv bool // Payload of request RawPayload any } From cc0e16ac91425063eb4f587e2bab549926d2e011 Mon Sep 17 00:00:00 2001 From: Douglas Thrift Date: Fri, 31 Jan 2025 17:46:45 -0800 Subject: [PATCH 13/23] Fix bug where the CLI ParseEndpoint method would try to wrap every method with interceptors even if they do not apply --- codegen/cli/cli.go | 19 +++++++++++++++---- grpc/codegen/client_cli.go | 2 +- grpc/codegen/templates/parse_endpoint.go.tpl | 7 +++---- http/codegen/client_cli.go | 4 ++-- http/codegen/templates/parse_endpoint.go.tpl | 5 ++--- 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/codegen/cli/cli.go b/codegen/cli/cli.go index 6c852cc5e8..7e3c461acf 100644 --- a/codegen/cli/cli.go +++ b/codegen/cli/cli.go @@ -58,6 +58,8 @@ type ( Conversion string // Example is a valid command invocation, starting with the command name. Example string + // Interceptors contains the data for client interceptors if any apply to the endpoint method. + Interceptors *InterceptorData } // InterceptorData contains the data needed to generate interceptor code. @@ -181,18 +183,19 @@ func BuildCommandData(data *service.Data) *CommandData { // BuildSubcommandData builds the data needed by CLI code generators to render // the CLI parsing of the service sub-command. -func BuildSubcommandData(svcName string, m *service.MethodData, buildFunction *BuildFunctionData, flags []*FlagData) *SubcommandData { +func BuildSubcommandData(data *service.Data, m *service.MethodData, buildFunction *BuildFunctionData, flags []*FlagData) *SubcommandData { var ( name string fullName string description string - conversion string + conversion string + interceptors *InterceptorData ) { en := m.Name name = codegen.KebabCase(en) - fullName = goifyTerms(svcName, en) + fullName = goifyTerms(data.Name, en) description = m.Description if description == "" { description = fmt.Sprintf("Make request to the %q endpoint", m.Name) @@ -227,6 +230,13 @@ func BuildSubcommandData(svcName string, m *service.MethodData, buildFunction *B conversion += "\n}" } } + + if len(m.ClientInterceptors) > 0 { + interceptors = &InterceptorData{ + VarName: "inter", + PkgName: data.PkgName, + } + } } sub := &SubcommandData{ Name: name, @@ -236,8 +246,9 @@ func BuildSubcommandData(svcName string, m *service.MethodData, buildFunction *B MethodVarName: m.VarName, BuildFunction: buildFunction, Conversion: conversion, + Interceptors: interceptors, } - generateExample(sub, svcName) + generateExample(sub, data.Name) return sub } diff --git a/grpc/codegen/client_cli.go b/grpc/codegen/client_cli.go index 1135455c3c..9f7f9d8f92 100644 --- a/grpc/codegen/client_cli.go +++ b/grpc/codegen/client_cli.go @@ -28,7 +28,7 @@ func ClientCLIFiles(genpkg string, root *expr.RootExpr) []*codegen.File { command := cli.BuildCommandData(sd.Service) for _, e := range sd.Endpoints { flags, buildFunction := buildFlags(e) - subcmd := cli.BuildSubcommandData(sd.Service.Name, e.Method, buildFunction, flags) + subcmd := cli.BuildSubcommandData(sd.Service, e.Method, buildFunction, flags) command.Subcommands = append(command.Subcommands, subcmd) } command.Example = command.Subcommands[0].Example diff --git a/grpc/codegen/templates/parse_endpoint.go.tpl b/grpc/codegen/templates/parse_endpoint.go.tpl index 43f98aec9f..538dad4768 100644 --- a/grpc/codegen/templates/parse_endpoint.go.tpl +++ b/grpc/codegen/templates/parse_endpoint.go.tpl @@ -22,12 +22,11 @@ func ParseEndpoint( c := {{ .PkgName }}.NewClient(cc, opts...) switch epn { {{- $pkgName := .PkgName }} - {{- $interceptors := .Interceptors }} {{ range .Subcommands }} case "{{ .Name }}": endpoint = c.{{ .MethodVarName }}() - {{- if $interceptors }} - endpoint = {{ $interceptors.PkgName }}.Wrap{{ .MethodVarName }}ClientEndpoint(endpoint, {{ $interceptors.VarName }}) + {{- if .Interceptors }} + endpoint = {{ .Interceptors.PkgName }}.Wrap{{ .MethodVarName }}ClientEndpoint(endpoint, {{ .Interceptors.VarName }}) {{- end }} {{- if .BuildFunction }} data, err = {{ $pkgName}}.{{ .BuildFunction.Name }}({{ range .BuildFunction.ActualParams }}*{{ . }}Flag, {{ end }}) @@ -44,4 +43,4 @@ func ParseEndpoint( } return endpoint, data, nil -} \ No newline at end of file +} diff --git a/http/codegen/client_cli.go b/http/codegen/client_cli.go index 9cf67f2888..da4fa238a8 100644 --- a/http/codegen/client_cli.go +++ b/http/codegen/client_cli.go @@ -24,7 +24,7 @@ type subcommandData struct { // MultipartFuncName is the name of the function used to render a multipart // request encoder. MultipartFuncName string - // MultipartFuncName is the name of the variabl used to render a multipart + // MultipartFuncName is the name of the variable used to render a multipart // request encoder. MultipartVarName string // StreamFlag is the flag used to identify the file to be streamed when @@ -87,7 +87,7 @@ func buildSubcommandData(sd *ServiceData, e *EndpointData) *subcommandData { flags, buildFunction := buildFlags(sd, e) sub := &subcommandData{ - SubcommandData: cli.BuildSubcommandData(sd.Service.Name, e.Method, buildFunction, flags), + SubcommandData: cli.BuildSubcommandData(sd.Service, e.Method, buildFunction, flags), } if e.MultipartRequestEncoder != nil { sub.MultipartVarName = e.MultipartRequestEncoder.VarName diff --git a/http/codegen/templates/parse_endpoint.go.tpl b/http/codegen/templates/parse_endpoint.go.tpl index fc55279552..55ef173574 100644 --- a/http/codegen/templates/parse_endpoint.go.tpl +++ b/http/codegen/templates/parse_endpoint.go.tpl @@ -38,12 +38,11 @@ func ParseEndpoint( c := {{ .PkgName }}.NewClient(scheme, host, doer, enc, dec, restore{{ if .NeedStream }}, dialer, {{ .VarName }}Configurer{{ end }}) switch epn { {{- $pkgName := .PkgName }} - {{- $interceptors := .Interceptors }} {{- range .Subcommands }} case "{{ .Name }}": endpoint = c.{{ .MethodVarName }}({{ if .MultipartVarName }}{{ .MultipartVarName }}{{ end }}) - {{- if $interceptors }} - endpoint = {{ $interceptors.PkgName }}.Wrap{{ .MethodVarName }}ClientEndpoint(endpoint, {{ $interceptors.VarName }}) + {{- if .Interceptors }} + endpoint = {{ .Interceptors.PkgName }}.Wrap{{ .MethodVarName }}ClientEndpoint(endpoint, {{ .Interceptors.VarName }}) {{- end }} {{- if .BuildFunction }} data, err = {{ $pkgName }}.{{ .BuildFunction.Name }}({{ range .BuildFunction.ActualParams }}*{{ . }}Flag, {{ end }}) From 81835c3ec4953eb040e533b97e9690177158616e Mon Sep 17 00:00:00 2001 From: Douglas Thrift Date: Mon, 3 Feb 2025 12:01:38 -0800 Subject: [PATCH 14/23] Update InterceptorInfo comment and replace Send and Recv boolean fields with a CallType enum; organize interceptor wrappers file sections as types, functions, then methods --- codegen/service/interceptors.go | 59 ++++++++++++++++--- ...nt_interceptor_stream_wrapper_types.go.tpl | 14 +++++ .../client_interceptor_stream_wrappers.go.tpl | 42 +++++++++++++ .../client_interceptor_wrappers.go.tpl | 59 ++----------------- ...er_interceptor_stream_wrapper_types.go.tpl | 14 +++++ .../server_interceptor_stream_wrappers.go.tpl | 42 +++++++++++++ .../server_interceptor_wrappers.go.tpl | 59 ++----------------- pkg/interceptor.go | 21 +++++-- 8 files changed, 188 insertions(+), 122 deletions(-) create mode 100644 codegen/service/templates/client_interceptor_stream_wrapper_types.go.tpl create mode 100644 codegen/service/templates/client_interceptor_stream_wrappers.go.tpl create mode 100644 codegen/service/templates/server_interceptor_stream_wrapper_types.go.tpl create mode 100644 codegen/service/templates/server_interceptor_stream_wrappers.go.tpl diff --git a/codegen/service/interceptors.go b/codegen/service/interceptors.go index 67a7021d3b..f24f270f46 100644 --- a/codegen/service/interceptors.go +++ b/codegen/service/interceptors.go @@ -140,15 +140,41 @@ func wrapperFile(svc *Data) *codegen.File { codegen.GoaImport(""), })) - // Generate the interceptor wrapper functions first (only once) + // Generate any interceptor stream wrapper struct types first + var wrappedServerStreams, wrappedClientStreams []*StreamInterceptorData + if len(svc.ServerInterceptors) > 0 { + wrappedServerStreams = collectWrappedStreams(svc.ServerInterceptors, true) + if len(wrappedServerStreams) > 0 { + sections = append(sections, &codegen.SectionTemplate{ + Name: "server-interceptor-stream-wrapper-types", + Source: readTemplate("server_interceptor_stream_wrapper_types"), + Data: map[string]interface{}{ + "WrappedServerStreams": wrappedServerStreams, + }, + }) + } + } + if len(svc.ClientInterceptors) > 0 { + wrappedClientStreams = collectWrappedStreams(svc.ClientInterceptors, false) + if len(wrappedClientStreams) > 0 { + sections = append(sections, &codegen.SectionTemplate{ + Name: "client-interceptor-stream-wrapper-types", + Source: readTemplate("client_interceptor_stream_wrapper_types"), + Data: map[string]interface{}{ + "WrappedClientStreams": wrappedClientStreams, + }, + }) + } + } + + // Generate the interceptor wrapper functions next (only once) if len(svc.ServerInterceptors) > 0 { sections = append(sections, &codegen.SectionTemplate{ Name: "server-interceptor-wrappers", Source: readTemplate("server_interceptor_wrappers"), Data: map[string]interface{}{ - "Service": svc.Name, - "ServerInterceptors": svc.ServerInterceptors, - "WrappedServerStreams": collectWrappedStreams(svc.ServerInterceptors, true), + "Service": svc.Name, + "ServerInterceptors": svc.ServerInterceptors, }, }) } @@ -157,9 +183,28 @@ func wrapperFile(svc *Data) *codegen.File { Name: "client-interceptor-wrappers", Source: readTemplate("client_interceptor_wrappers"), Data: map[string]interface{}{ - "Service": svc.Name, - "ClientInterceptors": svc.ClientInterceptors, - "WrappedClientStreams": collectWrappedStreams(svc.ClientInterceptors, false), + "Service": svc.Name, + "ClientInterceptors": svc.ClientInterceptors, + }, + }) + } + + // Generate any interceptor stream wrapper struct methods last + if len(wrappedServerStreams) > 0 { + sections = append(sections, &codegen.SectionTemplate{ + Name: "server-interceptor-stream-wrappers", + Source: readTemplate("server_interceptor_stream_wrappers"), + Data: map[string]interface{}{ + "WrappedServerStreams": wrappedServerStreams, + }, + }) + } + if len(wrappedClientStreams) > 0 { + sections = append(sections, &codegen.SectionTemplate{ + Name: "client-interceptor-stream-wrappers", + Source: readTemplate("client_interceptor_stream_wrappers"), + Data: map[string]interface{}{ + "WrappedClientStreams": wrappedClientStreams, }, }) } diff --git a/codegen/service/templates/client_interceptor_stream_wrapper_types.go.tpl b/codegen/service/templates/client_interceptor_stream_wrapper_types.go.tpl new file mode 100644 index 0000000000..7c4f444fa1 --- /dev/null +++ b/codegen/service/templates/client_interceptor_stream_wrapper_types.go.tpl @@ -0,0 +1,14 @@ +{{- range .WrappedClientStreams }} + +{{ comment (printf "wrapped%s is a client interceptor wrapper for the %s stream." .Interface .Interface) }} +type wrapped{{ .Interface }} struct { + ctx context.Context + {{- if ne .SendTypeRef "" }} + sendWithContext func(context.Context, {{ .SendTypeRef }}) (context.Context, error) + {{- end }} + {{- if ne .RecvTypeRef "" }} + recvWithContext func(context.Context) ({{ .RecvTypeRef }}, context.Context, error) + {{- end }} + stream {{ .Interface }} +} +{{- end }} diff --git a/codegen/service/templates/client_interceptor_stream_wrappers.go.tpl b/codegen/service/templates/client_interceptor_stream_wrappers.go.tpl new file mode 100644 index 0000000000..1a0c0b7e22 --- /dev/null +++ b/codegen/service/templates/client_interceptor_stream_wrappers.go.tpl @@ -0,0 +1,42 @@ +{{- range .WrappedClientStreams }} + + {{- if ne .SendTypeRef "" }} + +{{ comment (printf "%s streams instances of \"%s\" after executing the applied interceptor." .SendName .Interface) }} +func (w *wrapped{{ .Interface }}) {{ .SendName }}(v {{ .SendTypeRef }}) error { + _, err := w.SendWithContext(w.ctx, v) + return err +} + +{{ comment (printf "%s streams instances of \"%s\" after executing the applied interceptor with context." .SendWithContextName .Interface) }} +func (w *wrapped{{ .Interface }}) {{ .SendWithContextName }}(ctx context.Context, v {{ .SendTypeRef }}) (context.Context, error) { + if w.sendWithContext == nil { + return w.stream.{{ .SendWithContextName }}(ctx, v) + } + return w.sendWithContext(ctx, v) +} + {{- end }} + {{- if ne .RecvTypeRef "" }} + +{{ comment (printf "%s reads instances of \"%s\" from the stream after executing the applied interceptor." .RecvName .Interface) }} +func (w *wrapped{{ .Interface }}) {{ .RecvName }}() ({{ .RecvTypeRef }}, error) { + res, _, err := w.RecvWithContext(w.ctx) + return res, err +} + +{{ comment (printf "%s reads instances of \"%s\" from the stream after executing the applied interceptor with context." .RecvWithContextName .Interface) }} +func (w *wrapped{{ .Interface }}) {{ .RecvWithContextName }}(ctx context.Context) ({{ .RecvTypeRef }}, context.Context, error) { + if w.recvWithContext == nil { + return w.stream.{{ .RecvWithContextName }}(ctx) + } + return w.recvWithContext(ctx) +} + {{- end }} + {{- if .MustClose }} + +// Close closes the stream. +func (w *wrapped{{ .Interface }}) Close() error { + return w.stream.Close() +} + {{- end }} +{{- end }} diff --git a/codegen/service/templates/client_interceptor_wrappers.go.tpl b/codegen/service/templates/client_interceptor_wrappers.go.tpl index 1e7310ec63..f98cbeb595 100644 --- a/codegen/service/templates/client_interceptor_wrappers.go.tpl +++ b/codegen/service/templates/client_interceptor_wrappers.go.tpl @@ -10,6 +10,7 @@ func wrapClient{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i info := &{{ $interceptor.Name }}Info{ Service: "{{ $.Service }}", Method: "{{ .MethodName }}", + CallType: goa.InterceptorUnary, RawPayload: req, } res, err := i.{{ $interceptor.Name }}(ctx, info, endpoint) @@ -27,7 +28,7 @@ func wrapClient{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i info := &{{ $interceptor.Name }}Info{ Service: "{{ $.Service }}", Method: "{{ .MethodName }}", - Send: true, + CallType: goa.InterceptorStreamingSend, RawPayload: req, } var rCtx context.Context @@ -44,7 +45,7 @@ func wrapClient{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i info := &{{ $interceptor.Name }}Info{ Service: "{{ $.Service }}", Method: "{{ .MethodName }}", - Recv: true, + CallType: goa.InterceptorStreamingRecv, RawPayload: req, } var rCtx context.Context @@ -65,64 +66,12 @@ func wrapClient{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i info := &{{ $interceptor.Name }}Info{ Service: "{{ $.Service }}", Method: "{{ .MethodName }}", + CallType: goa.InterceptorUnary, RawPayload: req, } return i.{{ $interceptor.Name }}(ctx, info, endpoint) {{- end }} } } -{{ end }} {{- end }} -{{- range .WrappedClientStreams }} - -{{ comment (printf "wrapped%s is a client interceptor wrapper for the %s stream." .Interface .Interface) }} -type wrapped{{ .Interface }} struct { - ctx context.Context - {{- if ne .SendTypeRef "" }} - sendWithContext func(context.Context, {{ .SendTypeRef }}) (context.Context, error) - {{- end }} - {{- if ne .RecvTypeRef "" }} - recvWithContext func(context.Context) ({{ .RecvTypeRef }}, context.Context, error) - {{- end }} - stream {{ .Interface }} -} - {{- if ne .SendTypeRef "" }} - -{{ comment (printf "%s streams instances of \"%s\" after executing the applied interceptor." .SendName .Interface) }} -func (w *wrapped{{ .Interface }}) {{ .SendName }}(v {{ .SendTypeRef }}) error { - _, err := w.SendWithContext(w.ctx, v) - return err -} - -{{ comment (printf "%s streams instances of \"%s\" after executing the applied interceptor with context." .SendWithContextName .Interface) }} -func (w *wrapped{{ .Interface }}) {{ .SendWithContextName }}(ctx context.Context, v {{ .SendTypeRef }}) (context.Context, error) { - if w.sendWithContext == nil { - return w.stream.{{ .SendWithContextName }}(ctx, v) - } - return w.sendWithContext(ctx, v) -} - {{- end }} - {{- if ne .RecvTypeRef "" }} - -{{ comment (printf "%s reads instances of \"%s\" from the stream after executing the applied interceptor." .RecvName .Interface) }} -func (w *wrapped{{ .Interface }}) {{ .RecvName }}() ({{ .RecvTypeRef }}, error) { - res, _, err := w.RecvWithContext(w.ctx) - return res, err -} - -{{ comment (printf "%s reads instances of \"%s\" from the stream after executing the applied interceptor with context." .RecvWithContextName .Interface) }} -func (w *wrapped{{ .Interface }}) {{ .RecvWithContextName }}(ctx context.Context) ({{ .RecvTypeRef }}, context.Context, error) { - if w.recvWithContext == nil { - return w.stream.{{ .RecvWithContextName }}(ctx) - } - return w.recvWithContext(ctx) -} - {{- end }} - {{- if .MustClose }} - -// Close closes the stream. -func (w *wrapped{{ .Interface }}) Close() error { - return w.stream.Close() -} - {{- end }} {{- end }} diff --git a/codegen/service/templates/server_interceptor_stream_wrapper_types.go.tpl b/codegen/service/templates/server_interceptor_stream_wrapper_types.go.tpl new file mode 100644 index 0000000000..659e21cf06 --- /dev/null +++ b/codegen/service/templates/server_interceptor_stream_wrapper_types.go.tpl @@ -0,0 +1,14 @@ +{{- range .WrappedServerStreams }} + +{{ comment (printf "wrapped%s is a server interceptor wrapper for the %s stream." .Interface .Interface) }} +type wrapped{{ .Interface }} struct { + ctx context.Context + {{- if ne .SendTypeRef "" }} + sendWithContext func(context.Context, {{ .SendTypeRef }}) (context.Context, error) + {{- end }} + {{- if ne .RecvTypeRef "" }} + recvWithContext func(context.Context) ({{ .RecvTypeRef }}, context.Context, error) + {{- end }} + stream {{ .Interface }} +} +{{- end }} diff --git a/codegen/service/templates/server_interceptor_stream_wrappers.go.tpl b/codegen/service/templates/server_interceptor_stream_wrappers.go.tpl new file mode 100644 index 0000000000..0c62bff3f5 --- /dev/null +++ b/codegen/service/templates/server_interceptor_stream_wrappers.go.tpl @@ -0,0 +1,42 @@ +{{- range .WrappedServerStreams }} + + {{- if ne .SendTypeRef "" }} + +{{ comment (printf "%s streams instances of \"%s\" after executing the applied interceptor." .SendName .Interface) }} +func (w *wrapped{{ .Interface }}) {{ .SendName }}(v {{ .SendTypeRef }}) error { + _, err := w.SendWithContext(w.ctx, v) + return err +} + +{{ comment (printf "%s streams instances of \"%s\" after executing the applied interceptor with context." .SendWithContextName .Interface) }} +func (w *wrapped{{ .Interface }}) {{ .SendWithContextName }}(ctx context.Context, v {{ .SendTypeRef }}) (context.Context, error) { + if w.sendWithContext == nil { + return w.stream.{{ .SendWithContextName }}(ctx, v) + } + return w.sendWithContext(ctx, v) +} + {{- end }} + {{- if ne .RecvTypeRef "" }} + +{{ comment (printf "%s reads instances of \"%s\" from the stream after executing the applied interceptor." .RecvName .Interface) }} +func (w *wrapped{{ .Interface }}) {{ .RecvName }}() ({{ .RecvTypeRef }}, error) { + res, _, err := w.RecvWithContext(w.ctx) + return res, err +} + +{{ comment (printf "%s reads instances of \"%s\" from the stream after executing the applied interceptor with context." .RecvWithContextName .Interface) }} +func (w *wrapped{{ .Interface }}) {{ .RecvWithContextName }}(ctx context.Context) ({{ .RecvTypeRef }}, context.Context, error) { + if w.recvWithContext == nil { + return w.stream.{{ .RecvWithContextName }}(ctx) + } + return w.recvWithContext(ctx) +} + {{- end }} + {{- if .MustClose }} + +// Close closes the stream. +func (w *wrapped{{ .Interface }}) Close() error { + return w.stream.Close() +} + {{- end }} +{{- end }} diff --git a/codegen/service/templates/server_interceptor_wrappers.go.tpl b/codegen/service/templates/server_interceptor_wrappers.go.tpl index b5a3fc7a62..09206b7240 100644 --- a/codegen/service/templates/server_interceptor_wrappers.go.tpl +++ b/codegen/service/templates/server_interceptor_wrappers.go.tpl @@ -10,6 +10,7 @@ func wrap{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i Serve info := &{{ $interceptor.Name }}Info{ Service: "{{ $.Service }}", Method: "{{ .MethodName }}", + CallType: goa.InterceptorUnary, RawPayload: req, } res, err := i.{{ $interceptor.Name }}(ctx, info, endpoint) @@ -27,7 +28,7 @@ func wrap{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i Serve info := &{{ $interceptor.Name }}Info{ Service: "{{ $.Service }}", Method: "{{ .MethodName }}", - Send: true, + CallType: goa.InterceptorStreamingSend, RawPayload: req, } var rCtx context.Context @@ -44,7 +45,7 @@ func wrap{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i Serve info := &{{ $interceptor.Name }}Info{ Service: "{{ $.Service }}", Method: "{{ .MethodName }}", - Recv: true, + CallType: goa.InterceptorStreamingRecv, RawPayload: req, } var rCtx context.Context @@ -65,6 +66,7 @@ func wrap{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i Serve info := &{{ $interceptor.Name }}Info{ Service: "{{ $.Service }}", Method: "{{ .MethodName }}", + CallType: goa.InterceptorUnary, RawPayload: req, } return i.{{ $interceptor.Name }}(ctx, info, endpoint) @@ -73,56 +75,3 @@ func wrap{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i Serve } {{- end }} {{- end }} -{{- range .WrappedServerStreams }} - -{{ comment (printf "wrapped%s is a server interceptor wrapper for the %s stream." .Interface .Interface) }} -type wrapped{{ .Interface }} struct { - ctx context.Context - {{- if ne .SendTypeRef "" }} - sendWithContext func(context.Context, {{ .SendTypeRef }}) (context.Context, error) - {{- end }} - {{- if ne .RecvTypeRef "" }} - recvWithContext func(context.Context) ({{ .RecvTypeRef }}, context.Context, error) - {{- end }} - stream {{ .Interface }} -} - {{- if ne .SendTypeRef "" }} - -{{ comment (printf "%s streams instances of \"%s\" after executing the applied interceptor." .SendName .Interface) }} -func (w *wrapped{{ .Interface }}) {{ .SendName }}(v {{ .SendTypeRef }}) error { - _, err := w.SendWithContext(w.ctx, v) - return err -} - -{{ comment (printf "%s streams instances of \"%s\" after executing the applied interceptor with context." .SendWithContextName .Interface) }} -func (w *wrapped{{ .Interface }}) {{ .SendWithContextName }}(ctx context.Context, v {{ .SendTypeRef }}) (context.Context, error) { - if w.sendWithContext == nil { - return w.stream.{{ .SendWithContextName }}(ctx, v) - } - return w.sendWithContext(ctx, v) -} - {{- end }} - {{- if ne .RecvTypeRef "" }} - -{{ comment (printf "%s reads instances of \"%s\" from the stream after executing the applied interceptor." .RecvName .Interface) }} -func (w *wrapped{{ .Interface }}) {{ .RecvName }}() ({{ .RecvTypeRef }}, error) { - res, _, err := w.RecvWithContext(w.ctx) - return res, err -} - -{{ comment (printf "%s reads instances of \"%s\" from the stream after executing the applied interceptor with context." .RecvWithContextName .Interface) }} -func (w *wrapped{{ .Interface }}) {{ .RecvWithContextName }}(ctx context.Context) ({{ .RecvTypeRef }}, context.Context, error) { - if w.recvWithContext == nil { - return w.stream.{{ .RecvWithContextName }}(ctx) - } - return w.recvWithContext(ctx) -} - {{- end }} - {{- if .MustClose }} - -// Close closes the stream. -func (w *wrapped{{ .Interface }}) Close() error { - return w.stream.Close() -} - {{- end }} -{{- end }} diff --git a/pkg/interceptor.go b/pkg/interceptor.go index 0d2b3703b7..f3e7e900e4 100644 --- a/pkg/interceptor.go +++ b/pkg/interceptor.go @@ -3,17 +3,28 @@ package goa type ( // InterceptorInfo contains information about the request shared between // all interceptors in the service chain. It provides access to the service name, - // method name, endpoint function, and request payload. + // method name, the type of call the interceptor is handling (unary, streaming send, + // or streaming recv), and the request payload. InterceptorInfo struct { // Name of service handling request Service string // Name of method handling request Method string - // Send is true if the request is a streaming Send - Send bool - // Recv is true if the request is a streaming Recv - Recv bool + // CallType is the type of call the interceptor is handling + CallType InterceptorCallType // Payload of request RawPayload any } + + // InterceptorCallType is the type of call the interceptor is handling + InterceptorCallType int +) + +const ( + // InterceptorUnary indicates the interceptor is handling a unary call + InterceptorUnary InterceptorCallType = iota + // InterceptorStreamingSend indicates the interceptor is handling a streaming Send + InterceptorStreamingSend + // InterceptorStreamingRecv indicates the interceptor is handling a streaming Recv + InterceptorStreamingRecv ) From 1e1c7ab73d56bed040c93b88a7e0b2a564595dad Mon Sep 17 00:00:00 2001 From: Douglas Thrift Date: Mon, 3 Feb 2025 12:05:05 -0800 Subject: [PATCH 15/23] Update Golden files to make the Interceptor tests happy --- ...ead-payload_interceptor_wrappers.go.golden | 3 +- ...read-result_interceptor_wrappers.go.golden | 3 +- ...ite-payload_interceptor_wrappers.go.golden | 3 +- ...rite-result_interceptor_wrappers.go.golden | 3 +- ...ite-payload_interceptor_wrappers.go.golden | 3 +- ...rite-result_interceptor_wrappers.go.golden | 3 +- ...nterceptors_interceptor_wrappers.go.golden | 5 +- ...interceptor_interceptor_wrappers.go.golden | 2 + ...interceptor_interceptor_wrappers.go.golden | 2 +- ...interceptor_interceptor_wrappers.go.golden | 1 + ...interceptor_interceptor_wrappers.go.golden | 2 + ...ing-payload_interceptor_wrappers.go.golden | 76 ++++++------ ...ead-payload_interceptor_wrappers.go.golden | 1 + ...read-result_interceptor_wrappers.go.golden | 1 + ...ming-result_interceptor_wrappers.go.golden | 74 ++++++------ ...nterceptors_interceptor_wrappers.go.golden | 114 +++++++++--------- 16 files changed, 157 insertions(+), 139 deletions(-) diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-payload_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-payload_interceptor_wrappers.go.golden index 1f3ce8ae1e..62b7947564 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-payload_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-payload_interceptor_wrappers.go.golden @@ -6,6 +6,7 @@ func wrapMethodValidation(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpo info := &ValidationInfo{ Service: "InterceptorWithReadPayload", Method: "Method", + CallType: goa.InterceptorUnary, RawPayload: req, } return i.Validation(ctx, info, endpoint) @@ -19,9 +20,9 @@ func wrapClientMethodValidation(endpoint goa.Endpoint, i ClientInterceptors) goa info := &ValidationInfo{ Service: "InterceptorWithReadPayload", Method: "Method", + CallType: goa.InterceptorUnary, RawPayload: req, } return i.Validation(ctx, info, endpoint) } } - diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-result_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-result_interceptor_wrappers.go.golden index 691697a6ee..14820fd7c9 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-result_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-result_interceptor_wrappers.go.golden @@ -6,6 +6,7 @@ func wrapMethodCaching(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint info := &CachingInfo{ Service: "InterceptorWithReadResult", Method: "Method", + CallType: goa.InterceptorUnary, RawPayload: req, } return i.Caching(ctx, info, endpoint) @@ -18,9 +19,9 @@ func wrapClientMethodCaching(endpoint goa.Endpoint, i ClientInterceptors) goa.En info := &CachingInfo{ Service: "InterceptorWithReadResult", Method: "Method", + CallType: goa.InterceptorUnary, RawPayload: req, } return i.Caching(ctx, info, endpoint) } } - diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_interceptor_wrappers.go.golden index 9c26266c7b..979a7f79bd 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_interceptor_wrappers.go.golden @@ -6,6 +6,7 @@ func wrapMethodValidation(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpo info := &ValidationInfo{ Service: "InterceptorWithReadWritePayload", Method: "Method", + CallType: goa.InterceptorUnary, RawPayload: req, } return i.Validation(ctx, info, endpoint) @@ -19,9 +20,9 @@ func wrapClientMethodValidation(endpoint goa.Endpoint, i ClientInterceptors) goa info := &ValidationInfo{ Service: "InterceptorWithReadWritePayload", Method: "Method", + CallType: goa.InterceptorUnary, RawPayload: req, } return i.Validation(ctx, info, endpoint) } } - diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-write-result_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-write-result_interceptor_wrappers.go.golden index 03a814570c..cb20d1cb5f 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-write-result_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-write-result_interceptor_wrappers.go.golden @@ -6,6 +6,7 @@ func wrapMethodCaching(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint info := &CachingInfo{ Service: "InterceptorWithReadWriteResult", Method: "Method", + CallType: goa.InterceptorUnary, RawPayload: req, } return i.Caching(ctx, info, endpoint) @@ -18,9 +19,9 @@ func wrapClientMethodCaching(endpoint goa.Endpoint, i ClientInterceptors) goa.En info := &CachingInfo{ Service: "InterceptorWithReadWriteResult", Method: "Method", + CallType: goa.InterceptorUnary, RawPayload: req, } return i.Caching(ctx, info, endpoint) } } - diff --git a/codegen/service/testdata/interceptors/interceptor-with-write-payload_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/interceptor-with-write-payload_interceptor_wrappers.go.golden index 8a89a016f5..b7e7c3bcd3 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-write-payload_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-write-payload_interceptor_wrappers.go.golden @@ -6,6 +6,7 @@ func wrapMethodValidation(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpo info := &ValidationInfo{ Service: "InterceptorWithWritePayload", Method: "Method", + CallType: goa.InterceptorUnary, RawPayload: req, } return i.Validation(ctx, info, endpoint) @@ -19,9 +20,9 @@ func wrapClientMethodValidation(endpoint goa.Endpoint, i ClientInterceptors) goa info := &ValidationInfo{ Service: "InterceptorWithWritePayload", Method: "Method", + CallType: goa.InterceptorUnary, RawPayload: req, } return i.Validation(ctx, info, endpoint) } } - diff --git a/codegen/service/testdata/interceptors/interceptor-with-write-result_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/interceptor-with-write-result_interceptor_wrappers.go.golden index 565d208e84..c0cf2757b4 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-write-result_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-write-result_interceptor_wrappers.go.golden @@ -6,6 +6,7 @@ func wrapMethodCaching(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint info := &CachingInfo{ Service: "InterceptorWithWriteResult", Method: "Method", + CallType: goa.InterceptorUnary, RawPayload: req, } return i.Caching(ctx, info, endpoint) @@ -18,9 +19,9 @@ func wrapClientMethodCaching(endpoint goa.Endpoint, i ClientInterceptors) goa.En info := &CachingInfo{ Service: "InterceptorWithWriteResult", Method: "Method", + CallType: goa.InterceptorUnary, RawPayload: req, } return i.Caching(ctx, info, endpoint) } } - diff --git a/codegen/service/testdata/interceptors/multiple-interceptors_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/multiple-interceptors_interceptor_wrappers.go.golden index 1f5f64208e..5b98169284 100644 --- a/codegen/service/testdata/interceptors/multiple-interceptors_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/multiple-interceptors_interceptor_wrappers.go.golden @@ -6,6 +6,7 @@ func wrapMethodTest(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { info := &TestInfo{ Service: "MultipleInterceptorsService", Method: "Method", + CallType: goa.InterceptorUnary, RawPayload: req, } return i.Test(ctx, info, endpoint) @@ -18,6 +19,7 @@ func wrapMethodTest3(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { info := &Test3Info{ Service: "MultipleInterceptorsService", Method: "Method", + CallType: goa.InterceptorUnary, RawPayload: req, } return i.Test3(ctx, info, endpoint) @@ -30,6 +32,7 @@ func wrapClientMethodTest2(endpoint goa.Endpoint, i ClientInterceptors) goa.Endp info := &Test2Info{ Service: "MultipleInterceptorsService", Method: "Method", + CallType: goa.InterceptorUnary, RawPayload: req, } return i.Test2(ctx, info, endpoint) @@ -42,9 +45,9 @@ func wrapClientMethodTest4(endpoint goa.Endpoint, i ClientInterceptors) goa.Endp info := &Test4Info{ Service: "MultipleInterceptorsService", Method: "Method", + CallType: goa.InterceptorUnary, RawPayload: req, } return i.Test4(ctx, info, endpoint) } } - diff --git a/codegen/service/testdata/interceptors/single-api-server-interceptor_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/single-api-server-interceptor_interceptor_wrappers.go.golden index 98088d5ac2..63149a1fe5 100644 --- a/codegen/service/testdata/interceptors/single-api-server-interceptor_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/single-api-server-interceptor_interceptor_wrappers.go.golden @@ -6,6 +6,7 @@ func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint info := &LoggingInfo{ Service: "SingleAPIServerInterceptor", Method: "Method", + CallType: goa.InterceptorUnary, RawPayload: req, } return i.Logging(ctx, info, endpoint) @@ -18,6 +19,7 @@ func wrapMethod2Logging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoin info := &LoggingInfo{ Service: "SingleAPIServerInterceptor", Method: "Method2", + CallType: goa.InterceptorUnary, RawPayload: req, } return i.Logging(ctx, info, endpoint) diff --git a/codegen/service/testdata/interceptors/single-client-interceptor_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/single-client-interceptor_interceptor_wrappers.go.golden index dda05a49b5..ae1d69d550 100644 --- a/codegen/service/testdata/interceptors/single-client-interceptor_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/single-client-interceptor_interceptor_wrappers.go.golden @@ -6,9 +6,9 @@ func wrapClientMethodTracing(endpoint goa.Endpoint, i ClientInterceptors) goa.En info := &TracingInfo{ Service: "SingleClientInterceptor", Method: "Method", + CallType: goa.InterceptorUnary, RawPayload: req, } return i.Tracing(ctx, info, endpoint) } } - diff --git a/codegen/service/testdata/interceptors/single-method-server-interceptor_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/single-method-server-interceptor_interceptor_wrappers.go.golden index 94a6d97091..112499cc5a 100644 --- a/codegen/service/testdata/interceptors/single-method-server-interceptor_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/single-method-server-interceptor_interceptor_wrappers.go.golden @@ -6,6 +6,7 @@ func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint info := &LoggingInfo{ Service: "SingleMethodServerInterceptor", Method: "Method", + CallType: goa.InterceptorUnary, RawPayload: req, } return i.Logging(ctx, info, endpoint) diff --git a/codegen/service/testdata/interceptors/single-service-server-interceptor_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/single-service-server-interceptor_interceptor_wrappers.go.golden index 3e8a292f16..5b083b9aad 100644 --- a/codegen/service/testdata/interceptors/single-service-server-interceptor_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/single-service-server-interceptor_interceptor_wrappers.go.golden @@ -6,6 +6,7 @@ func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint info := &LoggingInfo{ Service: "SingleServerInterceptor", Method: "Method", + CallType: goa.InterceptorUnary, RawPayload: req, } return i.Logging(ctx, info, endpoint) @@ -18,6 +19,7 @@ func wrapMethod2Logging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoin info := &LoggingInfo{ Service: "SingleServerInterceptor", Method: "Method2", + CallType: goa.InterceptorUnary, RawPayload: req, } return i.Logging(ctx, info, endpoint) diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_interceptor_wrappers.go.golden index 79a02f5c63..5ce3204e88 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_interceptor_wrappers.go.golden @@ -1,11 +1,28 @@ +// wrappedMethodServerStream is a server interceptor wrapper for the +// MethodServerStream stream. +type wrappedMethodServerStream struct { + ctx context.Context + recvWithContext func(context.Context) (*MethodStreamingPayload, context.Context, error) + stream MethodServerStream +} + +// wrappedMethodClientStream is a client interceptor wrapper for the +// MethodClientStream stream. +type wrappedMethodClientStream struct { + ctx context.Context + sendWithContext func(context.Context, *MethodStreamingPayload) (context.Context, error) + stream MethodClientStream +} + // wrapLoggingMethod applies the logging server interceptor to endpoints. func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { return func(ctx context.Context, req any) (any, error) { info := &LoggingInfo{ Service: "StreamingInterceptorsWithReadPayloadAndReadStreamingPayload", Method: "Method", + CallType: goa.InterceptorUnary, RawPayload: req, } res, err := i.Logging(ctx, info, endpoint) @@ -19,7 +36,7 @@ func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint info := &LoggingInfo{ Service: "StreamingInterceptorsWithReadPayloadAndReadStreamingPayload", Method: "Method", - Recv: true, + CallType: goa.InterceptorStreamingRecv, RawPayload: req, } var rCtx context.Context @@ -38,41 +55,13 @@ func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint } } -// wrappedMethodServerStream is a server interceptor wrapper for the -// MethodServerStream stream. -type wrappedMethodServerStream struct { - ctx context.Context - recvWithContext func(context.Context) (*MethodStreamingPayload, context.Context, error) - stream MethodServerStream -} - -// Recv reads instances of "MethodServerStream" from the stream after executing -// the applied interceptor. -func (w *wrappedMethodServerStream) Recv() (*MethodStreamingPayload, error) { - res, _, err := w.RecvWithContext(w.ctx) - return res, err -} - -// RecvWithContext reads instances of "MethodServerStream" from the stream -// after executing the applied interceptor with context. -func (w *wrappedMethodServerStream) RecvWithContext(ctx context.Context) (*MethodStreamingPayload, context.Context, error) { - if w.recvWithContext == nil { - return w.stream.RecvWithContext(ctx) - } - return w.recvWithContext(ctx) -} - -// Close closes the stream. -func (w *wrappedMethodServerStream) Close() error { - return w.stream.Close() -} - // wrapClientLoggingMethod applies the logging client interceptor to endpoints. func wrapClientMethodLogging(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { return func(ctx context.Context, req any) (any, error) { info := &LoggingInfo{ Service: "StreamingInterceptorsWithReadPayloadAndReadStreamingPayload", Method: "Method", + CallType: goa.InterceptorUnary, RawPayload: req, } res, err := i.Logging(ctx, info, endpoint) @@ -86,7 +75,7 @@ func wrapClientMethodLogging(endpoint goa.Endpoint, i ClientInterceptors) goa.En info := &LoggingInfo{ Service: "StreamingInterceptorsWithReadPayloadAndReadStreamingPayload", Method: "Method", - Send: true, + CallType: goa.InterceptorStreamingSend, RawPayload: req, } var rCtx context.Context @@ -102,12 +91,25 @@ func wrapClientMethodLogging(endpoint goa.Endpoint, i ClientInterceptors) goa.En } } -// wrappedMethodClientStream is a client interceptor wrapper for the -// MethodClientStream stream. -type wrappedMethodClientStream struct { - ctx context.Context - sendWithContext func(context.Context, *MethodStreamingPayload) (context.Context, error) - stream MethodClientStream +// Recv reads instances of "MethodServerStream" from the stream after executing +// the applied interceptor. +func (w *wrappedMethodServerStream) Recv() (*MethodStreamingPayload, error) { + res, _, err := w.RecvWithContext(w.ctx) + return res, err +} + +// RecvWithContext reads instances of "MethodServerStream" from the stream +// after executing the applied interceptor with context. +func (w *wrappedMethodServerStream) RecvWithContext(ctx context.Context) (*MethodStreamingPayload, context.Context, error) { + if w.recvWithContext == nil { + return w.stream.RecvWithContext(ctx) + } + return w.recvWithContext(ctx) +} + +// Close closes the stream. +func (w *wrappedMethodServerStream) Close() error { + return w.stream.Close() } // Send streams instances of "MethodClientStream" after executing the applied diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_interceptor_wrappers.go.golden index 9064fc0803..4df7def716 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_interceptor_wrappers.go.golden @@ -6,6 +6,7 @@ func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint info := &LoggingInfo{ Service: "StreamingInterceptorsWithReadPayload", Method: "Method", + CallType: goa.InterceptorUnary, RawPayload: req, } return i.Logging(ctx, info, endpoint) diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_interceptor_wrappers.go.golden index e55620d86d..fefe8935ca 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_interceptor_wrappers.go.golden @@ -6,6 +6,7 @@ func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint info := &LoggingInfo{ Service: "StreamingInterceptorsWithReadResult", Method: "Method", + CallType: goa.InterceptorUnary, RawPayload: req, } return i.Logging(ctx, info, endpoint) diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_interceptor_wrappers.go.golden index 4ae7e348d1..4f7382c181 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_interceptor_wrappers.go.golden @@ -1,5 +1,21 @@ +// wrappedMethodServerStream is a server interceptor wrapper for the +// MethodServerStream stream. +type wrappedMethodServerStream struct { + ctx context.Context + sendWithContext func(context.Context, *MethodResult) (context.Context, error) + stream MethodServerStream +} + +// wrappedMethodClientStream is a client interceptor wrapper for the +// MethodClientStream stream. +type wrappedMethodClientStream struct { + ctx context.Context + recvWithContext func(context.Context) (*MethodResult, context.Context, error) + stream MethodClientStream +} + // wrapLoggingMethod applies the logging server interceptor to endpoints. func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { return func(ctx context.Context, req any) (any, error) { @@ -14,7 +30,7 @@ func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint info := &LoggingInfo{ Service: "StreamingInterceptorsWithReadStreamingResult", Method: "Method", - Send: true, + CallType: goa.InterceptorStreamingSend, RawPayload: req, } var rCtx context.Context @@ -30,35 +46,6 @@ func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint } } -// wrappedMethodServerStream is a server interceptor wrapper for the -// MethodServerStream stream. -type wrappedMethodServerStream struct { - ctx context.Context - sendWithContext func(context.Context, *MethodResult) (context.Context, error) - stream MethodServerStream -} - -// Send streams instances of "MethodServerStream" after executing the applied -// interceptor. -func (w *wrappedMethodServerStream) Send(v *MethodResult) error { - _, err := w.SendWithContext(w.ctx, v) - return err -} - -// SendWithContext streams instances of "MethodServerStream" after executing -// the applied interceptor with context. -func (w *wrappedMethodServerStream) SendWithContext(ctx context.Context, v *MethodResult) (context.Context, error) { - if w.sendWithContext == nil { - return w.stream.SendWithContext(ctx, v) - } - return w.sendWithContext(ctx, v) -} - -// Close closes the stream. -func (w *wrappedMethodServerStream) Close() error { - return w.stream.Close() -} - // wrapClientLoggingMethod applies the logging client interceptor to endpoints. func wrapClientMethodLogging(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { return func(ctx context.Context, req any) (any, error) { @@ -73,7 +60,7 @@ func wrapClientMethodLogging(endpoint goa.Endpoint, i ClientInterceptors) goa.En info := &LoggingInfo{ Service: "StreamingInterceptorsWithReadStreamingResult", Method: "Method", - Recv: true, + CallType: goa.InterceptorStreamingRecv, RawPayload: req, } var rCtx context.Context @@ -92,12 +79,25 @@ func wrapClientMethodLogging(endpoint goa.Endpoint, i ClientInterceptors) goa.En } } -// wrappedMethodClientStream is a client interceptor wrapper for the -// MethodClientStream stream. -type wrappedMethodClientStream struct { - ctx context.Context - recvWithContext func(context.Context) (*MethodResult, context.Context, error) - stream MethodClientStream +// Send streams instances of "MethodServerStream" after executing the applied +// interceptor. +func (w *wrappedMethodServerStream) Send(v *MethodResult) error { + _, err := w.SendWithContext(w.ctx, v) + return err +} + +// SendWithContext streams instances of "MethodServerStream" after executing +// the applied interceptor with context. +func (w *wrappedMethodServerStream) SendWithContext(ctx context.Context, v *MethodResult) (context.Context, error) { + if w.sendWithContext == nil { + return w.stream.SendWithContext(ctx, v) + } + return w.sendWithContext(ctx, v) +} + +// Close closes the stream. +func (w *wrappedMethodServerStream) Close() error { + return w.stream.Close() } // Recv reads instances of "MethodClientStream" from the stream after executing diff --git a/codegen/service/testdata/interceptors/streaming-interceptors_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors_interceptor_wrappers.go.golden index 07ae5e3cfe..2a7d95ac6e 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors_interceptor_wrappers.go.golden @@ -1,5 +1,23 @@ +// wrappedMethodServerStream is a server interceptor wrapper for the +// MethodServerStream stream. +type wrappedMethodServerStream struct { + ctx context.Context + sendWithContext func(context.Context, *MethodResult) (context.Context, error) + recvWithContext func(context.Context) (*MethodStreamingPayload, context.Context, error) + stream MethodServerStream +} + +// wrappedMethodClientStream is a client interceptor wrapper for the +// MethodClientStream stream. +type wrappedMethodClientStream struct { + ctx context.Context + sendWithContext func(context.Context, *MethodStreamingPayload) (context.Context, error) + recvWithContext func(context.Context) (*MethodResult, context.Context, error) + stream MethodClientStream +} + // wrapLoggingMethod applies the logging server interceptor to endpoints. func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { return func(ctx context.Context, req any) (any, error) { @@ -14,7 +32,7 @@ func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint info := &LoggingInfo{ Service: "StreamingInterceptors", Method: "Method", - Send: true, + CallType: goa.InterceptorStreamingSend, RawPayload: req, } var rCtx context.Context @@ -29,7 +47,7 @@ func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint info := &LoggingInfo{ Service: "StreamingInterceptors", Method: "Method", - Recv: true, + CallType: goa.InterceptorStreamingRecv, RawPayload: req, } var rCtx context.Context @@ -48,52 +66,6 @@ func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint } } -// wrappedMethodServerStream is a server interceptor wrapper for the -// MethodServerStream stream. -type wrappedMethodServerStream struct { - ctx context.Context - sendWithContext func(context.Context, *MethodResult) (context.Context, error) - recvWithContext func(context.Context) (*MethodStreamingPayload, context.Context, error) - stream MethodServerStream -} - -// Send streams instances of "MethodServerStream" after executing the applied -// interceptor. -func (w *wrappedMethodServerStream) Send(v *MethodResult) error { - _, err := w.SendWithContext(w.ctx, v) - return err -} - -// SendWithContext streams instances of "MethodServerStream" after executing -// the applied interceptor with context. -func (w *wrappedMethodServerStream) SendWithContext(ctx context.Context, v *MethodResult) (context.Context, error) { - if w.sendWithContext == nil { - return w.stream.SendWithContext(ctx, v) - } - return w.sendWithContext(ctx, v) -} - -// Recv reads instances of "MethodServerStream" from the stream after executing -// the applied interceptor. -func (w *wrappedMethodServerStream) Recv() (*MethodStreamingPayload, error) { - res, _, err := w.RecvWithContext(w.ctx) - return res, err -} - -// RecvWithContext reads instances of "MethodServerStream" from the stream -// after executing the applied interceptor with context. -func (w *wrappedMethodServerStream) RecvWithContext(ctx context.Context) (*MethodStreamingPayload, context.Context, error) { - if w.recvWithContext == nil { - return w.stream.RecvWithContext(ctx) - } - return w.recvWithContext(ctx) -} - -// Close closes the stream. -func (w *wrappedMethodServerStream) Close() error { - return w.stream.Close() -} - // wrapClientLoggingMethod applies the logging client interceptor to endpoints. func wrapClientMethodLogging(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { return func(ctx context.Context, req any) (any, error) { @@ -108,7 +80,7 @@ func wrapClientMethodLogging(endpoint goa.Endpoint, i ClientInterceptors) goa.En info := &LoggingInfo{ Service: "StreamingInterceptors", Method: "Method", - Send: true, + CallType: goa.InterceptorStreamingSend, RawPayload: req, } var rCtx context.Context @@ -123,7 +95,7 @@ func wrapClientMethodLogging(endpoint goa.Endpoint, i ClientInterceptors) goa.En info := &LoggingInfo{ Service: "StreamingInterceptors", Method: "Method", - Recv: true, + CallType: goa.InterceptorStreamingRecv, RawPayload: req, } var rCtx context.Context @@ -142,13 +114,41 @@ func wrapClientMethodLogging(endpoint goa.Endpoint, i ClientInterceptors) goa.En } } -// wrappedMethodClientStream is a client interceptor wrapper for the -// MethodClientStream stream. -type wrappedMethodClientStream struct { - ctx context.Context - sendWithContext func(context.Context, *MethodStreamingPayload) (context.Context, error) - recvWithContext func(context.Context) (*MethodResult, context.Context, error) - stream MethodClientStream +// Send streams instances of "MethodServerStream" after executing the applied +// interceptor. +func (w *wrappedMethodServerStream) Send(v *MethodResult) error { + _, err := w.SendWithContext(w.ctx, v) + return err +} + +// SendWithContext streams instances of "MethodServerStream" after executing +// the applied interceptor with context. +func (w *wrappedMethodServerStream) SendWithContext(ctx context.Context, v *MethodResult) (context.Context, error) { + if w.sendWithContext == nil { + return w.stream.SendWithContext(ctx, v) + } + return w.sendWithContext(ctx, v) +} + +// Recv reads instances of "MethodServerStream" from the stream after executing +// the applied interceptor. +func (w *wrappedMethodServerStream) Recv() (*MethodStreamingPayload, error) { + res, _, err := w.RecvWithContext(w.ctx) + return res, err +} + +// RecvWithContext reads instances of "MethodServerStream" from the stream +// after executing the applied interceptor with context. +func (w *wrappedMethodServerStream) RecvWithContext(ctx context.Context) (*MethodStreamingPayload, context.Context, error) { + if w.recvWithContext == nil { + return w.stream.RecvWithContext(ctx) + } + return w.recvWithContext(ctx) +} + +// Close closes the stream. +func (w *wrappedMethodServerStream) Close() error { + return w.stream.Close() } // Send streams instances of "MethodClientStream" after executing the applied From 712ab19bf18e7ddd4a8b9fb6d25676db8ba9a572 Mon Sep 17 00:00:00 2001 From: Douglas Thrift Date: Mon, 3 Feb 2025 17:54:05 -0800 Subject: [PATCH 16/23] Add a ReturnContext field to goa.InterceptorInfo to allow interceptors to modify the context returned by SendWithContext/RecvWithContext even after calling next --- .../client_interceptor_wrappers.go.tpl | 10 ++++------ .../server_interceptor_wrappers.go.tpl | 10 ++++------ ...ing-payload_interceptor_wrappers.go.golden | 10 ++++------ ...ming-result_interceptor_wrappers.go.golden | 10 ++++------ ...nterceptors_interceptor_wrappers.go.golden | 20 ++++++++----------- pkg/interceptor.go | 4 ++++ 6 files changed, 28 insertions(+), 36 deletions(-) diff --git a/codegen/service/templates/client_interceptor_wrappers.go.tpl b/codegen/service/templates/client_interceptor_wrappers.go.tpl index f98cbeb595..5241a9edcf 100644 --- a/codegen/service/templates/client_interceptor_wrappers.go.tpl +++ b/codegen/service/templates/client_interceptor_wrappers.go.tpl @@ -31,13 +31,12 @@ func wrapClient{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i CallType: goa.InterceptorStreamingSend, RawPayload: req, } - var rCtx context.Context _, err := i.{{ $interceptor.Name }}(ctx, info, func(ctx context.Context, req any) (any, error) { var err error - rCtx, err = stream.{{ .ClientStream.SendWithContextName }}(ctx, req.({{ .ClientStream.SendTypeRef }})) + info.ReturnContext, err = stream.{{ .ClientStream.SendWithContextName }}(ctx, req.({{ .ClientStream.SendTypeRef }})) return nil, err }) - return rCtx, err + return info.ReturnContext, err }, {{- end }} {{- if $interceptor.HasStreamingResultAccess }} @@ -48,16 +47,15 @@ func wrapClient{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i CallType: goa.InterceptorStreamingRecv, RawPayload: req, } - var rCtx context.Context res, err := i.{{ $interceptor.Name }}(ctx, info, func(ctx context.Context, req any) (any, error) { var ( res {{ .ClientStream.RecvTypeRef }} err error ) - res, rCtx, err = stream.{{ .ClientStream.RecvWithContextName }}(ctx) + res, info.ReturnContext, err = stream.{{ .ClientStream.RecvWithContextName }}(ctx) return res, err }) - return res.({{ .ClientStream.RecvTypeRef }}), rCtx, err + return res.({{ .ClientStream.RecvTypeRef }}), info.ReturnContext, err }, {{- end }} stream: stream, diff --git a/codegen/service/templates/server_interceptor_wrappers.go.tpl b/codegen/service/templates/server_interceptor_wrappers.go.tpl index 09206b7240..b319db7187 100644 --- a/codegen/service/templates/server_interceptor_wrappers.go.tpl +++ b/codegen/service/templates/server_interceptor_wrappers.go.tpl @@ -31,13 +31,12 @@ func wrap{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i Serve CallType: goa.InterceptorStreamingSend, RawPayload: req, } - var rCtx context.Context _, err := i.{{ $interceptor.Name }}(ctx, info, func(ctx context.Context, req any) (any, error) { var err error - rCtx, err = stream.{{ .ServerStream.SendWithContextName }}(ctx, req.({{ .ServerStream.SendTypeRef }})) + info.ReturnContext, err = stream.{{ .ServerStream.SendWithContextName }}(ctx, req.({{ .ServerStream.SendTypeRef }})) return nil, err }) - return rCtx, err + return info.ReturnContext, err }, {{- end }} {{- if $interceptor.HasStreamingPayloadAccess }} @@ -48,16 +47,15 @@ func wrap{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i Serve CallType: goa.InterceptorStreamingRecv, RawPayload: req, } - var rCtx context.Context res, err := i.{{ $interceptor.Name }}(ctx, info, func(ctx context.Context, req any) (any, error) { var ( res {{ .ServerStream.RecvTypeRef }} err error ) - res, rCtx, err = stream.{{ .ServerStream.RecvWithContextName }}(ctx) + res, info.ReturnContext, err = stream.{{ .ServerStream.RecvWithContextName }}(ctx) return res, err }) - return res.({{ .ServerStream.RecvTypeRef }}), rCtx, err + return res.({{ .ServerStream.RecvTypeRef }}), info.ReturnContext, err }, {{- end }} stream: stream, diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_interceptor_wrappers.go.golden index 5ce3204e88..cffbddcd7b 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_interceptor_wrappers.go.golden @@ -39,16 +39,15 @@ func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint CallType: goa.InterceptorStreamingRecv, RawPayload: req, } - var rCtx context.Context res, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, error) { var ( res *MethodStreamingPayload err error ) - res, rCtx, err = stream.RecvWithContext(ctx) + res, info.ReturnContext, err = stream.RecvWithContext(ctx) return res, err }) - return res.(*MethodStreamingPayload), rCtx, err + return res.(*MethodStreamingPayload), info.ReturnContext, err }, stream: stream, }, nil @@ -78,13 +77,12 @@ func wrapClientMethodLogging(endpoint goa.Endpoint, i ClientInterceptors) goa.En CallType: goa.InterceptorStreamingSend, RawPayload: req, } - var rCtx context.Context _, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, error) { var err error - rCtx, err = stream.SendWithContext(ctx, req.(*MethodStreamingPayload)) + info.ReturnContext, err = stream.SendWithContext(ctx, req.(*MethodStreamingPayload)) return nil, err }) - return rCtx, err + return info.ReturnContext, err }, stream: stream, }, nil diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_interceptor_wrappers.go.golden index 4f7382c181..75546b9cb3 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_interceptor_wrappers.go.golden @@ -33,13 +33,12 @@ func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint CallType: goa.InterceptorStreamingSend, RawPayload: req, } - var rCtx context.Context _, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, error) { var err error - rCtx, err = stream.SendWithContext(ctx, req.(*MethodResult)) + info.ReturnContext, err = stream.SendWithContext(ctx, req.(*MethodResult)) return nil, err }) - return rCtx, err + return info.ReturnContext, err }, stream: stream, }, nil @@ -63,16 +62,15 @@ func wrapClientMethodLogging(endpoint goa.Endpoint, i ClientInterceptors) goa.En CallType: goa.InterceptorStreamingRecv, RawPayload: req, } - var rCtx context.Context res, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, error) { var ( res *MethodResult err error ) - res, rCtx, err = stream.RecvWithContext(ctx) + res, info.ReturnContext, err = stream.RecvWithContext(ctx) return res, err }) - return res.(*MethodResult), rCtx, err + return res.(*MethodResult), info.ReturnContext, err }, stream: stream, }, nil diff --git a/codegen/service/testdata/interceptors/streaming-interceptors_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors_interceptor_wrappers.go.golden index 2a7d95ac6e..310c32876c 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors_interceptor_wrappers.go.golden @@ -35,13 +35,12 @@ func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint CallType: goa.InterceptorStreamingSend, RawPayload: req, } - var rCtx context.Context _, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, error) { var err error - rCtx, err = stream.SendWithContext(ctx, req.(*MethodResult)) + info.ReturnContext, err = stream.SendWithContext(ctx, req.(*MethodResult)) return nil, err }) - return rCtx, err + return info.ReturnContext, err }, recvWithContext: func(ctx context.Context) (*MethodStreamingPayload, context.Context, error) { info := &LoggingInfo{ @@ -50,16 +49,15 @@ func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint CallType: goa.InterceptorStreamingRecv, RawPayload: req, } - var rCtx context.Context res, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, error) { var ( res *MethodStreamingPayload err error ) - res, rCtx, err = stream.RecvWithContext(ctx) + res, info.ReturnContext, err = stream.RecvWithContext(ctx) return res, err }) - return res.(*MethodStreamingPayload), rCtx, err + return res.(*MethodStreamingPayload), info.ReturnContext, err }, stream: stream, }, nil @@ -83,13 +81,12 @@ func wrapClientMethodLogging(endpoint goa.Endpoint, i ClientInterceptors) goa.En CallType: goa.InterceptorStreamingSend, RawPayload: req, } - var rCtx context.Context _, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, error) { var err error - rCtx, err = stream.SendWithContext(ctx, req.(*MethodStreamingPayload)) + info.ReturnContext, err = stream.SendWithContext(ctx, req.(*MethodStreamingPayload)) return nil, err }) - return rCtx, err + return info.ReturnContext, err }, recvWithContext: func(ctx context.Context) (*MethodResult, context.Context, error) { info := &LoggingInfo{ @@ -98,16 +95,15 @@ func wrapClientMethodLogging(endpoint goa.Endpoint, i ClientInterceptors) goa.En CallType: goa.InterceptorStreamingRecv, RawPayload: req, } - var rCtx context.Context res, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, error) { var ( res *MethodResult err error ) - res, rCtx, err = stream.RecvWithContext(ctx) + res, info.ReturnContext, err = stream.RecvWithContext(ctx) return res, err }) - return res.(*MethodResult), rCtx, err + return res.(*MethodResult), info.ReturnContext, err }, stream: stream, }, nil diff --git a/pkg/interceptor.go b/pkg/interceptor.go index f3e7e900e4..0f97e233b9 100644 --- a/pkg/interceptor.go +++ b/pkg/interceptor.go @@ -1,5 +1,7 @@ package goa +import "context" + type ( // InterceptorInfo contains information about the request shared between // all interceptors in the service chain. It provides access to the service name, @@ -12,6 +14,8 @@ type ( Method string // CallType is the type of call the interceptor is handling CallType InterceptorCallType + // ReturnContext is the context returned by the interceptor for streaming calls + ReturnContext context.Context // Payload of request RawPayload any } From 3161e0bcde47a10d9f4c4b3e491cdfba7a13e999 Mon Sep 17 00:00:00 2001 From: Douglas Thrift Date: Tue, 4 Feb 2025 15:07:09 -0800 Subject: [PATCH 17/23] Scrap ReturnContext field in favor of changing the interceptor interface to return a context itself --- .../client_interceptor_wrappers.go.tpl | 35 ++++++++----------- .../templates/client_interceptors.go.tpl | 2 +- .../service/templates/client_wrappers.go.tpl | 11 ++++-- .../templates/endpoint_wrappers.go.tpl | 11 ++++-- .../server_interceptor_wrappers.go.tpl | 35 ++++++++----------- .../templates/server_interceptors.go.tpl | 4 +-- .../templates/service_interceptor.go.tpl | 0 pkg/interceptor.go | 7 ++-- 8 files changed, 56 insertions(+), 49 deletions(-) delete mode 100644 codegen/service/templates/service_interceptor.go.tpl diff --git a/codegen/service/templates/client_interceptor_wrappers.go.tpl b/codegen/service/templates/client_interceptor_wrappers.go.tpl index 5241a9edcf..0313b257d5 100644 --- a/codegen/service/templates/client_interceptor_wrappers.go.tpl +++ b/codegen/service/templates/client_interceptor_wrappers.go.tpl @@ -3,8 +3,8 @@ {{- range .Methods }} {{ comment (printf "wrapClient%s%s applies the %s client interceptor to endpoints." $interceptor.Name .MethodName $interceptor.DesignName) }} -func wrapClient{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { - return func(ctx context.Context, req any) (any, error) { +func wrapClient{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { + return func(ctx context.Context, req any) (any, context.Context, error) { {{- if or $interceptor.HasStreamingPayloadAccess $interceptor.HasStreamingResultAccess }} {{- if $interceptor.HasPayloadAccess }} info := &{{ $interceptor.Name }}Info{ @@ -13,12 +13,12 @@ func wrapClient{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i CallType: goa.InterceptorUnary, RawPayload: req, } - res, err := i.{{ $interceptor.Name }}(ctx, info, endpoint) + res, ctx, err := i.{{ $interceptor.Name }}(ctx, info, endpoint) {{- else }} - res, err := endpoint(ctx, req) + res, ctx, err := endpoint(ctx, req) {{- end }} if err != nil { - return nil, err + return res, ctx, err } stream := res.({{ .ClientStream.Interface }}) return &wrapped{{ .ClientStream.Interface }}{ @@ -31,12 +31,12 @@ func wrapClient{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i CallType: goa.InterceptorStreamingSend, RawPayload: req, } - _, err := i.{{ $interceptor.Name }}(ctx, info, func(ctx context.Context, req any) (any, error) { - var err error - info.ReturnContext, err = stream.{{ .ClientStream.SendWithContextName }}(ctx, req.({{ .ClientStream.SendTypeRef }})) - return nil, err + _, ctx, err := i.{{ $interceptor.Name }}(ctx, info, func(ctx context.Context, req any) (any, context.Context, error) { + castReq, _ := req.({{ .ClientStream.SendTypeRef }}) + ctx, err = stream.{{ .ClientStream.SendWithContextName }}(ctx, castReq) + return nil, ctx, err }) - return info.ReturnContext, err + return ctx, err }, {{- end }} {{- if $interceptor.HasStreamingResultAccess }} @@ -45,21 +45,16 @@ func wrapClient{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i Service: "{{ $.Service }}", Method: "{{ .MethodName }}", CallType: goa.InterceptorStreamingRecv, - RawPayload: req, } - res, err := i.{{ $interceptor.Name }}(ctx, info, func(ctx context.Context, req any) (any, error) { - var ( - res {{ .ClientStream.RecvTypeRef }} - err error - ) - res, info.ReturnContext, err = stream.{{ .ClientStream.RecvWithContextName }}(ctx) - return res, err + res, ctx, err := i.{{ $interceptor.Name }}(ctx, info, func(ctx context.Context, _ any) (any, context.Context, error) { + return stream.{{ .ClientStream.RecvWithContextName }}(ctx) }) - return res.({{ .ClientStream.RecvTypeRef }}), info.ReturnContext, err + castRes, _ := res.({{ .ClientStream.RecvTypeRef }}) + return castRes, ctx, err }, {{- end }} stream: stream, - }, nil + }, ctx, nil {{- else }} info := &{{ $interceptor.Name }}Info{ Service: "{{ $.Service }}", diff --git a/codegen/service/templates/client_interceptors.go.tpl b/codegen/service/templates/client_interceptors.go.tpl index 9528e3d123..8c4ea5432e 100644 --- a/codegen/service/templates/client_interceptors.go.tpl +++ b/codegen/service/templates/client_interceptors.go.tpl @@ -7,6 +7,6 @@ type ClientInterceptors interface { {{- if .Description }} {{ comment .Description }} {{- end }} - {{ .Name }}(ctx context.Context, info *{{ .Name }}Info, next goa.Endpoint) (any, error) + {{ .Name }}(ctx context.Context, info *{{ .Name }}Info, next goa.InterceptorEndpoint) (any, context.Context, error) {{- end }} } diff --git a/codegen/service/templates/client_wrappers.go.tpl b/codegen/service/templates/client_wrappers.go.tpl index 9287d25b35..683d1f3b49 100644 --- a/codegen/service/templates/client_wrappers.go.tpl +++ b/codegen/service/templates/client_wrappers.go.tpl @@ -1,8 +1,15 @@ {{ comment (printf "Wrap%sClientEndpoint wraps the %s endpoint with the client interceptors defined in the design." .MethodVarName .Method) }} func Wrap{{ .MethodVarName }}ClientEndpoint(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { + var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { + response, err := endpoint(ctx, request) + return response, ctx, err + } {{- range .Interceptors }} - endpoint = wrapClient{{ $.MethodVarName }}{{ . }}(endpoint, i) + interceptorEndpoint = wrapClient{{ $.MethodVarName }}{{ . }}(interceptorEndpoint, i) {{- end }} - return endpoint + return func(ctx context.Context, request any) (any, error) { + response, _, err := interceptorEndpoint(ctx, request) + return response, err + } } diff --git a/codegen/service/templates/endpoint_wrappers.go.tpl b/codegen/service/templates/endpoint_wrappers.go.tpl index deffd14fc9..27c2e8264b 100644 --- a/codegen/service/templates/endpoint_wrappers.go.tpl +++ b/codegen/service/templates/endpoint_wrappers.go.tpl @@ -1,7 +1,14 @@ {{ comment (printf "Wrap%sEndpoint wraps the %s endpoint with the server-side interceptors defined in the design." .MethodVarName .Method) }} func Wrap{{ .MethodVarName }}Endpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { + var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { + response, err := endpoint(ctx, request) + return response, ctx, err + } {{- range .Interceptors }} - endpoint = wrap{{ $.MethodVarName }}{{ . }}(endpoint, i) + interceptorEndpoint = wrap{{ $.MethodVarName }}{{ . }}(interceptorEndpoint, i) {{- end }} - return endpoint + return func(ctx context.Context, request any) (any, error) { + response, _, err := interceptorEndpoint(ctx, request) + return response, err + } } diff --git a/codegen/service/templates/server_interceptor_wrappers.go.tpl b/codegen/service/templates/server_interceptor_wrappers.go.tpl index b319db7187..5bbb24f3e1 100644 --- a/codegen/service/templates/server_interceptor_wrappers.go.tpl +++ b/codegen/service/templates/server_interceptor_wrappers.go.tpl @@ -3,8 +3,8 @@ {{- range .Methods }} {{ comment (printf "wrap%s%s applies the %s server interceptor to endpoints." $interceptor.Name .MethodName $interceptor.DesignName) }} -func wrap{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - return func(ctx context.Context, req any) (any, error) { +func wrap{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { + return func(ctx context.Context, req any) (any, context.Context, error) { {{- if or $interceptor.HasStreamingPayloadAccess $interceptor.HasStreamingResultAccess }} {{- if $interceptor.HasPayloadAccess }} info := &{{ $interceptor.Name }}Info{ @@ -13,12 +13,12 @@ func wrap{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i Serve CallType: goa.InterceptorUnary, RawPayload: req, } - res, err := i.{{ $interceptor.Name }}(ctx, info, endpoint) + res, ctx, err := i.{{ $interceptor.Name }}(ctx, info, endpoint) {{- else }} - res, err := endpoint(ctx, req) + res, ctx, err := endpoint(ctx, req) {{- end }} if err != nil { - return nil, err + return res, ctx, err } stream := res.({{ .ServerStream.Interface }}) return &wrapped{{ .ServerStream.Interface }}{ @@ -31,12 +31,12 @@ func wrap{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i Serve CallType: goa.InterceptorStreamingSend, RawPayload: req, } - _, err := i.{{ $interceptor.Name }}(ctx, info, func(ctx context.Context, req any) (any, error) { - var err error - info.ReturnContext, err = stream.{{ .ServerStream.SendWithContextName }}(ctx, req.({{ .ServerStream.SendTypeRef }})) - return nil, err + _, ctx, err := i.{{ $interceptor.Name }}(ctx, info, func(ctx context.Context, req any) (any, context.Context, error) { + castReq, _ := req.({{ .ServerStream.SendTypeRef }}) + ctx, err := stream.{{ .ServerStream.SendWithContextName }}(ctx, castReq) + return nil, ctx, err }) - return info.ReturnContext, err + return ctx, err }, {{- end }} {{- if $interceptor.HasStreamingPayloadAccess }} @@ -45,21 +45,16 @@ func wrap{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i Serve Service: "{{ $.Service }}", Method: "{{ .MethodName }}", CallType: goa.InterceptorStreamingRecv, - RawPayload: req, } - res, err := i.{{ $interceptor.Name }}(ctx, info, func(ctx context.Context, req any) (any, error) { - var ( - res {{ .ServerStream.RecvTypeRef }} - err error - ) - res, info.ReturnContext, err = stream.{{ .ServerStream.RecvWithContextName }}(ctx) - return res, err + res, ctx, err := i.{{ $interceptor.Name }}(ctx, info, func(ctx context.Context, _ any) (any, context.Context, error) { + return stream.{{ .ServerStream.RecvWithContextName }}(ctx) }) - return res.({{ .ServerStream.RecvTypeRef }}), info.ReturnContext, err + castRes, _ := res.({{ .ServerStream.RecvTypeRef }}) + return castRes, ctx, err }, {{- end }} stream: stream, - }, nil + }, ctx, nil {{- else }} info := &{{ $interceptor.Name }}Info{ Service: "{{ $.Service }}", diff --git a/codegen/service/templates/server_interceptors.go.tpl b/codegen/service/templates/server_interceptors.go.tpl index cdfb9287ec..e5d869622e 100644 --- a/codegen/service/templates/server_interceptors.go.tpl +++ b/codegen/service/templates/server_interceptors.go.tpl @@ -7,6 +7,6 @@ type ServerInterceptors interface { {{- if .Description }} {{ comment .Description }} {{- end }} - {{ .Name }}(ctx context.Context, info *{{ .Name }}Info, next goa.Endpoint) (any, error) + {{ .Name }}(ctx context.Context, info *{{ .Name }}Info, next goa.InterceptorEndpoint) (any, context.Context, error) {{- end }} -} \ No newline at end of file +} diff --git a/codegen/service/templates/service_interceptor.go.tpl b/codegen/service/templates/service_interceptor.go.tpl deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/pkg/interceptor.go b/pkg/interceptor.go index 0f97e233b9..368d9efd92 100644 --- a/pkg/interceptor.go +++ b/pkg/interceptor.go @@ -14,12 +14,15 @@ type ( Method string // CallType is the type of call the interceptor is handling CallType InterceptorCallType - // ReturnContext is the context returned by the interceptor for streaming calls - ReturnContext context.Context // Payload of request RawPayload any } + // InterceptorEndpoint is the endpoint function interface that interceptors call. It differs from the + // Endpoint function interface in that it also returns a context that allows streaming interceptors to + // return a context to the SendWithContext or RecvWithContext methods. + InterceptorEndpoint func(ctx context.Context, request any) (response any, returnCtx context.Context, err error) + // InterceptorCallType is the type of call the interceptor is handling InterceptorCallType int ) From 6a734fea355dfddbc3ccbd22272e0ec1fe2ed8de Mon Sep 17 00:00:00 2001 From: Douglas Thrift Date: Tue, 4 Feb 2025 15:11:26 -0800 Subject: [PATCH 18/23] Update Golden files to make the Interceptor tests happy again --- ...read-payload_client_interceptors.go.golden | 13 +++- ...ead-payload_interceptor_wrappers.go.golden | 8 +- ...ead-payload_service_interceptors.go.golden | 13 +++- ...-read-result_client_interceptors.go.golden | 13 +++- ...read-result_interceptor_wrappers.go.golden | 8 +- ...read-result_service_interceptors.go.golden | 13 +++- ...rite-payload_client_interceptors.go.golden | 13 +++- ...ite-payload_interceptor_wrappers.go.golden | 8 +- ...ite-payload_service_interceptors.go.golden | 13 +++- ...write-result_client_interceptors.go.golden | 13 +++- ...rite-result_interceptor_wrappers.go.golden | 8 +- ...rite-result_service_interceptors.go.golden | 13 +++- ...rite-payload_client_interceptors.go.golden | 13 +++- ...ite-payload_interceptor_wrappers.go.golden | 8 +- ...ite-payload_service_interceptors.go.golden | 13 +++- ...write-result_client_interceptors.go.golden | 13 +++- ...rite-result_interceptor_wrappers.go.golden | 8 +- ...rite-result_service_interceptors.go.golden | 13 +++- ...interceptors_client_interceptors.go.golden | 17 ++-- ...nterceptors_interceptor_wrappers.go.golden | 16 ++-- ...nterceptors_service_interceptors.go.golden | 17 ++-- ...interceptor_interceptor_wrappers.go.golden | 8 +- ...interceptor_service_interceptors.go.golden | 24 ++++-- ...-interceptor_client_interceptors.go.golden | 13 +++- ...interceptor_interceptor_wrappers.go.golden | 4 +- ...interceptor_interceptor_wrappers.go.golden | 4 +- ...interceptor_service_interceptors.go.golden | 13 +++- ...interceptor_interceptor_wrappers.go.golden | 8 +- ...interceptor_service_interceptors.go.golden | 24 ++++-- ...ming-payload_client_interceptors.go.golden | 13 +++- ...ing-payload_interceptor_wrappers.go.golden | 49 ++++++------ ...ing-payload_service_interceptors.go.golden | 13 +++- ...ead-payload_interceptor_wrappers.go.golden | 4 +- ...ead-payload_service_interceptors.go.golden | 13 +++- ...read-result_interceptor_wrappers.go.golden | 4 +- ...read-result_service_interceptors.go.golden | 13 +++- ...aming-result_client_interceptors.go.golden | 13 +++- ...ming-result_interceptor_wrappers.go.golden | 49 ++++++------ ...ming-result_service_interceptors.go.golden | 13 +++- ...interceptors_client_interceptors.go.golden | 13 +++- ...nterceptors_interceptor_wrappers.go.golden | 78 ++++++++----------- ...nterceptors_service_interceptors.go.golden | 13 +++- 42 files changed, 408 insertions(+), 232 deletions(-) diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-payload_client_interceptors.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-payload_client_interceptors.go.golden index 5b21e6d339..3c2f41b687 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-payload_client_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-payload_client_interceptors.go.golden @@ -3,12 +3,19 @@ // is sent to the server. The implementation is responsible for calling next to // complete the request. type ClientInterceptors interface { - Validation(ctx context.Context, info *ValidationInfo, next goa.Endpoint) (any, error) + Validation(ctx context.Context, info *ValidationInfo, next goa.InterceptorEndpoint) (any, context.Context, error) } // WrapMethodClientEndpoint wraps the Method endpoint with the client // interceptors defined in the design. func WrapMethodClientEndpoint(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { - endpoint = wrapClientMethodvalidation(endpoint, i) - return endpoint + var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { + response, err := endpoint(ctx, request) + return response, ctx, err + } + interceptorEndpoint = wrapClientMethodvalidation(interceptorEndpoint, i) + return func(ctx context.Context, request any) (any, error) { + response, _, err := interceptorEndpoint(ctx, request) + return response, err + } } diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-payload_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-payload_interceptor_wrappers.go.golden index 62b7947564..7c27d0db47 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-payload_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-payload_interceptor_wrappers.go.golden @@ -1,8 +1,8 @@ // wrapValidationMethod applies the validation server interceptor to endpoints. -func wrapMethodValidation(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - return func(ctx context.Context, req any) (any, error) { +func wrapMethodValidation(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { + return func(ctx context.Context, req any) (any, context.Context, error) { info := &ValidationInfo{ Service: "InterceptorWithReadPayload", Method: "Method", @@ -15,8 +15,8 @@ func wrapMethodValidation(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpo // wrapClientValidationMethod applies the validation client interceptor to // endpoints. -func wrapClientMethodValidation(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { - return func(ctx context.Context, req any) (any, error) { +func wrapClientMethodValidation(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { + return func(ctx context.Context, req any) (any, context.Context, error) { info := &ValidationInfo{ Service: "InterceptorWithReadPayload", Method: "Method", diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-payload_service_interceptors.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-payload_service_interceptors.go.golden index 7e616c9438..1873bd5f0e 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-payload_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-payload_service_interceptors.go.golden @@ -3,7 +3,7 @@ // payload is sent to the service. The implementation is responsible for calling // next to complete the request. type ServerInterceptors interface { - Validation(ctx context.Context, info *ValidationInfo, next goa.Endpoint) (any, error) + Validation(ctx context.Context, info *ValidationInfo, next goa.InterceptorEndpoint) (any, context.Context, error) } // Access interfaces for interceptor payloads and results @@ -30,8 +30,15 @@ type ( // WrapMethodEndpoint wraps the Method endpoint with the server-side // interceptors defined in the design. func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - endpoint = wrapMethodvalidation(endpoint, i) - return endpoint + var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { + response, err := endpoint(ctx, request) + return response, ctx, err + } + interceptorEndpoint = wrapMethodvalidation(interceptorEndpoint, i) + return func(ctx context.Context, request any) (any, error) { + response, _, err := interceptorEndpoint(ctx, request) + return response, err + } } // Public accessor methods for Info types diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-result_client_interceptors.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-result_client_interceptors.go.golden index 7bf0271866..91c9e06107 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-result_client_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-result_client_interceptors.go.golden @@ -3,12 +3,19 @@ // is sent to the server. The implementation is responsible for calling next to // complete the request. type ClientInterceptors interface { - Caching(ctx context.Context, info *CachingInfo, next goa.Endpoint) (any, error) + Caching(ctx context.Context, info *CachingInfo, next goa.InterceptorEndpoint) (any, context.Context, error) } // WrapMethodClientEndpoint wraps the Method endpoint with the client // interceptors defined in the design. func WrapMethodClientEndpoint(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { - endpoint = wrapClientMethodcaching(endpoint, i) - return endpoint + var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { + response, err := endpoint(ctx, request) + return response, ctx, err + } + interceptorEndpoint = wrapClientMethodcaching(interceptorEndpoint, i) + return func(ctx context.Context, request any) (any, error) { + response, _, err := interceptorEndpoint(ctx, request) + return response, err + } } diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-result_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-result_interceptor_wrappers.go.golden index 14820fd7c9..4cdb85e8a6 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-result_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-result_interceptor_wrappers.go.golden @@ -1,8 +1,8 @@ // wrapCachingMethod applies the caching server interceptor to endpoints. -func wrapMethodCaching(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - return func(ctx context.Context, req any) (any, error) { +func wrapMethodCaching(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { + return func(ctx context.Context, req any) (any, context.Context, error) { info := &CachingInfo{ Service: "InterceptorWithReadResult", Method: "Method", @@ -14,8 +14,8 @@ func wrapMethodCaching(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint } // wrapClientCachingMethod applies the caching client interceptor to endpoints. -func wrapClientMethodCaching(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { - return func(ctx context.Context, req any) (any, error) { +func wrapClientMethodCaching(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { + return func(ctx context.Context, req any) (any, context.Context, error) { info := &CachingInfo{ Service: "InterceptorWithReadResult", Method: "Method", diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-result_service_interceptors.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-result_service_interceptors.go.golden index a658f22d37..b0f6ee9482 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-result_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-result_service_interceptors.go.golden @@ -3,7 +3,7 @@ // payload is sent to the service. The implementation is responsible for calling // next to complete the request. type ServerInterceptors interface { - Caching(ctx context.Context, info *CachingInfo, next goa.Endpoint) (any, error) + Caching(ctx context.Context, info *CachingInfo, next goa.InterceptorEndpoint) (any, context.Context, error) } // Access interfaces for interceptor payloads and results @@ -30,8 +30,15 @@ type ( // WrapMethodEndpoint wraps the Method endpoint with the server-side // interceptors defined in the design. func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - endpoint = wrapMethodcaching(endpoint, i) - return endpoint + var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { + response, err := endpoint(ctx, request) + return response, ctx, err + } + interceptorEndpoint = wrapMethodcaching(interceptorEndpoint, i) + return func(ctx context.Context, request any) (any, error) { + response, _, err := interceptorEndpoint(ctx, request) + return response, err + } } // Public accessor methods for Info types diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_client_interceptors.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_client_interceptors.go.golden index 5b21e6d339..3c2f41b687 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_client_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_client_interceptors.go.golden @@ -3,12 +3,19 @@ // is sent to the server. The implementation is responsible for calling next to // complete the request. type ClientInterceptors interface { - Validation(ctx context.Context, info *ValidationInfo, next goa.Endpoint) (any, error) + Validation(ctx context.Context, info *ValidationInfo, next goa.InterceptorEndpoint) (any, context.Context, error) } // WrapMethodClientEndpoint wraps the Method endpoint with the client // interceptors defined in the design. func WrapMethodClientEndpoint(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { - endpoint = wrapClientMethodvalidation(endpoint, i) - return endpoint + var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { + response, err := endpoint(ctx, request) + return response, ctx, err + } + interceptorEndpoint = wrapClientMethodvalidation(interceptorEndpoint, i) + return func(ctx context.Context, request any) (any, error) { + response, _, err := interceptorEndpoint(ctx, request) + return response, err + } } diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_interceptor_wrappers.go.golden index 979a7f79bd..823c286e18 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_interceptor_wrappers.go.golden @@ -1,8 +1,8 @@ // wrapValidationMethod applies the validation server interceptor to endpoints. -func wrapMethodValidation(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - return func(ctx context.Context, req any) (any, error) { +func wrapMethodValidation(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { + return func(ctx context.Context, req any) (any, context.Context, error) { info := &ValidationInfo{ Service: "InterceptorWithReadWritePayload", Method: "Method", @@ -15,8 +15,8 @@ func wrapMethodValidation(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpo // wrapClientValidationMethod applies the validation client interceptor to // endpoints. -func wrapClientMethodValidation(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { - return func(ctx context.Context, req any) (any, error) { +func wrapClientMethodValidation(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { + return func(ctx context.Context, req any) (any, context.Context, error) { info := &ValidationInfo{ Service: "InterceptorWithReadWritePayload", Method: "Method", diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_service_interceptors.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_service_interceptors.go.golden index 0f84e22320..ef6b6cc357 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_service_interceptors.go.golden @@ -3,7 +3,7 @@ // payload is sent to the service. The implementation is responsible for calling // next to complete the request. type ServerInterceptors interface { - Validation(ctx context.Context, info *ValidationInfo, next goa.Endpoint) (any, error) + Validation(ctx context.Context, info *ValidationInfo, next goa.InterceptorEndpoint) (any, context.Context, error) } // Access interfaces for interceptor payloads and results @@ -31,8 +31,15 @@ type ( // WrapMethodEndpoint wraps the Method endpoint with the server-side // interceptors defined in the design. func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - endpoint = wrapMethodvalidation(endpoint, i) - return endpoint + var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { + response, err := endpoint(ctx, request) + return response, ctx, err + } + interceptorEndpoint = wrapMethodvalidation(interceptorEndpoint, i) + return func(ctx context.Context, request any) (any, error) { + response, _, err := interceptorEndpoint(ctx, request) + return response, err + } } // Public accessor methods for Info types diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-write-result_client_interceptors.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-write-result_client_interceptors.go.golden index 7bf0271866..91c9e06107 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-write-result_client_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-write-result_client_interceptors.go.golden @@ -3,12 +3,19 @@ // is sent to the server. The implementation is responsible for calling next to // complete the request. type ClientInterceptors interface { - Caching(ctx context.Context, info *CachingInfo, next goa.Endpoint) (any, error) + Caching(ctx context.Context, info *CachingInfo, next goa.InterceptorEndpoint) (any, context.Context, error) } // WrapMethodClientEndpoint wraps the Method endpoint with the client // interceptors defined in the design. func WrapMethodClientEndpoint(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { - endpoint = wrapClientMethodcaching(endpoint, i) - return endpoint + var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { + response, err := endpoint(ctx, request) + return response, ctx, err + } + interceptorEndpoint = wrapClientMethodcaching(interceptorEndpoint, i) + return func(ctx context.Context, request any) (any, error) { + response, _, err := interceptorEndpoint(ctx, request) + return response, err + } } diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-write-result_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-write-result_interceptor_wrappers.go.golden index cb20d1cb5f..74c50e35aa 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-write-result_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-write-result_interceptor_wrappers.go.golden @@ -1,8 +1,8 @@ // wrapCachingMethod applies the caching server interceptor to endpoints. -func wrapMethodCaching(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - return func(ctx context.Context, req any) (any, error) { +func wrapMethodCaching(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { + return func(ctx context.Context, req any) (any, context.Context, error) { info := &CachingInfo{ Service: "InterceptorWithReadWriteResult", Method: "Method", @@ -14,8 +14,8 @@ func wrapMethodCaching(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint } // wrapClientCachingMethod applies the caching client interceptor to endpoints. -func wrapClientMethodCaching(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { - return func(ctx context.Context, req any) (any, error) { +func wrapClientMethodCaching(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { + return func(ctx context.Context, req any) (any, context.Context, error) { info := &CachingInfo{ Service: "InterceptorWithReadWriteResult", Method: "Method", diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-write-result_service_interceptors.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-write-result_service_interceptors.go.golden index 96c934c24e..572f287895 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-write-result_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-write-result_service_interceptors.go.golden @@ -3,7 +3,7 @@ // payload is sent to the service. The implementation is responsible for calling // next to complete the request. type ServerInterceptors interface { - Caching(ctx context.Context, info *CachingInfo, next goa.Endpoint) (any, error) + Caching(ctx context.Context, info *CachingInfo, next goa.InterceptorEndpoint) (any, context.Context, error) } // Access interfaces for interceptor payloads and results @@ -31,8 +31,15 @@ type ( // WrapMethodEndpoint wraps the Method endpoint with the server-side // interceptors defined in the design. func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - endpoint = wrapMethodcaching(endpoint, i) - return endpoint + var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { + response, err := endpoint(ctx, request) + return response, ctx, err + } + interceptorEndpoint = wrapMethodcaching(interceptorEndpoint, i) + return func(ctx context.Context, request any) (any, error) { + response, _, err := interceptorEndpoint(ctx, request) + return response, err + } } // Public accessor methods for Info types diff --git a/codegen/service/testdata/interceptors/interceptor-with-write-payload_client_interceptors.go.golden b/codegen/service/testdata/interceptors/interceptor-with-write-payload_client_interceptors.go.golden index 5b21e6d339..3c2f41b687 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-write-payload_client_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-write-payload_client_interceptors.go.golden @@ -3,12 +3,19 @@ // is sent to the server. The implementation is responsible for calling next to // complete the request. type ClientInterceptors interface { - Validation(ctx context.Context, info *ValidationInfo, next goa.Endpoint) (any, error) + Validation(ctx context.Context, info *ValidationInfo, next goa.InterceptorEndpoint) (any, context.Context, error) } // WrapMethodClientEndpoint wraps the Method endpoint with the client // interceptors defined in the design. func WrapMethodClientEndpoint(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { - endpoint = wrapClientMethodvalidation(endpoint, i) - return endpoint + var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { + response, err := endpoint(ctx, request) + return response, ctx, err + } + interceptorEndpoint = wrapClientMethodvalidation(interceptorEndpoint, i) + return func(ctx context.Context, request any) (any, error) { + response, _, err := interceptorEndpoint(ctx, request) + return response, err + } } diff --git a/codegen/service/testdata/interceptors/interceptor-with-write-payload_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/interceptor-with-write-payload_interceptor_wrappers.go.golden index b7e7c3bcd3..05f76f2420 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-write-payload_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-write-payload_interceptor_wrappers.go.golden @@ -1,8 +1,8 @@ // wrapValidationMethod applies the validation server interceptor to endpoints. -func wrapMethodValidation(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - return func(ctx context.Context, req any) (any, error) { +func wrapMethodValidation(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { + return func(ctx context.Context, req any) (any, context.Context, error) { info := &ValidationInfo{ Service: "InterceptorWithWritePayload", Method: "Method", @@ -15,8 +15,8 @@ func wrapMethodValidation(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpo // wrapClientValidationMethod applies the validation client interceptor to // endpoints. -func wrapClientMethodValidation(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { - return func(ctx context.Context, req any) (any, error) { +func wrapClientMethodValidation(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { + return func(ctx context.Context, req any) (any, context.Context, error) { info := &ValidationInfo{ Service: "InterceptorWithWritePayload", Method: "Method", diff --git a/codegen/service/testdata/interceptors/interceptor-with-write-payload_service_interceptors.go.golden b/codegen/service/testdata/interceptors/interceptor-with-write-payload_service_interceptors.go.golden index c76eb125e0..3fd38592ad 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-write-payload_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-write-payload_service_interceptors.go.golden @@ -3,7 +3,7 @@ // payload is sent to the service. The implementation is responsible for calling // next to complete the request. type ServerInterceptors interface { - Validation(ctx context.Context, info *ValidationInfo, next goa.Endpoint) (any, error) + Validation(ctx context.Context, info *ValidationInfo, next goa.InterceptorEndpoint) (any, context.Context, error) } // Access interfaces for interceptor payloads and results @@ -30,8 +30,15 @@ type ( // WrapMethodEndpoint wraps the Method endpoint with the server-side // interceptors defined in the design. func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - endpoint = wrapMethodvalidation(endpoint, i) - return endpoint + var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { + response, err := endpoint(ctx, request) + return response, ctx, err + } + interceptorEndpoint = wrapMethodvalidation(interceptorEndpoint, i) + return func(ctx context.Context, request any) (any, error) { + response, _, err := interceptorEndpoint(ctx, request) + return response, err + } } // Public accessor methods for Info types diff --git a/codegen/service/testdata/interceptors/interceptor-with-write-result_client_interceptors.go.golden b/codegen/service/testdata/interceptors/interceptor-with-write-result_client_interceptors.go.golden index 7bf0271866..91c9e06107 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-write-result_client_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-write-result_client_interceptors.go.golden @@ -3,12 +3,19 @@ // is sent to the server. The implementation is responsible for calling next to // complete the request. type ClientInterceptors interface { - Caching(ctx context.Context, info *CachingInfo, next goa.Endpoint) (any, error) + Caching(ctx context.Context, info *CachingInfo, next goa.InterceptorEndpoint) (any, context.Context, error) } // WrapMethodClientEndpoint wraps the Method endpoint with the client // interceptors defined in the design. func WrapMethodClientEndpoint(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { - endpoint = wrapClientMethodcaching(endpoint, i) - return endpoint + var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { + response, err := endpoint(ctx, request) + return response, ctx, err + } + interceptorEndpoint = wrapClientMethodcaching(interceptorEndpoint, i) + return func(ctx context.Context, request any) (any, error) { + response, _, err := interceptorEndpoint(ctx, request) + return response, err + } } diff --git a/codegen/service/testdata/interceptors/interceptor-with-write-result_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/interceptor-with-write-result_interceptor_wrappers.go.golden index c0cf2757b4..6d5f4afeb6 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-write-result_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-write-result_interceptor_wrappers.go.golden @@ -1,8 +1,8 @@ // wrapCachingMethod applies the caching server interceptor to endpoints. -func wrapMethodCaching(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - return func(ctx context.Context, req any) (any, error) { +func wrapMethodCaching(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { + return func(ctx context.Context, req any) (any, context.Context, error) { info := &CachingInfo{ Service: "InterceptorWithWriteResult", Method: "Method", @@ -14,8 +14,8 @@ func wrapMethodCaching(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint } // wrapClientCachingMethod applies the caching client interceptor to endpoints. -func wrapClientMethodCaching(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { - return func(ctx context.Context, req any) (any, error) { +func wrapClientMethodCaching(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { + return func(ctx context.Context, req any) (any, context.Context, error) { info := &CachingInfo{ Service: "InterceptorWithWriteResult", Method: "Method", diff --git a/codegen/service/testdata/interceptors/interceptor-with-write-result_service_interceptors.go.golden b/codegen/service/testdata/interceptors/interceptor-with-write-result_service_interceptors.go.golden index 26b2620a97..b3c44eafe5 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-write-result_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-write-result_service_interceptors.go.golden @@ -3,7 +3,7 @@ // payload is sent to the service. The implementation is responsible for calling // next to complete the request. type ServerInterceptors interface { - Caching(ctx context.Context, info *CachingInfo, next goa.Endpoint) (any, error) + Caching(ctx context.Context, info *CachingInfo, next goa.InterceptorEndpoint) (any, context.Context, error) } // Access interfaces for interceptor payloads and results @@ -30,8 +30,15 @@ type ( // WrapMethodEndpoint wraps the Method endpoint with the server-side // interceptors defined in the design. func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - endpoint = wrapMethodcaching(endpoint, i) - return endpoint + var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { + response, err := endpoint(ctx, request) + return response, ctx, err + } + interceptorEndpoint = wrapMethodcaching(interceptorEndpoint, i) + return func(ctx context.Context, request any) (any, error) { + response, _, err := interceptorEndpoint(ctx, request) + return response, err + } } // Public accessor methods for Info types diff --git a/codegen/service/testdata/interceptors/multiple-interceptors_client_interceptors.go.golden b/codegen/service/testdata/interceptors/multiple-interceptors_client_interceptors.go.golden index 00d3b74592..a1df7e470b 100644 --- a/codegen/service/testdata/interceptors/multiple-interceptors_client_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/multiple-interceptors_client_interceptors.go.golden @@ -3,8 +3,8 @@ // is sent to the server. The implementation is responsible for calling next to // complete the request. type ClientInterceptors interface { - Test2(ctx context.Context, info *Test2Info, next goa.Endpoint) (any, error) - Test4(ctx context.Context, info *Test4Info, next goa.Endpoint) (any, error) + Test2(ctx context.Context, info *Test2Info, next goa.InterceptorEndpoint) (any, context.Context, error) + Test4(ctx context.Context, info *Test4Info, next goa.InterceptorEndpoint) (any, context.Context, error) } // Access interfaces for interceptor payloads and results @@ -20,8 +20,15 @@ type ( // WrapMethodClientEndpoint wraps the Method endpoint with the client // interceptors defined in the design. func WrapMethodClientEndpoint(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { - endpoint = wrapClientMethodtest2(endpoint, i) - endpoint = wrapClientMethodtest4(endpoint, i) - return endpoint + var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { + response, err := endpoint(ctx, request) + return response, ctx, err + } + interceptorEndpoint = wrapClientMethodtest2(interceptorEndpoint, i) + interceptorEndpoint = wrapClientMethodtest4(interceptorEndpoint, i) + return func(ctx context.Context, request any) (any, error) { + response, _, err := interceptorEndpoint(ctx, request) + return response, err + } } diff --git a/codegen/service/testdata/interceptors/multiple-interceptors_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/multiple-interceptors_interceptor_wrappers.go.golden index 5b98169284..9fb3e9dbd6 100644 --- a/codegen/service/testdata/interceptors/multiple-interceptors_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/multiple-interceptors_interceptor_wrappers.go.golden @@ -1,8 +1,8 @@ // wrapTestMethod applies the test server interceptor to endpoints. -func wrapMethodTest(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - return func(ctx context.Context, req any) (any, error) { +func wrapMethodTest(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { + return func(ctx context.Context, req any) (any, context.Context, error) { info := &TestInfo{ Service: "MultipleInterceptorsService", Method: "Method", @@ -14,8 +14,8 @@ func wrapMethodTest(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { } // wrapTest3Method applies the test3 server interceptor to endpoints. -func wrapMethodTest3(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - return func(ctx context.Context, req any) (any, error) { +func wrapMethodTest3(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { + return func(ctx context.Context, req any) (any, context.Context, error) { info := &Test3Info{ Service: "MultipleInterceptorsService", Method: "Method", @@ -27,8 +27,8 @@ func wrapMethodTest3(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { } // wrapClientTest2Method applies the test2 client interceptor to endpoints. -func wrapClientMethodTest2(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { - return func(ctx context.Context, req any) (any, error) { +func wrapClientMethodTest2(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { + return func(ctx context.Context, req any) (any, context.Context, error) { info := &Test2Info{ Service: "MultipleInterceptorsService", Method: "Method", @@ -40,8 +40,8 @@ func wrapClientMethodTest2(endpoint goa.Endpoint, i ClientInterceptors) goa.Endp } // wrapClientTest4Method applies the test4 client interceptor to endpoints. -func wrapClientMethodTest4(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { - return func(ctx context.Context, req any) (any, error) { +func wrapClientMethodTest4(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { + return func(ctx context.Context, req any) (any, context.Context, error) { info := &Test4Info{ Service: "MultipleInterceptorsService", Method: "Method", diff --git a/codegen/service/testdata/interceptors/multiple-interceptors_service_interceptors.go.golden b/codegen/service/testdata/interceptors/multiple-interceptors_service_interceptors.go.golden index 1df6e00cf8..66db059d49 100644 --- a/codegen/service/testdata/interceptors/multiple-interceptors_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/multiple-interceptors_service_interceptors.go.golden @@ -3,8 +3,8 @@ // payload is sent to the service. The implementation is responsible for calling // next to complete the request. type ServerInterceptors interface { - Test(ctx context.Context, info *TestInfo, next goa.Endpoint) (any, error) - Test3(ctx context.Context, info *Test3Info, next goa.Endpoint) (any, error) + Test(ctx context.Context, info *TestInfo, next goa.InterceptorEndpoint) (any, context.Context, error) + Test3(ctx context.Context, info *Test3Info, next goa.InterceptorEndpoint) (any, context.Context, error) } // Access interfaces for interceptor payloads and results @@ -20,8 +20,15 @@ type ( // WrapMethodEndpoint wraps the Method endpoint with the server-side // interceptors defined in the design. func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - endpoint = wrapMethodtest(endpoint, i) - endpoint = wrapMethodtest3(endpoint, i) - return endpoint + var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { + response, err := endpoint(ctx, request) + return response, ctx, err + } + interceptorEndpoint = wrapMethodtest(interceptorEndpoint, i) + interceptorEndpoint = wrapMethodtest3(interceptorEndpoint, i) + return func(ctx context.Context, request any) (any, error) { + response, _, err := interceptorEndpoint(ctx, request) + return response, err + } } diff --git a/codegen/service/testdata/interceptors/single-api-server-interceptor_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/single-api-server-interceptor_interceptor_wrappers.go.golden index 63149a1fe5..495fbff0df 100644 --- a/codegen/service/testdata/interceptors/single-api-server-interceptor_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/single-api-server-interceptor_interceptor_wrappers.go.golden @@ -1,8 +1,8 @@ // wrapLoggingMethod applies the logging server interceptor to endpoints. -func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - return func(ctx context.Context, req any) (any, error) { +func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { + return func(ctx context.Context, req any) (any, context.Context, error) { info := &LoggingInfo{ Service: "SingleAPIServerInterceptor", Method: "Method", @@ -14,8 +14,8 @@ func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint } // wrapLoggingMethod2 applies the logging server interceptor to endpoints. -func wrapMethod2Logging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - return func(ctx context.Context, req any) (any, error) { +func wrapMethod2Logging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { + return func(ctx context.Context, req any) (any, context.Context, error) { info := &LoggingInfo{ Service: "SingleAPIServerInterceptor", Method: "Method2", diff --git a/codegen/service/testdata/interceptors/single-api-server-interceptor_service_interceptors.go.golden b/codegen/service/testdata/interceptors/single-api-server-interceptor_service_interceptors.go.golden index f4870a7eef..47c50507e4 100644 --- a/codegen/service/testdata/interceptors/single-api-server-interceptor_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/single-api-server-interceptor_service_interceptors.go.golden @@ -3,7 +3,7 @@ // payload is sent to the service. The implementation is responsible for calling // next to complete the request. type ServerInterceptors interface { - Logging(ctx context.Context, info *LoggingInfo, next goa.Endpoint) (any, error) + Logging(ctx context.Context, info *LoggingInfo, next goa.InterceptorEndpoint) (any, context.Context, error) } // Access interfaces for interceptor payloads and results @@ -16,14 +16,28 @@ type ( // WrapMethodEndpoint wraps the Method endpoint with the server-side // interceptors defined in the design. func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - endpoint = wrapMethodlogging(endpoint, i) - return endpoint + var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { + response, err := endpoint(ctx, request) + return response, ctx, err + } + interceptorEndpoint = wrapMethodlogging(interceptorEndpoint, i) + return func(ctx context.Context, request any) (any, error) { + response, _, err := interceptorEndpoint(ctx, request) + return response, err + } } // WrapMethod2Endpoint wraps the Method2 endpoint with the server-side // interceptors defined in the design. func WrapMethod2Endpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - endpoint = wrapMethod2logging(endpoint, i) - return endpoint + var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { + response, err := endpoint(ctx, request) + return response, ctx, err + } + interceptorEndpoint = wrapMethod2logging(interceptorEndpoint, i) + return func(ctx context.Context, request any) (any, error) { + response, _, err := interceptorEndpoint(ctx, request) + return response, err + } } diff --git a/codegen/service/testdata/interceptors/single-client-interceptor_client_interceptors.go.golden b/codegen/service/testdata/interceptors/single-client-interceptor_client_interceptors.go.golden index 8f272d85e6..ee25058df4 100644 --- a/codegen/service/testdata/interceptors/single-client-interceptor_client_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/single-client-interceptor_client_interceptors.go.golden @@ -3,7 +3,7 @@ // is sent to the server. The implementation is responsible for calling next to // complete the request. type ClientInterceptors interface { - Tracing(ctx context.Context, info *TracingInfo, next goa.Endpoint) (any, error) + Tracing(ctx context.Context, info *TracingInfo, next goa.InterceptorEndpoint) (any, context.Context, error) } // Access interfaces for interceptor payloads and results @@ -16,7 +16,14 @@ type ( // WrapMethodClientEndpoint wraps the Method endpoint with the client // interceptors defined in the design. func WrapMethodClientEndpoint(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { - endpoint = wrapClientMethodtracing(endpoint, i) - return endpoint + var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { + response, err := endpoint(ctx, request) + return response, ctx, err + } + interceptorEndpoint = wrapClientMethodtracing(interceptorEndpoint, i) + return func(ctx context.Context, request any) (any, error) { + response, _, err := interceptorEndpoint(ctx, request) + return response, err + } } diff --git a/codegen/service/testdata/interceptors/single-client-interceptor_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/single-client-interceptor_interceptor_wrappers.go.golden index ae1d69d550..691c0863a2 100644 --- a/codegen/service/testdata/interceptors/single-client-interceptor_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/single-client-interceptor_interceptor_wrappers.go.golden @@ -1,8 +1,8 @@ // wrapClientTracingMethod applies the tracing client interceptor to endpoints. -func wrapClientMethodTracing(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { - return func(ctx context.Context, req any) (any, error) { +func wrapClientMethodTracing(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { + return func(ctx context.Context, req any) (any, context.Context, error) { info := &TracingInfo{ Service: "SingleClientInterceptor", Method: "Method", diff --git a/codegen/service/testdata/interceptors/single-method-server-interceptor_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/single-method-server-interceptor_interceptor_wrappers.go.golden index 112499cc5a..185ae87fb4 100644 --- a/codegen/service/testdata/interceptors/single-method-server-interceptor_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/single-method-server-interceptor_interceptor_wrappers.go.golden @@ -1,8 +1,8 @@ // wrapLoggingMethod applies the logging server interceptor to endpoints. -func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - return func(ctx context.Context, req any) (any, error) { +func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { + return func(ctx context.Context, req any) (any, context.Context, error) { info := &LoggingInfo{ Service: "SingleMethodServerInterceptor", Method: "Method", diff --git a/codegen/service/testdata/interceptors/single-method-server-interceptor_service_interceptors.go.golden b/codegen/service/testdata/interceptors/single-method-server-interceptor_service_interceptors.go.golden index 58b647a34a..411e5fd142 100644 --- a/codegen/service/testdata/interceptors/single-method-server-interceptor_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/single-method-server-interceptor_service_interceptors.go.golden @@ -3,7 +3,7 @@ // payload is sent to the service. The implementation is responsible for calling // next to complete the request. type ServerInterceptors interface { - Logging(ctx context.Context, info *LoggingInfo, next goa.Endpoint) (any, error) + Logging(ctx context.Context, info *LoggingInfo, next goa.InterceptorEndpoint) (any, context.Context, error) } // Access interfaces for interceptor payloads and results @@ -16,7 +16,14 @@ type ( // WrapMethodEndpoint wraps the Method endpoint with the server-side // interceptors defined in the design. func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - endpoint = wrapMethodlogging(endpoint, i) - return endpoint + var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { + response, err := endpoint(ctx, request) + return response, ctx, err + } + interceptorEndpoint = wrapMethodlogging(interceptorEndpoint, i) + return func(ctx context.Context, request any) (any, error) { + response, _, err := interceptorEndpoint(ctx, request) + return response, err + } } diff --git a/codegen/service/testdata/interceptors/single-service-server-interceptor_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/single-service-server-interceptor_interceptor_wrappers.go.golden index 5b083b9aad..6045e2ac9d 100644 --- a/codegen/service/testdata/interceptors/single-service-server-interceptor_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/single-service-server-interceptor_interceptor_wrappers.go.golden @@ -1,8 +1,8 @@ // wrapLoggingMethod applies the logging server interceptor to endpoints. -func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - return func(ctx context.Context, req any) (any, error) { +func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { + return func(ctx context.Context, req any) (any, context.Context, error) { info := &LoggingInfo{ Service: "SingleServerInterceptor", Method: "Method", @@ -14,8 +14,8 @@ func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint } // wrapLoggingMethod2 applies the logging server interceptor to endpoints. -func wrapMethod2Logging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - return func(ctx context.Context, req any) (any, error) { +func wrapMethod2Logging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { + return func(ctx context.Context, req any) (any, context.Context, error) { info := &LoggingInfo{ Service: "SingleServerInterceptor", Method: "Method2", diff --git a/codegen/service/testdata/interceptors/single-service-server-interceptor_service_interceptors.go.golden b/codegen/service/testdata/interceptors/single-service-server-interceptor_service_interceptors.go.golden index f4870a7eef..47c50507e4 100644 --- a/codegen/service/testdata/interceptors/single-service-server-interceptor_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/single-service-server-interceptor_service_interceptors.go.golden @@ -3,7 +3,7 @@ // payload is sent to the service. The implementation is responsible for calling // next to complete the request. type ServerInterceptors interface { - Logging(ctx context.Context, info *LoggingInfo, next goa.Endpoint) (any, error) + Logging(ctx context.Context, info *LoggingInfo, next goa.InterceptorEndpoint) (any, context.Context, error) } // Access interfaces for interceptor payloads and results @@ -16,14 +16,28 @@ type ( // WrapMethodEndpoint wraps the Method endpoint with the server-side // interceptors defined in the design. func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - endpoint = wrapMethodlogging(endpoint, i) - return endpoint + var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { + response, err := endpoint(ctx, request) + return response, ctx, err + } + interceptorEndpoint = wrapMethodlogging(interceptorEndpoint, i) + return func(ctx context.Context, request any) (any, error) { + response, _, err := interceptorEndpoint(ctx, request) + return response, err + } } // WrapMethod2Endpoint wraps the Method2 endpoint with the server-side // interceptors defined in the design. func WrapMethod2Endpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - endpoint = wrapMethod2logging(endpoint, i) - return endpoint + var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { + response, err := endpoint(ctx, request) + return response, ctx, err + } + interceptorEndpoint = wrapMethod2logging(interceptorEndpoint, i) + return func(ctx context.Context, request any) (any, error) { + response, _, err := interceptorEndpoint(ctx, request) + return response, err + } } diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_client_interceptors.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_client_interceptors.go.golden index 3790fd8cde..705ce41ebc 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_client_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_client_interceptors.go.golden @@ -3,12 +3,19 @@ // is sent to the server. The implementation is responsible for calling next to // complete the request. type ClientInterceptors interface { - Logging(ctx context.Context, info *LoggingInfo, next goa.Endpoint) (any, error) + Logging(ctx context.Context, info *LoggingInfo, next goa.InterceptorEndpoint) (any, context.Context, error) } // WrapMethodClientEndpoint wraps the Method endpoint with the client // interceptors defined in the design. func WrapMethodClientEndpoint(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { - endpoint = wrapClientMethodlogging(endpoint, i) - return endpoint + var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { + response, err := endpoint(ctx, request) + return response, ctx, err + } + interceptorEndpoint = wrapClientMethodlogging(interceptorEndpoint, i) + return func(ctx context.Context, request any) (any, error) { + response, _, err := interceptorEndpoint(ctx, request) + return response, err + } } diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_interceptor_wrappers.go.golden index cffbddcd7b..1ec772951c 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_interceptor_wrappers.go.golden @@ -17,55 +17,50 @@ type wrappedMethodClientStream struct { } // wrapLoggingMethod applies the logging server interceptor to endpoints. -func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - return func(ctx context.Context, req any) (any, error) { +func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { + return func(ctx context.Context, req any) (any, context.Context, error) { info := &LoggingInfo{ Service: "StreamingInterceptorsWithReadPayloadAndReadStreamingPayload", Method: "Method", CallType: goa.InterceptorUnary, RawPayload: req, } - res, err := i.Logging(ctx, info, endpoint) + res, ctx, err := i.Logging(ctx, info, endpoint) if err != nil { - return nil, err + return res, ctx, err } stream := res.(MethodServerStream) return &wrappedMethodServerStream{ ctx: ctx, recvWithContext: func(ctx context.Context) (*MethodStreamingPayload, context.Context, error) { info := &LoggingInfo{ - Service: "StreamingInterceptorsWithReadPayloadAndReadStreamingPayload", - Method: "Method", - CallType: goa.InterceptorStreamingRecv, - RawPayload: req, + Service: "StreamingInterceptorsWithReadPayloadAndReadStreamingPayload", + Method: "Method", + CallType: goa.InterceptorStreamingRecv, } - res, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, error) { - var ( - res *MethodStreamingPayload - err error - ) - res, info.ReturnContext, err = stream.RecvWithContext(ctx) - return res, err + res, ctx, err := i.Logging(ctx, info, func(ctx context.Context, _ any) (any, context.Context, error) { + return stream.RecvWithContext(ctx) }) - return res.(*MethodStreamingPayload), info.ReturnContext, err + castRes, _ := res.(*MethodStreamingPayload) + return castRes, ctx, err }, stream: stream, - }, nil + }, ctx, nil } } // wrapClientLoggingMethod applies the logging client interceptor to endpoints. -func wrapClientMethodLogging(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { - return func(ctx context.Context, req any) (any, error) { +func wrapClientMethodLogging(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { + return func(ctx context.Context, req any) (any, context.Context, error) { info := &LoggingInfo{ Service: "StreamingInterceptorsWithReadPayloadAndReadStreamingPayload", Method: "Method", CallType: goa.InterceptorUnary, RawPayload: req, } - res, err := i.Logging(ctx, info, endpoint) + res, ctx, err := i.Logging(ctx, info, endpoint) if err != nil { - return nil, err + return res, ctx, err } stream := res.(MethodClientStream) return &wrappedMethodClientStream{ @@ -77,15 +72,15 @@ func wrapClientMethodLogging(endpoint goa.Endpoint, i ClientInterceptors) goa.En CallType: goa.InterceptorStreamingSend, RawPayload: req, } - _, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, error) { - var err error - info.ReturnContext, err = stream.SendWithContext(ctx, req.(*MethodStreamingPayload)) - return nil, err + _, ctx, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, context.Context, error) { + castReq, _ := req.(*MethodStreamingPayload) + ctx, err = stream.SendWithContext(ctx, castReq) + return nil, ctx, err }) - return info.ReturnContext, err + return ctx, err }, stream: stream, - }, nil + }, ctx, nil } } diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_service_interceptors.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_service_interceptors.go.golden index a977525534..66752aedbb 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_service_interceptors.go.golden @@ -3,7 +3,7 @@ // payload is sent to the service. The implementation is responsible for calling // next to complete the request. type ServerInterceptors interface { - Logging(ctx context.Context, info *LoggingInfo, next goa.Endpoint) (any, error) + Logging(ctx context.Context, info *LoggingInfo, next goa.InterceptorEndpoint) (any, context.Context, error) } // Access interfaces for interceptor payloads and results @@ -40,8 +40,15 @@ type ( // WrapMethodEndpoint wraps the Method endpoint with the server-side // interceptors defined in the design. func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - endpoint = wrapMethodlogging(endpoint, i) - return endpoint + var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { + response, err := endpoint(ctx, request) + return response, ctx, err + } + interceptorEndpoint = wrapMethodlogging(interceptorEndpoint, i) + return func(ctx context.Context, request any) (any, error) { + response, _, err := interceptorEndpoint(ctx, request) + return response, err + } } // Public accessor methods for Info types diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_interceptor_wrappers.go.golden index 4df7def716..5b5eb93f10 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_interceptor_wrappers.go.golden @@ -1,8 +1,8 @@ // wrapLoggingMethod applies the logging server interceptor to endpoints. -func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - return func(ctx context.Context, req any) (any, error) { +func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { + return func(ctx context.Context, req any) (any, context.Context, error) { info := &LoggingInfo{ Service: "StreamingInterceptorsWithReadPayload", Method: "Method", diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_service_interceptors.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_service_interceptors.go.golden index 4a173a3ce4..68b3f20c34 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_service_interceptors.go.golden @@ -3,7 +3,7 @@ // payload is sent to the service. The implementation is responsible for calling // next to complete the request. type ServerInterceptors interface { - Logging(ctx context.Context, info *LoggingInfo, next goa.Endpoint) (any, error) + Logging(ctx context.Context, info *LoggingInfo, next goa.InterceptorEndpoint) (any, context.Context, error) } // Access interfaces for interceptor payloads and results @@ -30,8 +30,15 @@ type ( // WrapMethodEndpoint wraps the Method endpoint with the server-side // interceptors defined in the design. func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - endpoint = wrapMethodlogging(endpoint, i) - return endpoint + var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { + response, err := endpoint(ctx, request) + return response, ctx, err + } + interceptorEndpoint = wrapMethodlogging(interceptorEndpoint, i) + return func(ctx context.Context, request any) (any, error) { + response, _, err := interceptorEndpoint(ctx, request) + return response, err + } } // Public accessor methods for Info types diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_interceptor_wrappers.go.golden index fefe8935ca..04e149d9e0 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_interceptor_wrappers.go.golden @@ -1,8 +1,8 @@ // wrapLoggingMethod applies the logging server interceptor to endpoints. -func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - return func(ctx context.Context, req any) (any, error) { +func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { + return func(ctx context.Context, req any) (any, context.Context, error) { info := &LoggingInfo{ Service: "StreamingInterceptorsWithReadResult", Method: "Method", diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_service_interceptors.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_service_interceptors.go.golden index fc61ae626f..650a217a5f 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_service_interceptors.go.golden @@ -3,7 +3,7 @@ // payload is sent to the service. The implementation is responsible for calling // next to complete the request. type ServerInterceptors interface { - Logging(ctx context.Context, info *LoggingInfo, next goa.Endpoint) (any, error) + Logging(ctx context.Context, info *LoggingInfo, next goa.InterceptorEndpoint) (any, context.Context, error) } // Access interfaces for interceptor payloads and results @@ -30,8 +30,15 @@ type ( // WrapMethodEndpoint wraps the Method endpoint with the server-side // interceptors defined in the design. func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - endpoint = wrapMethodlogging(endpoint, i) - return endpoint + var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { + response, err := endpoint(ctx, request) + return response, ctx, err + } + interceptorEndpoint = wrapMethodlogging(interceptorEndpoint, i) + return func(ctx context.Context, request any) (any, error) { + response, _, err := interceptorEndpoint(ctx, request) + return response, err + } } // Public accessor methods for Info types diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_client_interceptors.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_client_interceptors.go.golden index 3790fd8cde..705ce41ebc 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_client_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_client_interceptors.go.golden @@ -3,12 +3,19 @@ // is sent to the server. The implementation is responsible for calling next to // complete the request. type ClientInterceptors interface { - Logging(ctx context.Context, info *LoggingInfo, next goa.Endpoint) (any, error) + Logging(ctx context.Context, info *LoggingInfo, next goa.InterceptorEndpoint) (any, context.Context, error) } // WrapMethodClientEndpoint wraps the Method endpoint with the client // interceptors defined in the design. func WrapMethodClientEndpoint(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { - endpoint = wrapClientMethodlogging(endpoint, i) - return endpoint + var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { + response, err := endpoint(ctx, request) + return response, ctx, err + } + interceptorEndpoint = wrapClientMethodlogging(interceptorEndpoint, i) + return func(ctx context.Context, request any) (any, error) { + response, _, err := interceptorEndpoint(ctx, request) + return response, err + } } diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_interceptor_wrappers.go.golden index 75546b9cb3..7a72f914af 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_interceptor_wrappers.go.golden @@ -17,11 +17,11 @@ type wrappedMethodClientStream struct { } // wrapLoggingMethod applies the logging server interceptor to endpoints. -func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - return func(ctx context.Context, req any) (any, error) { - res, err := endpoint(ctx, req) +func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { + return func(ctx context.Context, req any) (any, context.Context, error) { + res, ctx, err := endpoint(ctx, req) if err != nil { - return nil, err + return res, ctx, err } stream := res.(MethodServerStream) return &wrappedMethodServerStream{ @@ -33,47 +33,42 @@ func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint CallType: goa.InterceptorStreamingSend, RawPayload: req, } - _, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, error) { - var err error - info.ReturnContext, err = stream.SendWithContext(ctx, req.(*MethodResult)) - return nil, err + _, ctx, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, context.Context, error) { + castReq, _ := req.(*MethodResult) + ctx, err := stream.SendWithContext(ctx, castReq) + return nil, ctx, err }) - return info.ReturnContext, err + return ctx, err }, stream: stream, - }, nil + }, ctx, nil } } // wrapClientLoggingMethod applies the logging client interceptor to endpoints. -func wrapClientMethodLogging(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { - return func(ctx context.Context, req any) (any, error) { - res, err := endpoint(ctx, req) +func wrapClientMethodLogging(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { + return func(ctx context.Context, req any) (any, context.Context, error) { + res, ctx, err := endpoint(ctx, req) if err != nil { - return nil, err + return res, ctx, err } stream := res.(MethodClientStream) return &wrappedMethodClientStream{ ctx: ctx, recvWithContext: func(ctx context.Context) (*MethodResult, context.Context, error) { info := &LoggingInfo{ - Service: "StreamingInterceptorsWithReadStreamingResult", - Method: "Method", - CallType: goa.InterceptorStreamingRecv, - RawPayload: req, + Service: "StreamingInterceptorsWithReadStreamingResult", + Method: "Method", + CallType: goa.InterceptorStreamingRecv, } - res, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, error) { - var ( - res *MethodResult - err error - ) - res, info.ReturnContext, err = stream.RecvWithContext(ctx) - return res, err + res, ctx, err := i.Logging(ctx, info, func(ctx context.Context, _ any) (any, context.Context, error) { + return stream.RecvWithContext(ctx) }) - return res.(*MethodResult), info.ReturnContext, err + castRes, _ := res.(*MethodResult) + return castRes, ctx, err }, stream: stream, - }, nil + }, ctx, nil } } diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_service_interceptors.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_service_interceptors.go.golden index b65b74dc89..12bde5c8d2 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_service_interceptors.go.golden @@ -3,7 +3,7 @@ // payload is sent to the service. The implementation is responsible for calling // next to complete the request. type ServerInterceptors interface { - Logging(ctx context.Context, info *LoggingInfo, next goa.Endpoint) (any, error) + Logging(ctx context.Context, info *LoggingInfo, next goa.InterceptorEndpoint) (any, context.Context, error) } // Access interfaces for interceptor payloads and results @@ -30,8 +30,15 @@ type ( // WrapMethodEndpoint wraps the Method endpoint with the server-side // interceptors defined in the design. func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - endpoint = wrapMethodlogging(endpoint, i) - return endpoint + var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { + response, err := endpoint(ctx, request) + return response, ctx, err + } + interceptorEndpoint = wrapMethodlogging(interceptorEndpoint, i) + return func(ctx context.Context, request any) (any, error) { + response, _, err := interceptorEndpoint(ctx, request) + return response, err + } } // Public accessor methods for Info types diff --git a/codegen/service/testdata/interceptors/streaming-interceptors_client_interceptors.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors_client_interceptors.go.golden index 3790fd8cde..705ce41ebc 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors_client_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors_client_interceptors.go.golden @@ -3,12 +3,19 @@ // is sent to the server. The implementation is responsible for calling next to // complete the request. type ClientInterceptors interface { - Logging(ctx context.Context, info *LoggingInfo, next goa.Endpoint) (any, error) + Logging(ctx context.Context, info *LoggingInfo, next goa.InterceptorEndpoint) (any, context.Context, error) } // WrapMethodClientEndpoint wraps the Method endpoint with the client // interceptors defined in the design. func WrapMethodClientEndpoint(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { - endpoint = wrapClientMethodlogging(endpoint, i) - return endpoint + var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { + response, err := endpoint(ctx, request) + return response, ctx, err + } + interceptorEndpoint = wrapClientMethodlogging(interceptorEndpoint, i) + return func(ctx context.Context, request any) (any, error) { + response, _, err := interceptorEndpoint(ctx, request) + return response, err + } } diff --git a/codegen/service/testdata/interceptors/streaming-interceptors_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors_interceptor_wrappers.go.golden index 310c32876c..dad0c4efd9 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors_interceptor_wrappers.go.golden @@ -19,11 +19,11 @@ type wrappedMethodClientStream struct { } // wrapLoggingMethod applies the logging server interceptor to endpoints. -func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - return func(ctx context.Context, req any) (any, error) { - res, err := endpoint(ctx, req) +func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { + return func(ctx context.Context, req any) (any, context.Context, error) { + res, ctx, err := endpoint(ctx, req) if err != nil { - return nil, err + return res, ctx, err } stream := res.(MethodServerStream) return &wrappedMethodServerStream{ @@ -35,41 +35,36 @@ func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint CallType: goa.InterceptorStreamingSend, RawPayload: req, } - _, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, error) { - var err error - info.ReturnContext, err = stream.SendWithContext(ctx, req.(*MethodResult)) - return nil, err + _, ctx, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, context.Context, error) { + castReq, _ := req.(*MethodResult) + ctx, err := stream.SendWithContext(ctx, castReq) + return nil, ctx, err }) - return info.ReturnContext, err + return ctx, err }, recvWithContext: func(ctx context.Context) (*MethodStreamingPayload, context.Context, error) { info := &LoggingInfo{ - Service: "StreamingInterceptors", - Method: "Method", - CallType: goa.InterceptorStreamingRecv, - RawPayload: req, + Service: "StreamingInterceptors", + Method: "Method", + CallType: goa.InterceptorStreamingRecv, } - res, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, error) { - var ( - res *MethodStreamingPayload - err error - ) - res, info.ReturnContext, err = stream.RecvWithContext(ctx) - return res, err + res, ctx, err := i.Logging(ctx, info, func(ctx context.Context, _ any) (any, context.Context, error) { + return stream.RecvWithContext(ctx) }) - return res.(*MethodStreamingPayload), info.ReturnContext, err + castRes, _ := res.(*MethodStreamingPayload) + return castRes, ctx, err }, stream: stream, - }, nil + }, ctx, nil } } // wrapClientLoggingMethod applies the logging client interceptor to endpoints. -func wrapClientMethodLogging(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { - return func(ctx context.Context, req any) (any, error) { - res, err := endpoint(ctx, req) +func wrapClientMethodLogging(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { + return func(ctx context.Context, req any) (any, context.Context, error) { + res, ctx, err := endpoint(ctx, req) if err != nil { - return nil, err + return res, ctx, err } stream := res.(MethodClientStream) return &wrappedMethodClientStream{ @@ -81,32 +76,27 @@ func wrapClientMethodLogging(endpoint goa.Endpoint, i ClientInterceptors) goa.En CallType: goa.InterceptorStreamingSend, RawPayload: req, } - _, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, error) { - var err error - info.ReturnContext, err = stream.SendWithContext(ctx, req.(*MethodStreamingPayload)) - return nil, err + _, ctx, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, context.Context, error) { + castReq, _ := req.(*MethodStreamingPayload) + ctx, err = stream.SendWithContext(ctx, castReq) + return nil, ctx, err }) - return info.ReturnContext, err + return ctx, err }, recvWithContext: func(ctx context.Context) (*MethodResult, context.Context, error) { info := &LoggingInfo{ - Service: "StreamingInterceptors", - Method: "Method", - CallType: goa.InterceptorStreamingRecv, - RawPayload: req, + Service: "StreamingInterceptors", + Method: "Method", + CallType: goa.InterceptorStreamingRecv, } - res, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, error) { - var ( - res *MethodResult - err error - ) - res, info.ReturnContext, err = stream.RecvWithContext(ctx) - return res, err + res, ctx, err := i.Logging(ctx, info, func(ctx context.Context, _ any) (any, context.Context, error) { + return stream.RecvWithContext(ctx) }) - return res.(*MethodResult), info.ReturnContext, err + castRes, _ := res.(*MethodResult) + return castRes, ctx, err }, stream: stream, - }, nil + }, ctx, nil } } diff --git a/codegen/service/testdata/interceptors/streaming-interceptors_service_interceptors.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors_service_interceptors.go.golden index 9c0c04c43b..f2004b0487 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors_service_interceptors.go.golden @@ -3,7 +3,7 @@ // payload is sent to the service. The implementation is responsible for calling // next to complete the request. type ServerInterceptors interface { - Logging(ctx context.Context, info *LoggingInfo, next goa.Endpoint) (any, error) + Logging(ctx context.Context, info *LoggingInfo, next goa.InterceptorEndpoint) (any, context.Context, error) } // Access interfaces for interceptor payloads and results @@ -42,8 +42,15 @@ type ( // WrapMethodEndpoint wraps the Method endpoint with the server-side // interceptors defined in the design. func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - endpoint = wrapMethodlogging(endpoint, i) - return endpoint + var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { + response, err := endpoint(ctx, request) + return response, ctx, err + } + interceptorEndpoint = wrapMethodlogging(interceptorEndpoint, i) + return func(ctx context.Context, request any) (any, error) { + response, _, err := interceptorEndpoint(ctx, request) + return response, err + } } // Public accessor methods for Info types From c36dfb623a54631c61470546b54ba2ecc09d0b7a Mon Sep 17 00:00:00 2001 From: Douglas Thrift Date: Wed, 5 Feb 2025 12:16:54 -0800 Subject: [PATCH 19/23] Change goa.InterceptorInfo to an interface that generated interceptor info structs implement --- .../client_interceptor_wrappers.go.tpl | 30 ++++++++-------- .../example_client_interceptor.go.tpl | 12 +++---- .../example_server_interceptor.go.tpl | 12 +++---- codegen/service/templates/interceptors.go.tpl | 36 ++++++++++++++----- .../templates/interceptors_types.go.tpl | 7 +++- .../server_interceptor_wrappers.go.tpl | 30 ++++++++-------- .../api_interceptor_service_client.golden | 10 +++--- .../api_interceptor_service_server.golden | 10 +++--- .../chained_interceptor_service_client.golden | 30 ++++++++-------- .../chained_interceptor_service_server.golden | 30 ++++++++-------- .../client_interceptor_service_client.golden | 10 +++--- ...ultiple_interceptors_service_client.golden | 20 +++++------ ...ultiple_interceptors_service_server.golden | 20 +++++------ ...rvices_interceptors_service2_client.golden | 20 +++++------ ...rvices_interceptors_service2_server.golden | 20 +++++------ ...ervices_interceptors_service_client.golden | 20 +++++------ ...ervices_interceptors_service_server.golden | 20 +++++------ ..._interceptor_by_name_service_server.golden | 10 +++--- .../server_interceptor_service_server.golden | 10 +++--- ...ead-payload_interceptor_wrappers.go.golden | 16 ++++----- ...ead-payload_service_interceptors.go.golden | 29 +++++++++++++-- ...read-result_interceptor_wrappers.go.golden | 16 ++++----- ...read-result_service_interceptors.go.golden | 28 ++++++++++++++- ...ite-payload_interceptor_wrappers.go.golden | 16 ++++----- ...ite-payload_service_interceptors.go.golden | 29 +++++++++++++-- ...rite-result_interceptor_wrappers.go.golden | 16 ++++----- ...rite-result_service_interceptors.go.golden | 28 ++++++++++++++- ...ite-payload_interceptor_wrappers.go.golden | 16 ++++----- ...ite-payload_service_interceptors.go.golden | 29 +++++++++++++-- ...rite-result_interceptor_wrappers.go.golden | 16 ++++----- ...rite-result_service_interceptors.go.golden | 28 ++++++++++++++- ...interceptors_client_interceptors.go.golden | 14 ++++++-- ...nterceptors_interceptor_wrappers.go.golden | 32 ++++++++--------- ...nterceptors_service_interceptors.go.golden | 14 ++++++-- ...interceptor_interceptor_wrappers.go.golden | 16 ++++----- ...interceptor_service_interceptors.go.golden | 7 +++- ...-interceptor_client_interceptors.go.golden | 7 +++- ...interceptor_interceptor_wrappers.go.golden | 8 ++--- ...interceptor_interceptor_wrappers.go.golden | 8 ++--- ...interceptor_service_interceptors.go.golden | 7 +++- ...interceptor_interceptor_wrappers.go.golden | 16 ++++----- ...interceptor_service_interceptors.go.golden | 7 +++- ...ing-payload_interceptor_wrappers.go.golden | 30 ++++++++-------- ...ing-payload_service_interceptors.go.golden | 31 ++++++++++++++-- ...ead-payload_interceptor_wrappers.go.golden | 8 ++--- ...ead-payload_service_interceptors.go.golden | 29 +++++++++++++-- ...read-result_interceptor_wrappers.go.golden | 8 ++--- ...read-result_service_interceptors.go.golden | 28 ++++++++++++++- ...ming-result_interceptor_wrappers.go.golden | 14 ++++---- ...ming-result_service_interceptors.go.golden | 28 ++++++++++++++- ...nterceptors_interceptor_wrappers.go.golden | 28 +++++++-------- ...nterceptors_service_interceptors.go.golden | 30 ++++++++++++++-- pkg/interceptor.go | 18 +++++----- 53 files changed, 679 insertions(+), 333 deletions(-) diff --git a/codegen/service/templates/client_interceptor_wrappers.go.tpl b/codegen/service/templates/client_interceptor_wrappers.go.tpl index 0313b257d5..51a0802e93 100644 --- a/codegen/service/templates/client_interceptor_wrappers.go.tpl +++ b/codegen/service/templates/client_interceptor_wrappers.go.tpl @@ -8,10 +8,10 @@ func wrapClient{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Interceptor {{- if or $interceptor.HasStreamingPayloadAccess $interceptor.HasStreamingResultAccess }} {{- if $interceptor.HasPayloadAccess }} info := &{{ $interceptor.Name }}Info{ - Service: "{{ $.Service }}", - Method: "{{ .MethodName }}", - CallType: goa.InterceptorUnary, - RawPayload: req, + service: "{{ $.Service }}", + method: "{{ .MethodName }}", + callType: goa.InterceptorUnary, + payload: req, } res, ctx, err := i.{{ $interceptor.Name }}(ctx, info, endpoint) {{- else }} @@ -26,10 +26,10 @@ func wrapClient{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Interceptor {{- if $interceptor.HasStreamingPayloadAccess }} sendWithContext: func(ctx context.Context, req {{ .ClientStream.SendTypeRef }}) (context.Context, error) { info := &{{ $interceptor.Name }}Info{ - Service: "{{ $.Service }}", - Method: "{{ .MethodName }}", - CallType: goa.InterceptorStreamingSend, - RawPayload: req, + service: "{{ $.Service }}", + method: "{{ .MethodName }}", + callType: goa.InterceptorStreamingSend, + payload: req, } _, ctx, err := i.{{ $interceptor.Name }}(ctx, info, func(ctx context.Context, req any) (any, context.Context, error) { castReq, _ := req.({{ .ClientStream.SendTypeRef }}) @@ -42,9 +42,9 @@ func wrapClient{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Interceptor {{- if $interceptor.HasStreamingResultAccess }} recvWithContext: func(ctx context.Context) ({{ .ClientStream.RecvTypeRef }}, context.Context, error) { info := &{{ $interceptor.Name }}Info{ - Service: "{{ $.Service }}", - Method: "{{ .MethodName }}", - CallType: goa.InterceptorStreamingRecv, + service: "{{ $.Service }}", + method: "{{ .MethodName }}", + callType: goa.InterceptorStreamingRecv, } res, ctx, err := i.{{ $interceptor.Name }}(ctx, info, func(ctx context.Context, _ any) (any, context.Context, error) { return stream.{{ .ClientStream.RecvWithContextName }}(ctx) @@ -57,10 +57,10 @@ func wrapClient{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Interceptor }, ctx, nil {{- else }} info := &{{ $interceptor.Name }}Info{ - Service: "{{ $.Service }}", - Method: "{{ .MethodName }}", - CallType: goa.InterceptorUnary, - RawPayload: req, + service: "{{ $.Service }}", + method: "{{ .MethodName }}", + callType: goa.InterceptorUnary, + payload: req, } return i.{{ $interceptor.Name }}(ctx, info, endpoint) {{- end }} diff --git a/codegen/service/templates/example_client_interceptor.go.tpl b/codegen/service/templates/example_client_interceptor.go.tpl index 455c74c9f4..1580286352 100644 --- a/codegen/service/templates/example_client_interceptor.go.tpl +++ b/codegen/service/templates/example_client_interceptor.go.tpl @@ -11,14 +11,14 @@ func New{{ .StructName }}ClientInterceptors() *{{ .StructName }}ClientIntercepto {{- if .Description }} {{ comment .Description }} {{- end }} -func (i *{{ $.StructName }}ClientInterceptors) {{ .Name }}(ctx context.Context, info *{{ $.PkgName }}.{{ .Name }}Info, next goa.Endpoint) (any, error) { - log.Printf(ctx, "[{{ .Name }}] Sending request: %v", info.RawPayload) - resp, err := next(ctx, info.RawPayload) +func (i *{{ $.StructName }}ClientInterceptors) {{ .Name }}(ctx context.Context, info *{{ $.PkgName }}.{{ .Name }}Info, next goa.InterceptorEndpoint) (any, context.Context, error) { + log.Printf(ctx, "[{{ .Name }}] Sending request: %v", info.RawPayload()) + resp, ctx, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[{{ .Name }}] Error: %v", err) - return nil, err + return nil, ctx, err } log.Printf(ctx, "[{{ .Name }}] Received response: %v", resp) - return resp, nil + return resp, ctx, nil } -{{- end }} \ No newline at end of file +{{- end }} diff --git a/codegen/service/templates/example_server_interceptor.go.tpl b/codegen/service/templates/example_server_interceptor.go.tpl index dfbb7d93bb..d2f0534219 100644 --- a/codegen/service/templates/example_server_interceptor.go.tpl +++ b/codegen/service/templates/example_server_interceptor.go.tpl @@ -11,14 +11,14 @@ func New{{ .StructName }}ServerInterceptors() *{{ .StructName }}ServerIntercepto {{- if .Description }} {{ comment .Description }} {{- end }} -func (i *{{ $.StructName }}ServerInterceptors) {{ .Name }}(ctx context.Context, info *{{ $.PkgName }}.{{ .Name }}Info, next goa.Endpoint) (any, error) { - log.Printf(ctx, "[{{ .Name }}] Processing request: %v", info.RawPayload) - resp, err := next(ctx, info.RawPayload) +func (i *{{ $.StructName }}ServerInterceptors) {{ .Name }}(ctx context.Context, info *{{ $.PkgName }}.{{ .Name }}Info, next goa.InterceptorEndpoint) (any, context.Context, error) { + log.Printf(ctx, "[{{ .Name }}] Processing request: %v", info.RawPayload()) + resp, ctx, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[{{ .Name }}] Error: %v", err) - return nil, err + return nil, ctx, err } log.Printf(ctx, "[{{ .Name }}] Response: %v", resp) - return resp, nil + return resp, ctx, nil } -{{- end }} \ No newline at end of file +{{- end }} diff --git a/codegen/service/templates/interceptors.go.tpl b/codegen/service/templates/interceptors.go.tpl index 6f5f2250c0..e11b49bc9f 100644 --- a/codegen/service/templates/interceptors.go.tpl +++ b/codegen/service/templates/interceptors.go.tpl @@ -1,21 +1,41 @@ {{- if hasPrivateImplementationTypes . }} // Public accessor methods for Info types {{- range . }} + +// Service returns the name of the service handling the request. +func (info *{{ .Name }}Info) Service() string { + return info.service +} + +// Method returns the name of the method handling the request. +func (info *{{ .Name }}Info) Method() string { + return info.method +} + +// CallType returns the type of call the interceptor is handling. +func (info *{{ .Name }}Info) CallType() goa.InterceptorCallType { + return info.callType +} + +// RawPayload returns the raw payload of the request. +func (info *{{ .Name }}Info) RawPayload() any { + return info.payload +} {{- if .HasPayloadAccess }} // Payload returns a type-safe accessor for the method payload. func (info *{{ .Name }}Info) Payload() {{ .Name }}Payload { {{- if gt (len .Methods) 1 }} - switch info.Method { + switch info.Method() { {{- range .Methods }} case "{{ .MethodName }}": - return &{{ .PayloadAccess }}{payload: info.RawPayload.({{ .PayloadRef }})} + return &{{ .PayloadAccess }}{payload: info.RawPayload().({{ .PayloadRef }})} {{- end }} default: return nil } {{- else }} - return &{{ (index .Methods 0).PayloadAccess }}{payload: info.RawPayload.({{ (index .Methods 0).PayloadRef }})} + return &{{ (index .Methods 0).PayloadAccess }}{payload: info.RawPayload().({{ (index .Methods 0).PayloadRef }})} {{- end }} } {{- end }} @@ -24,7 +44,7 @@ func (info *{{ .Name }}Info) Payload() {{ .Name }}Payload { // Result returns a type-safe accessor for the method result. func (info *{{ .Name }}Info) Result(res any) {{ .Name }}Result { {{- if gt (len .Methods) 1 }} - switch info.Method { + switch info.Method() { {{- range .Methods }} case "{{ .MethodName }}": return &{{ .ResultAccess }}{result: res.({{ .ResultRef }})} @@ -42,16 +62,16 @@ func (info *{{ .Name }}Info) Result(res any) {{ .Name }}Result { // StreamingPayload returns a type-safe accessor for the method streaming payload. func (info *{{ .Name }}Info) StreamingPayload() {{ .Name }}StreamingPayload { {{- if gt (len .Methods) 1 }} - switch info.Method { + switch info.Method() { {{- range .Methods }} case "{{ .MethodName }}": - return &{{ .StreamingPayloadAccess }}{payload: info.RawPayload.({{ .StreamingPayloadRef }})} + return &{{ .StreamingPayloadAccess }}{payload: info.RawPayload().({{ .StreamingPayloadRef }})} {{- end }} default: return nil } {{- else }} - return &{{ (index .Methods 0).StreamingPayloadAccess }}{payload: info.RawPayload.({{ (index .Methods 0).StreamingPayloadRef }})} + return &{{ (index .Methods 0).StreamingPayloadAccess }}{payload: info.RawPayload().({{ (index .Methods 0).StreamingPayloadRef }})} {{- end }} } {{- end }} @@ -60,7 +80,7 @@ func (info *{{ .Name }}Info) StreamingPayload() {{ .Name }}StreamingPayload { // StreamingResult returns a type-safe accessor for the method streaming result. func (info *{{ .Name }}Info) StreamingResult(res any) {{ .Name }}StreamingResult { {{- if gt (len .Methods) 1 }} - switch info.Method { + switch info.Method() { {{- range .Methods }} case "{{ .MethodName }}": return &{{ .StreamingResultAccess }}{result: res.({{ .StreamingResultRef }})} diff --git a/codegen/service/templates/interceptors_types.go.tpl b/codegen/service/templates/interceptors_types.go.tpl index 1e992dd26d..2bc7deed92 100644 --- a/codegen/service/templates/interceptors_types.go.tpl +++ b/codegen/service/templates/interceptors_types.go.tpl @@ -4,7 +4,12 @@ type ( {{- range . }} // {{ .Name }}Info provides metadata about the current interception. // It includes service name, method name, and access to the endpoint. - {{ .Name }}Info goa.InterceptorInfo + {{ .Name }}Info struct { + service string + method string + callType goa.InterceptorCallType + payload any + } {{- if .HasPayloadAccess }} // {{ .Name }}Payload provides type-safe access to the method payload. diff --git a/codegen/service/templates/server_interceptor_wrappers.go.tpl b/codegen/service/templates/server_interceptor_wrappers.go.tpl index 5bbb24f3e1..744da4bb9c 100644 --- a/codegen/service/templates/server_interceptor_wrappers.go.tpl +++ b/codegen/service/templates/server_interceptor_wrappers.go.tpl @@ -8,10 +8,10 @@ func wrap{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.InterceptorEndpoi {{- if or $interceptor.HasStreamingPayloadAccess $interceptor.HasStreamingResultAccess }} {{- if $interceptor.HasPayloadAccess }} info := &{{ $interceptor.Name }}Info{ - Service: "{{ $.Service }}", - Method: "{{ .MethodName }}", - CallType: goa.InterceptorUnary, - RawPayload: req, + service: "{{ $.Service }}", + method: "{{ .MethodName }}", + callType: goa.InterceptorUnary, + payload: req, } res, ctx, err := i.{{ $interceptor.Name }}(ctx, info, endpoint) {{- else }} @@ -26,10 +26,10 @@ func wrap{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.InterceptorEndpoi {{- if $interceptor.HasStreamingResultAccess }} sendWithContext: func(ctx context.Context, req {{ .ServerStream.SendTypeRef }}) (context.Context, error) { info := &{{ $interceptor.Name }}Info{ - Service: "{{ $.Service }}", - Method: "{{ .MethodName }}", - CallType: goa.InterceptorStreamingSend, - RawPayload: req, + service: "{{ $.Service }}", + method: "{{ .MethodName }}", + callType: goa.InterceptorStreamingSend, + payload: req, } _, ctx, err := i.{{ $interceptor.Name }}(ctx, info, func(ctx context.Context, req any) (any, context.Context, error) { castReq, _ := req.({{ .ServerStream.SendTypeRef }}) @@ -42,9 +42,9 @@ func wrap{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.InterceptorEndpoi {{- if $interceptor.HasStreamingPayloadAccess }} recvWithContext: func(ctx context.Context) ({{ .ServerStream.RecvTypeRef }}, context.Context, error) { info := &{{ $interceptor.Name }}Info{ - Service: "{{ $.Service }}", - Method: "{{ .MethodName }}", - CallType: goa.InterceptorStreamingRecv, + service: "{{ $.Service }}", + method: "{{ .MethodName }}", + callType: goa.InterceptorStreamingRecv, } res, ctx, err := i.{{ $interceptor.Name }}(ctx, info, func(ctx context.Context, _ any) (any, context.Context, error) { return stream.{{ .ServerStream.RecvWithContextName }}(ctx) @@ -57,10 +57,10 @@ func wrap{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.InterceptorEndpoi }, ctx, nil {{- else }} info := &{{ $interceptor.Name }}Info{ - Service: "{{ $.Service }}", - Method: "{{ .MethodName }}", - CallType: goa.InterceptorUnary, - RawPayload: req, + service: "{{ $.Service }}", + method: "{{ .MethodName }}", + callType: goa.InterceptorUnary, + payload: req, } return i.{{ $interceptor.Name }}(ctx, info, endpoint) {{- end }} diff --git a/codegen/service/testdata/example_interceptors/api_interceptor_service_client.golden b/codegen/service/testdata/example_interceptors/api_interceptor_service_client.golden index 5188cca366..5cb6b71d33 100644 --- a/codegen/service/testdata/example_interceptors/api_interceptor_service_client.golden +++ b/codegen/service/testdata/example_interceptors/api_interceptor_service_client.golden @@ -23,13 +23,13 @@ type APIInterceptorServiceClientInterceptors struct { func NewAPIInterceptorServiceClientInterceptors() *APIInterceptorServiceClientInterceptors { return &APIInterceptorServiceClientInterceptors{} } -func (i *APIInterceptorServiceClientInterceptors) API(ctx context.Context, info *interceptors.APIInfo, next goa.Endpoint) (any, error) { - log.Printf(ctx, "[API] Sending request: %v", info.RawPayload) - resp, err := next(ctx, info.RawPayload) +func (i *APIInterceptorServiceClientInterceptors) API(ctx context.Context, info *interceptors.APIInfo, next goa.InterceptorEndpoint) (any, context.Context, error) { + log.Printf(ctx, "[API] Sending request: %v", info.RawPayload()) + resp, ctx, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[API] Error: %v", err) - return nil, err + return nil, ctx, err } log.Printf(ctx, "[API] Received response: %v", resp) - return resp, nil + return resp, ctx, nil } diff --git a/codegen/service/testdata/example_interceptors/api_interceptor_service_server.golden b/codegen/service/testdata/example_interceptors/api_interceptor_service_server.golden index ff86a4cee7..e193d8083f 100644 --- a/codegen/service/testdata/example_interceptors/api_interceptor_service_server.golden +++ b/codegen/service/testdata/example_interceptors/api_interceptor_service_server.golden @@ -23,13 +23,13 @@ type APIInterceptorServiceServerInterceptors struct { func NewAPIInterceptorServiceServerInterceptors() *APIInterceptorServiceServerInterceptors { return &APIInterceptorServiceServerInterceptors{} } -func (i *APIInterceptorServiceServerInterceptors) API(ctx context.Context, info *interceptors.APIInfo, next goa.Endpoint) (any, error) { - log.Printf(ctx, "[API] Processing request: %v", info.RawPayload) - resp, err := next(ctx, info.RawPayload) +func (i *APIInterceptorServiceServerInterceptors) API(ctx context.Context, info *interceptors.APIInfo, next goa.InterceptorEndpoint) (any, context.Context, error) { + log.Printf(ctx, "[API] Processing request: %v", info.RawPayload()) + resp, ctx, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[API] Error: %v", err) - return nil, err + return nil, ctx, err } log.Printf(ctx, "[API] Response: %v", resp) - return resp, nil + return resp, ctx, nil } diff --git a/codegen/service/testdata/example_interceptors/chained_interceptor_service_client.golden b/codegen/service/testdata/example_interceptors/chained_interceptor_service_client.golden index 4a1eeebce9..ca3f13bb6a 100644 --- a/codegen/service/testdata/example_interceptors/chained_interceptor_service_client.golden +++ b/codegen/service/testdata/example_interceptors/chained_interceptor_service_client.golden @@ -23,33 +23,33 @@ type ChainedInterceptorServiceClientInterceptors struct { func NewChainedInterceptorServiceClientInterceptors() *ChainedInterceptorServiceClientInterceptors { return &ChainedInterceptorServiceClientInterceptors{} } -func (i *ChainedInterceptorServiceClientInterceptors) API(ctx context.Context, info *interceptors.APIInfo, next goa.Endpoint) (any, error) { - log.Printf(ctx, "[API] Sending request: %v", info.RawPayload) - resp, err := next(ctx, info.RawPayload) +func (i *ChainedInterceptorServiceClientInterceptors) API(ctx context.Context, info *interceptors.APIInfo, next goa.InterceptorEndpoint) (any, context.Context, error) { + log.Printf(ctx, "[API] Sending request: %v", info.RawPayload()) + resp, ctx, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[API] Error: %v", err) - return nil, err + return nil, ctx, err } log.Printf(ctx, "[API] Received response: %v", resp) - return resp, nil + return resp, ctx, nil } -func (i *ChainedInterceptorServiceClientInterceptors) Method(ctx context.Context, info *interceptors.MethodInfo, next goa.Endpoint) (any, error) { - log.Printf(ctx, "[Method] Sending request: %v", info.RawPayload) - resp, err := next(ctx, info.RawPayload) +func (i *ChainedInterceptorServiceClientInterceptors) Method(ctx context.Context, info *interceptors.MethodInfo, next goa.InterceptorEndpoint) (any, context.Context, error) { + log.Printf(ctx, "[Method] Sending request: %v", info.RawPayload()) + resp, ctx, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[Method] Error: %v", err) - return nil, err + return nil, ctx, err } log.Printf(ctx, "[Method] Received response: %v", resp) - return resp, nil + return resp, ctx, nil } -func (i *ChainedInterceptorServiceClientInterceptors) Service(ctx context.Context, info *interceptors.ServiceInfo, next goa.Endpoint) (any, error) { - log.Printf(ctx, "[Service] Sending request: %v", info.RawPayload) - resp, err := next(ctx, info.RawPayload) +func (i *ChainedInterceptorServiceClientInterceptors) Service(ctx context.Context, info *interceptors.ServiceInfo, next goa.InterceptorEndpoint) (any, context.Context, error) { + log.Printf(ctx, "[Service] Sending request: %v", info.RawPayload()) + resp, ctx, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[Service] Error: %v", err) - return nil, err + return nil, ctx, err } log.Printf(ctx, "[Service] Received response: %v", resp) - return resp, nil + return resp, ctx, nil } diff --git a/codegen/service/testdata/example_interceptors/chained_interceptor_service_server.golden b/codegen/service/testdata/example_interceptors/chained_interceptor_service_server.golden index 4027c3a597..baf6d5f9c8 100644 --- a/codegen/service/testdata/example_interceptors/chained_interceptor_service_server.golden +++ b/codegen/service/testdata/example_interceptors/chained_interceptor_service_server.golden @@ -23,33 +23,33 @@ type ChainedInterceptorServiceServerInterceptors struct { func NewChainedInterceptorServiceServerInterceptors() *ChainedInterceptorServiceServerInterceptors { return &ChainedInterceptorServiceServerInterceptors{} } -func (i *ChainedInterceptorServiceServerInterceptors) API(ctx context.Context, info *interceptors.APIInfo, next goa.Endpoint) (any, error) { - log.Printf(ctx, "[API] Processing request: %v", info.RawPayload) - resp, err := next(ctx, info.RawPayload) +func (i *ChainedInterceptorServiceServerInterceptors) API(ctx context.Context, info *interceptors.APIInfo, next goa.InterceptorEndpoint) (any, context.Context, error) { + log.Printf(ctx, "[API] Processing request: %v", info.RawPayload()) + resp, ctx, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[API] Error: %v", err) - return nil, err + return nil, ctx, err } log.Printf(ctx, "[API] Response: %v", resp) - return resp, nil + return resp, ctx, nil } -func (i *ChainedInterceptorServiceServerInterceptors) Method(ctx context.Context, info *interceptors.MethodInfo, next goa.Endpoint) (any, error) { - log.Printf(ctx, "[Method] Processing request: %v", info.RawPayload) - resp, err := next(ctx, info.RawPayload) +func (i *ChainedInterceptorServiceServerInterceptors) Method(ctx context.Context, info *interceptors.MethodInfo, next goa.InterceptorEndpoint) (any, context.Context, error) { + log.Printf(ctx, "[Method] Processing request: %v", info.RawPayload()) + resp, ctx, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[Method] Error: %v", err) - return nil, err + return nil, ctx, err } log.Printf(ctx, "[Method] Response: %v", resp) - return resp, nil + return resp, ctx, nil } -func (i *ChainedInterceptorServiceServerInterceptors) Service(ctx context.Context, info *interceptors.ServiceInfo, next goa.Endpoint) (any, error) { - log.Printf(ctx, "[Service] Processing request: %v", info.RawPayload) - resp, err := next(ctx, info.RawPayload) +func (i *ChainedInterceptorServiceServerInterceptors) Service(ctx context.Context, info *interceptors.ServiceInfo, next goa.InterceptorEndpoint) (any, context.Context, error) { + log.Printf(ctx, "[Service] Processing request: %v", info.RawPayload()) + resp, ctx, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[Service] Error: %v", err) - return nil, err + return nil, ctx, err } log.Printf(ctx, "[Service] Response: %v", resp) - return resp, nil + return resp, ctx, nil } diff --git a/codegen/service/testdata/example_interceptors/client_interceptor_service_client.golden b/codegen/service/testdata/example_interceptors/client_interceptor_service_client.golden index f64ea4bd10..c216cc8a4e 100644 --- a/codegen/service/testdata/example_interceptors/client_interceptor_service_client.golden +++ b/codegen/service/testdata/example_interceptors/client_interceptor_service_client.golden @@ -23,13 +23,13 @@ type ClientInterceptorServiceClientInterceptors struct { func NewClientInterceptorServiceClientInterceptors() *ClientInterceptorServiceClientInterceptors { return &ClientInterceptorServiceClientInterceptors{} } -func (i *ClientInterceptorServiceClientInterceptors) Test(ctx context.Context, info *interceptors.TestInfo, next goa.Endpoint) (any, error) { - log.Printf(ctx, "[Test] Sending request: %v", info.RawPayload) - resp, err := next(ctx, info.RawPayload) +func (i *ClientInterceptorServiceClientInterceptors) Test(ctx context.Context, info *interceptors.TestInfo, next goa.InterceptorEndpoint) (any, context.Context, error) { + log.Printf(ctx, "[Test] Sending request: %v", info.RawPayload()) + resp, ctx, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[Test] Error: %v", err) - return nil, err + return nil, ctx, err } log.Printf(ctx, "[Test] Received response: %v", resp) - return resp, nil + return resp, ctx, nil } diff --git a/codegen/service/testdata/example_interceptors/multiple_interceptors_service_client.golden b/codegen/service/testdata/example_interceptors/multiple_interceptors_service_client.golden index 3086ebce99..c4ff52cd5d 100644 --- a/codegen/service/testdata/example_interceptors/multiple_interceptors_service_client.golden +++ b/codegen/service/testdata/example_interceptors/multiple_interceptors_service_client.golden @@ -23,23 +23,23 @@ type MultipleInterceptorsServiceClientInterceptors struct { func NewMultipleInterceptorsServiceClientInterceptors() *MultipleInterceptorsServiceClientInterceptors { return &MultipleInterceptorsServiceClientInterceptors{} } -func (i *MultipleInterceptorsServiceClientInterceptors) Test2(ctx context.Context, info *interceptors.Test2Info, next goa.Endpoint) (any, error) { - log.Printf(ctx, "[Test2] Sending request: %v", info.RawPayload) - resp, err := next(ctx, info.RawPayload) +func (i *MultipleInterceptorsServiceClientInterceptors) Test2(ctx context.Context, info *interceptors.Test2Info, next goa.InterceptorEndpoint) (any, context.Context, error) { + log.Printf(ctx, "[Test2] Sending request: %v", info.RawPayload()) + resp, ctx, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[Test2] Error: %v", err) - return nil, err + return nil, ctx, err } log.Printf(ctx, "[Test2] Received response: %v", resp) - return resp, nil + return resp, ctx, nil } -func (i *MultipleInterceptorsServiceClientInterceptors) Test4(ctx context.Context, info *interceptors.Test4Info, next goa.Endpoint) (any, error) { - log.Printf(ctx, "[Test4] Sending request: %v", info.RawPayload) - resp, err := next(ctx, info.RawPayload) +func (i *MultipleInterceptorsServiceClientInterceptors) Test4(ctx context.Context, info *interceptors.Test4Info, next goa.InterceptorEndpoint) (any, context.Context, error) { + log.Printf(ctx, "[Test4] Sending request: %v", info.RawPayload()) + resp, ctx, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[Test4] Error: %v", err) - return nil, err + return nil, ctx, err } log.Printf(ctx, "[Test4] Received response: %v", resp) - return resp, nil + return resp, ctx, nil } diff --git a/codegen/service/testdata/example_interceptors/multiple_interceptors_service_server.golden b/codegen/service/testdata/example_interceptors/multiple_interceptors_service_server.golden index 75f774ef53..e5795aa7f7 100644 --- a/codegen/service/testdata/example_interceptors/multiple_interceptors_service_server.golden +++ b/codegen/service/testdata/example_interceptors/multiple_interceptors_service_server.golden @@ -23,23 +23,23 @@ type MultipleInterceptorsServiceServerInterceptors struct { func NewMultipleInterceptorsServiceServerInterceptors() *MultipleInterceptorsServiceServerInterceptors { return &MultipleInterceptorsServiceServerInterceptors{} } -func (i *MultipleInterceptorsServiceServerInterceptors) Test(ctx context.Context, info *interceptors.TestInfo, next goa.Endpoint) (any, error) { - log.Printf(ctx, "[Test] Processing request: %v", info.RawPayload) - resp, err := next(ctx, info.RawPayload) +func (i *MultipleInterceptorsServiceServerInterceptors) Test(ctx context.Context, info *interceptors.TestInfo, next goa.InterceptorEndpoint) (any, context.Context, error) { + log.Printf(ctx, "[Test] Processing request: %v", info.RawPayload()) + resp, ctx, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[Test] Error: %v", err) - return nil, err + return nil, ctx, err } log.Printf(ctx, "[Test] Response: %v", resp) - return resp, nil + return resp, ctx, nil } -func (i *MultipleInterceptorsServiceServerInterceptors) Test3(ctx context.Context, info *interceptors.Test3Info, next goa.Endpoint) (any, error) { - log.Printf(ctx, "[Test3] Processing request: %v", info.RawPayload) - resp, err := next(ctx, info.RawPayload) +func (i *MultipleInterceptorsServiceServerInterceptors) Test3(ctx context.Context, info *interceptors.Test3Info, next goa.InterceptorEndpoint) (any, context.Context, error) { + log.Printf(ctx, "[Test3] Processing request: %v", info.RawPayload()) + resp, ctx, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[Test3] Error: %v", err) - return nil, err + return nil, ctx, err } log.Printf(ctx, "[Test3] Response: %v", resp) - return resp, nil + return resp, ctx, nil } diff --git a/codegen/service/testdata/example_interceptors/multiple_services_interceptors_service2_client.golden b/codegen/service/testdata/example_interceptors/multiple_services_interceptors_service2_client.golden index ff9d84033d..2de5dfe09c 100644 --- a/codegen/service/testdata/example_interceptors/multiple_services_interceptors_service2_client.golden +++ b/codegen/service/testdata/example_interceptors/multiple_services_interceptors_service2_client.golden @@ -23,23 +23,23 @@ type MultipleServicesInterceptorsService2ClientInterceptors struct { func NewMultipleServicesInterceptorsService2ClientInterceptors() *MultipleServicesInterceptorsService2ClientInterceptors { return &MultipleServicesInterceptorsService2ClientInterceptors{} } -func (i *MultipleServicesInterceptorsService2ClientInterceptors) Test2(ctx context.Context, info *interceptors.Test2Info, next goa.Endpoint) (any, error) { - log.Printf(ctx, "[Test2] Sending request: %v", info.RawPayload) - resp, err := next(ctx, info.RawPayload) +func (i *MultipleServicesInterceptorsService2ClientInterceptors) Test2(ctx context.Context, info *interceptors.Test2Info, next goa.InterceptorEndpoint) (any, context.Context, error) { + log.Printf(ctx, "[Test2] Sending request: %v", info.RawPayload()) + resp, ctx, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[Test2] Error: %v", err) - return nil, err + return nil, ctx, err } log.Printf(ctx, "[Test2] Received response: %v", resp) - return resp, nil + return resp, ctx, nil } -func (i *MultipleServicesInterceptorsService2ClientInterceptors) Test4(ctx context.Context, info *interceptors.Test4Info, next goa.Endpoint) (any, error) { - log.Printf(ctx, "[Test4] Sending request: %v", info.RawPayload) - resp, err := next(ctx, info.RawPayload) +func (i *MultipleServicesInterceptorsService2ClientInterceptors) Test4(ctx context.Context, info *interceptors.Test4Info, next goa.InterceptorEndpoint) (any, context.Context, error) { + log.Printf(ctx, "[Test4] Sending request: %v", info.RawPayload()) + resp, ctx, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[Test4] Error: %v", err) - return nil, err + return nil, ctx, err } log.Printf(ctx, "[Test4] Received response: %v", resp) - return resp, nil + return resp, ctx, nil } diff --git a/codegen/service/testdata/example_interceptors/multiple_services_interceptors_service2_server.golden b/codegen/service/testdata/example_interceptors/multiple_services_interceptors_service2_server.golden index 173144f090..e6988dcd6f 100644 --- a/codegen/service/testdata/example_interceptors/multiple_services_interceptors_service2_server.golden +++ b/codegen/service/testdata/example_interceptors/multiple_services_interceptors_service2_server.golden @@ -23,23 +23,23 @@ type MultipleServicesInterceptorsService2ServerInterceptors struct { func NewMultipleServicesInterceptorsService2ServerInterceptors() *MultipleServicesInterceptorsService2ServerInterceptors { return &MultipleServicesInterceptorsService2ServerInterceptors{} } -func (i *MultipleServicesInterceptorsService2ServerInterceptors) Test(ctx context.Context, info *interceptors.TestInfo, next goa.Endpoint) (any, error) { - log.Printf(ctx, "[Test] Processing request: %v", info.RawPayload) - resp, err := next(ctx, info.RawPayload) +func (i *MultipleServicesInterceptorsService2ServerInterceptors) Test(ctx context.Context, info *interceptors.TestInfo, next goa.InterceptorEndpoint) (any, context.Context, error) { + log.Printf(ctx, "[Test] Processing request: %v", info.RawPayload()) + resp, ctx, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[Test] Error: %v", err) - return nil, err + return nil, ctx, err } log.Printf(ctx, "[Test] Response: %v", resp) - return resp, nil + return resp, ctx, nil } -func (i *MultipleServicesInterceptorsService2ServerInterceptors) Test3(ctx context.Context, info *interceptors.Test3Info, next goa.Endpoint) (any, error) { - log.Printf(ctx, "[Test3] Processing request: %v", info.RawPayload) - resp, err := next(ctx, info.RawPayload) +func (i *MultipleServicesInterceptorsService2ServerInterceptors) Test3(ctx context.Context, info *interceptors.Test3Info, next goa.InterceptorEndpoint) (any, context.Context, error) { + log.Printf(ctx, "[Test3] Processing request: %v", info.RawPayload()) + resp, ctx, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[Test3] Error: %v", err) - return nil, err + return nil, ctx, err } log.Printf(ctx, "[Test3] Response: %v", resp) - return resp, nil + return resp, ctx, nil } diff --git a/codegen/service/testdata/example_interceptors/multiple_services_interceptors_service_client.golden b/codegen/service/testdata/example_interceptors/multiple_services_interceptors_service_client.golden index 72c48c6bc8..ae0d6c70b6 100644 --- a/codegen/service/testdata/example_interceptors/multiple_services_interceptors_service_client.golden +++ b/codegen/service/testdata/example_interceptors/multiple_services_interceptors_service_client.golden @@ -23,23 +23,23 @@ type MultipleServicesInterceptorsServiceClientInterceptors struct { func NewMultipleServicesInterceptorsServiceClientInterceptors() *MultipleServicesInterceptorsServiceClientInterceptors { return &MultipleServicesInterceptorsServiceClientInterceptors{} } -func (i *MultipleServicesInterceptorsServiceClientInterceptors) Test2(ctx context.Context, info *interceptors.Test2Info, next goa.Endpoint) (any, error) { - log.Printf(ctx, "[Test2] Sending request: %v", info.RawPayload) - resp, err := next(ctx, info.RawPayload) +func (i *MultipleServicesInterceptorsServiceClientInterceptors) Test2(ctx context.Context, info *interceptors.Test2Info, next goa.InterceptorEndpoint) (any, context.Context, error) { + log.Printf(ctx, "[Test2] Sending request: %v", info.RawPayload()) + resp, ctx, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[Test2] Error: %v", err) - return nil, err + return nil, ctx, err } log.Printf(ctx, "[Test2] Received response: %v", resp) - return resp, nil + return resp, ctx, nil } -func (i *MultipleServicesInterceptorsServiceClientInterceptors) Test4(ctx context.Context, info *interceptors.Test4Info, next goa.Endpoint) (any, error) { - log.Printf(ctx, "[Test4] Sending request: %v", info.RawPayload) - resp, err := next(ctx, info.RawPayload) +func (i *MultipleServicesInterceptorsServiceClientInterceptors) Test4(ctx context.Context, info *interceptors.Test4Info, next goa.InterceptorEndpoint) (any, context.Context, error) { + log.Printf(ctx, "[Test4] Sending request: %v", info.RawPayload()) + resp, ctx, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[Test4] Error: %v", err) - return nil, err + return nil, ctx, err } log.Printf(ctx, "[Test4] Received response: %v", resp) - return resp, nil + return resp, ctx, nil } diff --git a/codegen/service/testdata/example_interceptors/multiple_services_interceptors_service_server.golden b/codegen/service/testdata/example_interceptors/multiple_services_interceptors_service_server.golden index 4e780407ea..47d45b2270 100644 --- a/codegen/service/testdata/example_interceptors/multiple_services_interceptors_service_server.golden +++ b/codegen/service/testdata/example_interceptors/multiple_services_interceptors_service_server.golden @@ -23,23 +23,23 @@ type MultipleServicesInterceptorsServiceServerInterceptors struct { func NewMultipleServicesInterceptorsServiceServerInterceptors() *MultipleServicesInterceptorsServiceServerInterceptors { return &MultipleServicesInterceptorsServiceServerInterceptors{} } -func (i *MultipleServicesInterceptorsServiceServerInterceptors) Test(ctx context.Context, info *interceptors.TestInfo, next goa.Endpoint) (any, error) { - log.Printf(ctx, "[Test] Processing request: %v", info.RawPayload) - resp, err := next(ctx, info.RawPayload) +func (i *MultipleServicesInterceptorsServiceServerInterceptors) Test(ctx context.Context, info *interceptors.TestInfo, next goa.InterceptorEndpoint) (any, context.Context, error) { + log.Printf(ctx, "[Test] Processing request: %v", info.RawPayload()) + resp, ctx, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[Test] Error: %v", err) - return nil, err + return nil, ctx, err } log.Printf(ctx, "[Test] Response: %v", resp) - return resp, nil + return resp, ctx, nil } -func (i *MultipleServicesInterceptorsServiceServerInterceptors) Test3(ctx context.Context, info *interceptors.Test3Info, next goa.Endpoint) (any, error) { - log.Printf(ctx, "[Test3] Processing request: %v", info.RawPayload) - resp, err := next(ctx, info.RawPayload) +func (i *MultipleServicesInterceptorsServiceServerInterceptors) Test3(ctx context.Context, info *interceptors.Test3Info, next goa.InterceptorEndpoint) (any, context.Context, error) { + log.Printf(ctx, "[Test3] Processing request: %v", info.RawPayload()) + resp, ctx, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[Test3] Error: %v", err) - return nil, err + return nil, ctx, err } log.Printf(ctx, "[Test3] Response: %v", resp) - return resp, nil + return resp, ctx, nil } diff --git a/codegen/service/testdata/example_interceptors/server_interceptor_by_name_service_server.golden b/codegen/service/testdata/example_interceptors/server_interceptor_by_name_service_server.golden index 2660f90abe..aacac9a275 100644 --- a/codegen/service/testdata/example_interceptors/server_interceptor_by_name_service_server.golden +++ b/codegen/service/testdata/example_interceptors/server_interceptor_by_name_service_server.golden @@ -23,13 +23,13 @@ type ServerInterceptorByNameServiceServerInterceptors struct { func NewServerInterceptorByNameServiceServerInterceptors() *ServerInterceptorByNameServiceServerInterceptors { return &ServerInterceptorByNameServiceServerInterceptors{} } -func (i *ServerInterceptorByNameServiceServerInterceptors) Test(ctx context.Context, info *interceptors.TestInfo, next goa.Endpoint) (any, error) { - log.Printf(ctx, "[Test] Processing request: %v", info.RawPayload) - resp, err := next(ctx, info.RawPayload) +func (i *ServerInterceptorByNameServiceServerInterceptors) Test(ctx context.Context, info *interceptors.TestInfo, next goa.InterceptorEndpoint) (any, context.Context, error) { + log.Printf(ctx, "[Test] Processing request: %v", info.RawPayload()) + resp, ctx, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[Test] Error: %v", err) - return nil, err + return nil, ctx, err } log.Printf(ctx, "[Test] Response: %v", resp) - return resp, nil + return resp, ctx, nil } diff --git a/codegen/service/testdata/example_interceptors/server_interceptor_service_server.golden b/codegen/service/testdata/example_interceptors/server_interceptor_service_server.golden index 517fdbc27e..bbedae66fd 100644 --- a/codegen/service/testdata/example_interceptors/server_interceptor_service_server.golden +++ b/codegen/service/testdata/example_interceptors/server_interceptor_service_server.golden @@ -23,13 +23,13 @@ type ServerInterceptorServiceServerInterceptors struct { func NewServerInterceptorServiceServerInterceptors() *ServerInterceptorServiceServerInterceptors { return &ServerInterceptorServiceServerInterceptors{} } -func (i *ServerInterceptorServiceServerInterceptors) Test(ctx context.Context, info *interceptors.TestInfo, next goa.Endpoint) (any, error) { - log.Printf(ctx, "[Test] Processing request: %v", info.RawPayload) - resp, err := next(ctx, info.RawPayload) +func (i *ServerInterceptorServiceServerInterceptors) Test(ctx context.Context, info *interceptors.TestInfo, next goa.InterceptorEndpoint) (any, context.Context, error) { + log.Printf(ctx, "[Test] Processing request: %v", info.RawPayload()) + resp, ctx, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[Test] Error: %v", err) - return nil, err + return nil, ctx, err } log.Printf(ctx, "[Test] Response: %v", resp) - return resp, nil + return resp, ctx, nil } diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-payload_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-payload_interceptor_wrappers.go.golden index 7c27d0db47..d897206376 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-payload_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-payload_interceptor_wrappers.go.golden @@ -4,10 +4,10 @@ func wrapMethodValidation(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &ValidationInfo{ - Service: "InterceptorWithReadPayload", - Method: "Method", - CallType: goa.InterceptorUnary, - RawPayload: req, + service: "InterceptorWithReadPayload", + method: "Method", + callType: goa.InterceptorUnary, + payload: req, } return i.Validation(ctx, info, endpoint) } @@ -18,10 +18,10 @@ func wrapMethodValidation(endpoint goa.InterceptorEndpoint, i ServerInterceptors func wrapClientMethodValidation(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &ValidationInfo{ - Service: "InterceptorWithReadPayload", - Method: "Method", - CallType: goa.InterceptorUnary, - RawPayload: req, + service: "InterceptorWithReadPayload", + method: "Method", + callType: goa.InterceptorUnary, + payload: req, } return i.Validation(ctx, info, endpoint) } diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-payload_service_interceptors.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-payload_service_interceptors.go.golden index 1873bd5f0e..45748140a1 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-payload_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-payload_service_interceptors.go.golden @@ -10,7 +10,12 @@ type ServerInterceptors interface { type ( // ValidationInfo provides metadata about the current interception. // It includes service name, method name, and access to the endpoint. - ValidationInfo goa.InterceptorInfo + ValidationInfo struct { + service string + method string + callType goa.InterceptorCallType + payload any + } // ValidationPayload provides type-safe access to the method payload. // It allows reading and writing specific fields of the payload as defined @@ -43,9 +48,29 @@ func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoin // Public accessor methods for Info types +// Service returns the name of the service handling the request. +func (info *ValidationInfo) Service() string { + return info.service +} + +// Method returns the name of the method handling the request. +func (info *ValidationInfo) Method() string { + return info.method +} + +// CallType returns the type of call the interceptor is handling. +func (info *ValidationInfo) CallType() goa.InterceptorCallType { + return info.callType +} + +// RawPayload returns the raw payload of the request. +func (info *ValidationInfo) RawPayload() any { + return info.payload +} + // Payload returns a type-safe accessor for the method payload. func (info *ValidationInfo) Payload() ValidationPayload { - return &validationMethodPayload{payload: info.RawPayload.(*MethodPayload)} + return &validationMethodPayload{payload: info.RawPayload().(*MethodPayload)} } // Private implementation methods diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-result_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-result_interceptor_wrappers.go.golden index 4cdb85e8a6..109f07d9cc 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-result_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-result_interceptor_wrappers.go.golden @@ -4,10 +4,10 @@ func wrapMethodCaching(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &CachingInfo{ - Service: "InterceptorWithReadResult", - Method: "Method", - CallType: goa.InterceptorUnary, - RawPayload: req, + service: "InterceptorWithReadResult", + method: "Method", + callType: goa.InterceptorUnary, + payload: req, } return i.Caching(ctx, info, endpoint) } @@ -17,10 +17,10 @@ func wrapMethodCaching(endpoint goa.InterceptorEndpoint, i ServerInterceptors) g func wrapClientMethodCaching(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &CachingInfo{ - Service: "InterceptorWithReadResult", - Method: "Method", - CallType: goa.InterceptorUnary, - RawPayload: req, + service: "InterceptorWithReadResult", + method: "Method", + callType: goa.InterceptorUnary, + payload: req, } return i.Caching(ctx, info, endpoint) } diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-result_service_interceptors.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-result_service_interceptors.go.golden index b0f6ee9482..a2ef88307d 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-result_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-result_service_interceptors.go.golden @@ -10,7 +10,12 @@ type ServerInterceptors interface { type ( // CachingInfo provides metadata about the current interception. // It includes service name, method name, and access to the endpoint. - CachingInfo goa.InterceptorInfo + CachingInfo struct { + service string + method string + callType goa.InterceptorCallType + payload any + } // CachingResult provides type-safe access to the method result. // It allows reading and writing specific fields of the result as defined @@ -42,6 +47,27 @@ func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoin } // Public accessor methods for Info types + +// Service returns the name of the service handling the request. +func (info *CachingInfo) Service() string { + return info.service +} + +// Method returns the name of the method handling the request. +func (info *CachingInfo) Method() string { + return info.method +} + +// CallType returns the type of call the interceptor is handling. +func (info *CachingInfo) CallType() goa.InterceptorCallType { + return info.callType +} + +// RawPayload returns the raw payload of the request. +func (info *CachingInfo) RawPayload() any { + return info.payload +} + // Result returns a type-safe accessor for the method result. func (info *CachingInfo) Result(res any) CachingResult { return &cachingMethodResult{result: res.(*MethodResult)} diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_interceptor_wrappers.go.golden index 823c286e18..ed5d9bd672 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_interceptor_wrappers.go.golden @@ -4,10 +4,10 @@ func wrapMethodValidation(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &ValidationInfo{ - Service: "InterceptorWithReadWritePayload", - Method: "Method", - CallType: goa.InterceptorUnary, - RawPayload: req, + service: "InterceptorWithReadWritePayload", + method: "Method", + callType: goa.InterceptorUnary, + payload: req, } return i.Validation(ctx, info, endpoint) } @@ -18,10 +18,10 @@ func wrapMethodValidation(endpoint goa.InterceptorEndpoint, i ServerInterceptors func wrapClientMethodValidation(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &ValidationInfo{ - Service: "InterceptorWithReadWritePayload", - Method: "Method", - CallType: goa.InterceptorUnary, - RawPayload: req, + service: "InterceptorWithReadWritePayload", + method: "Method", + callType: goa.InterceptorUnary, + payload: req, } return i.Validation(ctx, info, endpoint) } diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_service_interceptors.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_service_interceptors.go.golden index ef6b6cc357..05890a8824 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_service_interceptors.go.golden @@ -10,7 +10,12 @@ type ServerInterceptors interface { type ( // ValidationInfo provides metadata about the current interception. // It includes service name, method name, and access to the endpoint. - ValidationInfo goa.InterceptorInfo + ValidationInfo struct { + service string + method string + callType goa.InterceptorCallType + payload any + } // ValidationPayload provides type-safe access to the method payload. // It allows reading and writing specific fields of the payload as defined @@ -44,9 +49,29 @@ func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoin // Public accessor methods for Info types +// Service returns the name of the service handling the request. +func (info *ValidationInfo) Service() string { + return info.service +} + +// Method returns the name of the method handling the request. +func (info *ValidationInfo) Method() string { + return info.method +} + +// CallType returns the type of call the interceptor is handling. +func (info *ValidationInfo) CallType() goa.InterceptorCallType { + return info.callType +} + +// RawPayload returns the raw payload of the request. +func (info *ValidationInfo) RawPayload() any { + return info.payload +} + // Payload returns a type-safe accessor for the method payload. func (info *ValidationInfo) Payload() ValidationPayload { - return &validationMethodPayload{payload: info.RawPayload.(*MethodPayload)} + return &validationMethodPayload{payload: info.RawPayload().(*MethodPayload)} } // Private implementation methods diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-write-result_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-write-result_interceptor_wrappers.go.golden index 74c50e35aa..af5078707b 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-write-result_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-write-result_interceptor_wrappers.go.golden @@ -4,10 +4,10 @@ func wrapMethodCaching(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &CachingInfo{ - Service: "InterceptorWithReadWriteResult", - Method: "Method", - CallType: goa.InterceptorUnary, - RawPayload: req, + service: "InterceptorWithReadWriteResult", + method: "Method", + callType: goa.InterceptorUnary, + payload: req, } return i.Caching(ctx, info, endpoint) } @@ -17,10 +17,10 @@ func wrapMethodCaching(endpoint goa.InterceptorEndpoint, i ServerInterceptors) g func wrapClientMethodCaching(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &CachingInfo{ - Service: "InterceptorWithReadWriteResult", - Method: "Method", - CallType: goa.InterceptorUnary, - RawPayload: req, + service: "InterceptorWithReadWriteResult", + method: "Method", + callType: goa.InterceptorUnary, + payload: req, } return i.Caching(ctx, info, endpoint) } diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-write-result_service_interceptors.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-write-result_service_interceptors.go.golden index 572f287895..48ac781c30 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-write-result_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-write-result_service_interceptors.go.golden @@ -10,7 +10,12 @@ type ServerInterceptors interface { type ( // CachingInfo provides metadata about the current interception. // It includes service name, method name, and access to the endpoint. - CachingInfo goa.InterceptorInfo + CachingInfo struct { + service string + method string + callType goa.InterceptorCallType + payload any + } // CachingResult provides type-safe access to the method result. // It allows reading and writing specific fields of the result as defined @@ -43,6 +48,27 @@ func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoin } // Public accessor methods for Info types + +// Service returns the name of the service handling the request. +func (info *CachingInfo) Service() string { + return info.service +} + +// Method returns the name of the method handling the request. +func (info *CachingInfo) Method() string { + return info.method +} + +// CallType returns the type of call the interceptor is handling. +func (info *CachingInfo) CallType() goa.InterceptorCallType { + return info.callType +} + +// RawPayload returns the raw payload of the request. +func (info *CachingInfo) RawPayload() any { + return info.payload +} + // Result returns a type-safe accessor for the method result. func (info *CachingInfo) Result(res any) CachingResult { return &cachingMethodResult{result: res.(*MethodResult)} diff --git a/codegen/service/testdata/interceptors/interceptor-with-write-payload_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/interceptor-with-write-payload_interceptor_wrappers.go.golden index 05f76f2420..04b7626d29 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-write-payload_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-write-payload_interceptor_wrappers.go.golden @@ -4,10 +4,10 @@ func wrapMethodValidation(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &ValidationInfo{ - Service: "InterceptorWithWritePayload", - Method: "Method", - CallType: goa.InterceptorUnary, - RawPayload: req, + service: "InterceptorWithWritePayload", + method: "Method", + callType: goa.InterceptorUnary, + payload: req, } return i.Validation(ctx, info, endpoint) } @@ -18,10 +18,10 @@ func wrapMethodValidation(endpoint goa.InterceptorEndpoint, i ServerInterceptors func wrapClientMethodValidation(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &ValidationInfo{ - Service: "InterceptorWithWritePayload", - Method: "Method", - CallType: goa.InterceptorUnary, - RawPayload: req, + service: "InterceptorWithWritePayload", + method: "Method", + callType: goa.InterceptorUnary, + payload: req, } return i.Validation(ctx, info, endpoint) } diff --git a/codegen/service/testdata/interceptors/interceptor-with-write-payload_service_interceptors.go.golden b/codegen/service/testdata/interceptors/interceptor-with-write-payload_service_interceptors.go.golden index 3fd38592ad..eaee77f00b 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-write-payload_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-write-payload_service_interceptors.go.golden @@ -10,7 +10,12 @@ type ServerInterceptors interface { type ( // ValidationInfo provides metadata about the current interception. // It includes service name, method name, and access to the endpoint. - ValidationInfo goa.InterceptorInfo + ValidationInfo struct { + service string + method string + callType goa.InterceptorCallType + payload any + } // ValidationPayload provides type-safe access to the method payload. // It allows reading and writing specific fields of the payload as defined @@ -43,9 +48,29 @@ func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoin // Public accessor methods for Info types +// Service returns the name of the service handling the request. +func (info *ValidationInfo) Service() string { + return info.service +} + +// Method returns the name of the method handling the request. +func (info *ValidationInfo) Method() string { + return info.method +} + +// CallType returns the type of call the interceptor is handling. +func (info *ValidationInfo) CallType() goa.InterceptorCallType { + return info.callType +} + +// RawPayload returns the raw payload of the request. +func (info *ValidationInfo) RawPayload() any { + return info.payload +} + // Payload returns a type-safe accessor for the method payload. func (info *ValidationInfo) Payload() ValidationPayload { - return &validationMethodPayload{payload: info.RawPayload.(*MethodPayload)} + return &validationMethodPayload{payload: info.RawPayload().(*MethodPayload)} } // Private implementation methods diff --git a/codegen/service/testdata/interceptors/interceptor-with-write-result_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/interceptor-with-write-result_interceptor_wrappers.go.golden index 6d5f4afeb6..0844de7780 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-write-result_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-write-result_interceptor_wrappers.go.golden @@ -4,10 +4,10 @@ func wrapMethodCaching(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &CachingInfo{ - Service: "InterceptorWithWriteResult", - Method: "Method", - CallType: goa.InterceptorUnary, - RawPayload: req, + service: "InterceptorWithWriteResult", + method: "Method", + callType: goa.InterceptorUnary, + payload: req, } return i.Caching(ctx, info, endpoint) } @@ -17,10 +17,10 @@ func wrapMethodCaching(endpoint goa.InterceptorEndpoint, i ServerInterceptors) g func wrapClientMethodCaching(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &CachingInfo{ - Service: "InterceptorWithWriteResult", - Method: "Method", - CallType: goa.InterceptorUnary, - RawPayload: req, + service: "InterceptorWithWriteResult", + method: "Method", + callType: goa.InterceptorUnary, + payload: req, } return i.Caching(ctx, info, endpoint) } diff --git a/codegen/service/testdata/interceptors/interceptor-with-write-result_service_interceptors.go.golden b/codegen/service/testdata/interceptors/interceptor-with-write-result_service_interceptors.go.golden index b3c44eafe5..11cb55d4e9 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-write-result_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-write-result_service_interceptors.go.golden @@ -10,7 +10,12 @@ type ServerInterceptors interface { type ( // CachingInfo provides metadata about the current interception. // It includes service name, method name, and access to the endpoint. - CachingInfo goa.InterceptorInfo + CachingInfo struct { + service string + method string + callType goa.InterceptorCallType + payload any + } // CachingResult provides type-safe access to the method result. // It allows reading and writing specific fields of the result as defined @@ -42,6 +47,27 @@ func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoin } // Public accessor methods for Info types + +// Service returns the name of the service handling the request. +func (info *CachingInfo) Service() string { + return info.service +} + +// Method returns the name of the method handling the request. +func (info *CachingInfo) Method() string { + return info.method +} + +// CallType returns the type of call the interceptor is handling. +func (info *CachingInfo) CallType() goa.InterceptorCallType { + return info.callType +} + +// RawPayload returns the raw payload of the request. +func (info *CachingInfo) RawPayload() any { + return info.payload +} + // Result returns a type-safe accessor for the method result. func (info *CachingInfo) Result(res any) CachingResult { return &cachingMethodResult{result: res.(*MethodResult)} diff --git a/codegen/service/testdata/interceptors/multiple-interceptors_client_interceptors.go.golden b/codegen/service/testdata/interceptors/multiple-interceptors_client_interceptors.go.golden index a1df7e470b..273d4023f3 100644 --- a/codegen/service/testdata/interceptors/multiple-interceptors_client_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/multiple-interceptors_client_interceptors.go.golden @@ -11,10 +11,20 @@ type ClientInterceptors interface { type ( // Test2Info provides metadata about the current interception. // It includes service name, method name, and access to the endpoint. - Test2Info goa.InterceptorInfo + Test2Info struct { + service string + method string + callType goa.InterceptorCallType + payload any + } // Test4Info provides metadata about the current interception. // It includes service name, method name, and access to the endpoint. - Test4Info goa.InterceptorInfo + Test4Info struct { + service string + method string + callType goa.InterceptorCallType + payload any + } ) // WrapMethodClientEndpoint wraps the Method endpoint with the client diff --git a/codegen/service/testdata/interceptors/multiple-interceptors_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/multiple-interceptors_interceptor_wrappers.go.golden index 9fb3e9dbd6..e9a124ba23 100644 --- a/codegen/service/testdata/interceptors/multiple-interceptors_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/multiple-interceptors_interceptor_wrappers.go.golden @@ -4,10 +4,10 @@ func wrapMethodTest(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &TestInfo{ - Service: "MultipleInterceptorsService", - Method: "Method", - CallType: goa.InterceptorUnary, - RawPayload: req, + service: "MultipleInterceptorsService", + method: "Method", + callType: goa.InterceptorUnary, + payload: req, } return i.Test(ctx, info, endpoint) } @@ -17,10 +17,10 @@ func wrapMethodTest(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa. func wrapMethodTest3(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &Test3Info{ - Service: "MultipleInterceptorsService", - Method: "Method", - CallType: goa.InterceptorUnary, - RawPayload: req, + service: "MultipleInterceptorsService", + method: "Method", + callType: goa.InterceptorUnary, + payload: req, } return i.Test3(ctx, info, endpoint) } @@ -30,10 +30,10 @@ func wrapMethodTest3(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa func wrapClientMethodTest2(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &Test2Info{ - Service: "MultipleInterceptorsService", - Method: "Method", - CallType: goa.InterceptorUnary, - RawPayload: req, + service: "MultipleInterceptorsService", + method: "Method", + callType: goa.InterceptorUnary, + payload: req, } return i.Test2(ctx, info, endpoint) } @@ -43,10 +43,10 @@ func wrapClientMethodTest2(endpoint goa.InterceptorEndpoint, i ClientInterceptor func wrapClientMethodTest4(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &Test4Info{ - Service: "MultipleInterceptorsService", - Method: "Method", - CallType: goa.InterceptorUnary, - RawPayload: req, + service: "MultipleInterceptorsService", + method: "Method", + callType: goa.InterceptorUnary, + payload: req, } return i.Test4(ctx, info, endpoint) } diff --git a/codegen/service/testdata/interceptors/multiple-interceptors_service_interceptors.go.golden b/codegen/service/testdata/interceptors/multiple-interceptors_service_interceptors.go.golden index 66db059d49..744bd9c60f 100644 --- a/codegen/service/testdata/interceptors/multiple-interceptors_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/multiple-interceptors_service_interceptors.go.golden @@ -11,10 +11,20 @@ type ServerInterceptors interface { type ( // TestInfo provides metadata about the current interception. // It includes service name, method name, and access to the endpoint. - TestInfo goa.InterceptorInfo + TestInfo struct { + service string + method string + callType goa.InterceptorCallType + payload any + } // Test3Info provides metadata about the current interception. // It includes service name, method name, and access to the endpoint. - Test3Info goa.InterceptorInfo + Test3Info struct { + service string + method string + callType goa.InterceptorCallType + payload any + } ) // WrapMethodEndpoint wraps the Method endpoint with the server-side diff --git a/codegen/service/testdata/interceptors/single-api-server-interceptor_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/single-api-server-interceptor_interceptor_wrappers.go.golden index 495fbff0df..bd3a9c06fd 100644 --- a/codegen/service/testdata/interceptors/single-api-server-interceptor_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/single-api-server-interceptor_interceptor_wrappers.go.golden @@ -4,10 +4,10 @@ func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &LoggingInfo{ - Service: "SingleAPIServerInterceptor", - Method: "Method", - CallType: goa.InterceptorUnary, - RawPayload: req, + service: "SingleAPIServerInterceptor", + method: "Method", + callType: goa.InterceptorUnary, + payload: req, } return i.Logging(ctx, info, endpoint) } @@ -17,10 +17,10 @@ func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) g func wrapMethod2Logging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &LoggingInfo{ - Service: "SingleAPIServerInterceptor", - Method: "Method2", - CallType: goa.InterceptorUnary, - RawPayload: req, + service: "SingleAPIServerInterceptor", + method: "Method2", + callType: goa.InterceptorUnary, + payload: req, } return i.Logging(ctx, info, endpoint) } diff --git a/codegen/service/testdata/interceptors/single-api-server-interceptor_service_interceptors.go.golden b/codegen/service/testdata/interceptors/single-api-server-interceptor_service_interceptors.go.golden index 47c50507e4..4e8f5ea6b4 100644 --- a/codegen/service/testdata/interceptors/single-api-server-interceptor_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/single-api-server-interceptor_service_interceptors.go.golden @@ -10,7 +10,12 @@ type ServerInterceptors interface { type ( // LoggingInfo provides metadata about the current interception. // It includes service name, method name, and access to the endpoint. - LoggingInfo goa.InterceptorInfo + LoggingInfo struct { + service string + method string + callType goa.InterceptorCallType + payload any + } ) // WrapMethodEndpoint wraps the Method endpoint with the server-side diff --git a/codegen/service/testdata/interceptors/single-client-interceptor_client_interceptors.go.golden b/codegen/service/testdata/interceptors/single-client-interceptor_client_interceptors.go.golden index ee25058df4..4d1d3d6438 100644 --- a/codegen/service/testdata/interceptors/single-client-interceptor_client_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/single-client-interceptor_client_interceptors.go.golden @@ -10,7 +10,12 @@ type ClientInterceptors interface { type ( // TracingInfo provides metadata about the current interception. // It includes service name, method name, and access to the endpoint. - TracingInfo goa.InterceptorInfo + TracingInfo struct { + service string + method string + callType goa.InterceptorCallType + payload any + } ) // WrapMethodClientEndpoint wraps the Method endpoint with the client diff --git a/codegen/service/testdata/interceptors/single-client-interceptor_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/single-client-interceptor_interceptor_wrappers.go.golden index 691c0863a2..60b26a481d 100644 --- a/codegen/service/testdata/interceptors/single-client-interceptor_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/single-client-interceptor_interceptor_wrappers.go.golden @@ -4,10 +4,10 @@ func wrapClientMethodTracing(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &TracingInfo{ - Service: "SingleClientInterceptor", - Method: "Method", - CallType: goa.InterceptorUnary, - RawPayload: req, + service: "SingleClientInterceptor", + method: "Method", + callType: goa.InterceptorUnary, + payload: req, } return i.Tracing(ctx, info, endpoint) } diff --git a/codegen/service/testdata/interceptors/single-method-server-interceptor_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/single-method-server-interceptor_interceptor_wrappers.go.golden index 185ae87fb4..146e75002d 100644 --- a/codegen/service/testdata/interceptors/single-method-server-interceptor_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/single-method-server-interceptor_interceptor_wrappers.go.golden @@ -4,10 +4,10 @@ func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &LoggingInfo{ - Service: "SingleMethodServerInterceptor", - Method: "Method", - CallType: goa.InterceptorUnary, - RawPayload: req, + service: "SingleMethodServerInterceptor", + method: "Method", + callType: goa.InterceptorUnary, + payload: req, } return i.Logging(ctx, info, endpoint) } diff --git a/codegen/service/testdata/interceptors/single-method-server-interceptor_service_interceptors.go.golden b/codegen/service/testdata/interceptors/single-method-server-interceptor_service_interceptors.go.golden index 411e5fd142..82065f7595 100644 --- a/codegen/service/testdata/interceptors/single-method-server-interceptor_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/single-method-server-interceptor_service_interceptors.go.golden @@ -10,7 +10,12 @@ type ServerInterceptors interface { type ( // LoggingInfo provides metadata about the current interception. // It includes service name, method name, and access to the endpoint. - LoggingInfo goa.InterceptorInfo + LoggingInfo struct { + service string + method string + callType goa.InterceptorCallType + payload any + } ) // WrapMethodEndpoint wraps the Method endpoint with the server-side diff --git a/codegen/service/testdata/interceptors/single-service-server-interceptor_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/single-service-server-interceptor_interceptor_wrappers.go.golden index 6045e2ac9d..9df1a34dff 100644 --- a/codegen/service/testdata/interceptors/single-service-server-interceptor_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/single-service-server-interceptor_interceptor_wrappers.go.golden @@ -4,10 +4,10 @@ func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &LoggingInfo{ - Service: "SingleServerInterceptor", - Method: "Method", - CallType: goa.InterceptorUnary, - RawPayload: req, + service: "SingleServerInterceptor", + method: "Method", + callType: goa.InterceptorUnary, + payload: req, } return i.Logging(ctx, info, endpoint) } @@ -17,10 +17,10 @@ func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) g func wrapMethod2Logging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &LoggingInfo{ - Service: "SingleServerInterceptor", - Method: "Method2", - CallType: goa.InterceptorUnary, - RawPayload: req, + service: "SingleServerInterceptor", + method: "Method2", + callType: goa.InterceptorUnary, + payload: req, } return i.Logging(ctx, info, endpoint) } diff --git a/codegen/service/testdata/interceptors/single-service-server-interceptor_service_interceptors.go.golden b/codegen/service/testdata/interceptors/single-service-server-interceptor_service_interceptors.go.golden index 47c50507e4..4e8f5ea6b4 100644 --- a/codegen/service/testdata/interceptors/single-service-server-interceptor_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/single-service-server-interceptor_service_interceptors.go.golden @@ -10,7 +10,12 @@ type ServerInterceptors interface { type ( // LoggingInfo provides metadata about the current interception. // It includes service name, method name, and access to the endpoint. - LoggingInfo goa.InterceptorInfo + LoggingInfo struct { + service string + method string + callType goa.InterceptorCallType + payload any + } ) // WrapMethodEndpoint wraps the Method endpoint with the server-side diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_interceptor_wrappers.go.golden index 1ec772951c..08f9bd55b0 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_interceptor_wrappers.go.golden @@ -20,10 +20,10 @@ type wrappedMethodClientStream struct { func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &LoggingInfo{ - Service: "StreamingInterceptorsWithReadPayloadAndReadStreamingPayload", - Method: "Method", - CallType: goa.InterceptorUnary, - RawPayload: req, + service: "StreamingInterceptorsWithReadPayloadAndReadStreamingPayload", + method: "Method", + callType: goa.InterceptorUnary, + payload: req, } res, ctx, err := i.Logging(ctx, info, endpoint) if err != nil { @@ -34,9 +34,9 @@ func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) g ctx: ctx, recvWithContext: func(ctx context.Context) (*MethodStreamingPayload, context.Context, error) { info := &LoggingInfo{ - Service: "StreamingInterceptorsWithReadPayloadAndReadStreamingPayload", - Method: "Method", - CallType: goa.InterceptorStreamingRecv, + service: "StreamingInterceptorsWithReadPayloadAndReadStreamingPayload", + method: "Method", + callType: goa.InterceptorStreamingRecv, } res, ctx, err := i.Logging(ctx, info, func(ctx context.Context, _ any) (any, context.Context, error) { return stream.RecvWithContext(ctx) @@ -53,10 +53,10 @@ func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) g func wrapClientMethodLogging(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &LoggingInfo{ - Service: "StreamingInterceptorsWithReadPayloadAndReadStreamingPayload", - Method: "Method", - CallType: goa.InterceptorUnary, - RawPayload: req, + service: "StreamingInterceptorsWithReadPayloadAndReadStreamingPayload", + method: "Method", + callType: goa.InterceptorUnary, + payload: req, } res, ctx, err := i.Logging(ctx, info, endpoint) if err != nil { @@ -67,10 +67,10 @@ func wrapClientMethodLogging(endpoint goa.InterceptorEndpoint, i ClientIntercept ctx: ctx, sendWithContext: func(ctx context.Context, req *MethodStreamingPayload) (context.Context, error) { info := &LoggingInfo{ - Service: "StreamingInterceptorsWithReadPayloadAndReadStreamingPayload", - Method: "Method", - CallType: goa.InterceptorStreamingSend, - RawPayload: req, + service: "StreamingInterceptorsWithReadPayloadAndReadStreamingPayload", + method: "Method", + callType: goa.InterceptorStreamingSend, + payload: req, } _, ctx, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, context.Context, error) { castReq, _ := req.(*MethodStreamingPayload) diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_service_interceptors.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_service_interceptors.go.golden index 66752aedbb..31ac7968e2 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_service_interceptors.go.golden @@ -10,7 +10,12 @@ type ServerInterceptors interface { type ( // LoggingInfo provides metadata about the current interception. // It includes service name, method name, and access to the endpoint. - LoggingInfo goa.InterceptorInfo + LoggingInfo struct { + service string + method string + callType goa.InterceptorCallType + payload any + } // LoggingPayload provides type-safe access to the method payload. // It allows reading and writing specific fields of the payload as defined @@ -53,14 +58,34 @@ func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoin // Public accessor methods for Info types +// Service returns the name of the service handling the request. +func (info *LoggingInfo) Service() string { + return info.service +} + +// Method returns the name of the method handling the request. +func (info *LoggingInfo) Method() string { + return info.method +} + +// CallType returns the type of call the interceptor is handling. +func (info *LoggingInfo) CallType() goa.InterceptorCallType { + return info.callType +} + +// RawPayload returns the raw payload of the request. +func (info *LoggingInfo) RawPayload() any { + return info.payload +} + // Payload returns a type-safe accessor for the method payload. func (info *LoggingInfo) Payload() LoggingPayload { - return &loggingMethodPayload{payload: info.RawPayload.(*MethodPayload)} + return &loggingMethodPayload{payload: info.RawPayload().(*MethodPayload)} } // StreamingPayload returns a type-safe accessor for the method streaming payload. func (info *LoggingInfo) StreamingPayload() LoggingStreamingPayload { - return &loggingMethodStreamingPayload{payload: info.RawPayload.(*MethodStreamingPayload)} + return &loggingMethodStreamingPayload{payload: info.RawPayload().(*MethodStreamingPayload)} } // Private implementation methods diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_interceptor_wrappers.go.golden index 5b5eb93f10..11d355d6a5 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_interceptor_wrappers.go.golden @@ -4,10 +4,10 @@ func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &LoggingInfo{ - Service: "StreamingInterceptorsWithReadPayload", - Method: "Method", - CallType: goa.InterceptorUnary, - RawPayload: req, + service: "StreamingInterceptorsWithReadPayload", + method: "Method", + callType: goa.InterceptorUnary, + payload: req, } return i.Logging(ctx, info, endpoint) } diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_service_interceptors.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_service_interceptors.go.golden index 68b3f20c34..dfb547386b 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_service_interceptors.go.golden @@ -10,7 +10,12 @@ type ServerInterceptors interface { type ( // LoggingInfo provides metadata about the current interception. // It includes service name, method name, and access to the endpoint. - LoggingInfo goa.InterceptorInfo + LoggingInfo struct { + service string + method string + callType goa.InterceptorCallType + payload any + } // LoggingPayload provides type-safe access to the method payload. // It allows reading and writing specific fields of the payload as defined @@ -43,9 +48,29 @@ func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoin // Public accessor methods for Info types +// Service returns the name of the service handling the request. +func (info *LoggingInfo) Service() string { + return info.service +} + +// Method returns the name of the method handling the request. +func (info *LoggingInfo) Method() string { + return info.method +} + +// CallType returns the type of call the interceptor is handling. +func (info *LoggingInfo) CallType() goa.InterceptorCallType { + return info.callType +} + +// RawPayload returns the raw payload of the request. +func (info *LoggingInfo) RawPayload() any { + return info.payload +} + // Payload returns a type-safe accessor for the method payload. func (info *LoggingInfo) Payload() LoggingPayload { - return &loggingMethodPayload{payload: info.RawPayload.(*MethodPayload)} + return &loggingMethodPayload{payload: info.RawPayload().(*MethodPayload)} } // Private implementation methods diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_interceptor_wrappers.go.golden index 04e149d9e0..add4914dbd 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_interceptor_wrappers.go.golden @@ -4,10 +4,10 @@ func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &LoggingInfo{ - Service: "StreamingInterceptorsWithReadResult", - Method: "Method", - CallType: goa.InterceptorUnary, - RawPayload: req, + service: "StreamingInterceptorsWithReadResult", + method: "Method", + callType: goa.InterceptorUnary, + payload: req, } return i.Logging(ctx, info, endpoint) } diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_service_interceptors.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_service_interceptors.go.golden index 650a217a5f..d76b8adbc3 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_service_interceptors.go.golden @@ -10,7 +10,12 @@ type ServerInterceptors interface { type ( // LoggingInfo provides metadata about the current interception. // It includes service name, method name, and access to the endpoint. - LoggingInfo goa.InterceptorInfo + LoggingInfo struct { + service string + method string + callType goa.InterceptorCallType + payload any + } // LoggingResult provides type-safe access to the method result. // It allows reading and writing specific fields of the result as defined @@ -42,6 +47,27 @@ func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoin } // Public accessor methods for Info types + +// Service returns the name of the service handling the request. +func (info *LoggingInfo) Service() string { + return info.service +} + +// Method returns the name of the method handling the request. +func (info *LoggingInfo) Method() string { + return info.method +} + +// CallType returns the type of call the interceptor is handling. +func (info *LoggingInfo) CallType() goa.InterceptorCallType { + return info.callType +} + +// RawPayload returns the raw payload of the request. +func (info *LoggingInfo) RawPayload() any { + return info.payload +} + // Result returns a type-safe accessor for the method result. func (info *LoggingInfo) Result(res any) LoggingResult { return &loggingMethodResult{result: res.(*MethodResult)} diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_interceptor_wrappers.go.golden index 7a72f914af..edb650ddb6 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_interceptor_wrappers.go.golden @@ -28,10 +28,10 @@ func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) g ctx: ctx, sendWithContext: func(ctx context.Context, req *MethodResult) (context.Context, error) { info := &LoggingInfo{ - Service: "StreamingInterceptorsWithReadStreamingResult", - Method: "Method", - CallType: goa.InterceptorStreamingSend, - RawPayload: req, + service: "StreamingInterceptorsWithReadStreamingResult", + method: "Method", + callType: goa.InterceptorStreamingSend, + payload: req, } _, ctx, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, context.Context, error) { castReq, _ := req.(*MethodResult) @@ -57,9 +57,9 @@ func wrapClientMethodLogging(endpoint goa.InterceptorEndpoint, i ClientIntercept ctx: ctx, recvWithContext: func(ctx context.Context) (*MethodResult, context.Context, error) { info := &LoggingInfo{ - Service: "StreamingInterceptorsWithReadStreamingResult", - Method: "Method", - CallType: goa.InterceptorStreamingRecv, + service: "StreamingInterceptorsWithReadStreamingResult", + method: "Method", + callType: goa.InterceptorStreamingRecv, } res, ctx, err := i.Logging(ctx, info, func(ctx context.Context, _ any) (any, context.Context, error) { return stream.RecvWithContext(ctx) diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_service_interceptors.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_service_interceptors.go.golden index 12bde5c8d2..bec998ff1c 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_service_interceptors.go.golden @@ -10,7 +10,12 @@ type ServerInterceptors interface { type ( // LoggingInfo provides metadata about the current interception. // It includes service name, method name, and access to the endpoint. - LoggingInfo goa.InterceptorInfo + LoggingInfo struct { + service string + method string + callType goa.InterceptorCallType + payload any + } // LoggingStreamingResult provides type-safe access to the method streaming result. // It allows reading and writing specific fields of the streaming result as defined @@ -42,6 +47,27 @@ func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoin } // Public accessor methods for Info types + +// Service returns the name of the service handling the request. +func (info *LoggingInfo) Service() string { + return info.service +} + +// Method returns the name of the method handling the request. +func (info *LoggingInfo) Method() string { + return info.method +} + +// CallType returns the type of call the interceptor is handling. +func (info *LoggingInfo) CallType() goa.InterceptorCallType { + return info.callType +} + +// RawPayload returns the raw payload of the request. +func (info *LoggingInfo) RawPayload() any { + return info.payload +} + // StreamingResult returns a type-safe accessor for the method streaming result. func (info *LoggingInfo) StreamingResult(res any) LoggingStreamingResult { return &loggingMethodStreamingResult{result: res.(*MethodResult)} diff --git a/codegen/service/testdata/interceptors/streaming-interceptors_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors_interceptor_wrappers.go.golden index dad0c4efd9..b4fe7c4238 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors_interceptor_wrappers.go.golden @@ -30,10 +30,10 @@ func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) g ctx: ctx, sendWithContext: func(ctx context.Context, req *MethodResult) (context.Context, error) { info := &LoggingInfo{ - Service: "StreamingInterceptors", - Method: "Method", - CallType: goa.InterceptorStreamingSend, - RawPayload: req, + service: "StreamingInterceptors", + method: "Method", + callType: goa.InterceptorStreamingSend, + payload: req, } _, ctx, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, context.Context, error) { castReq, _ := req.(*MethodResult) @@ -44,9 +44,9 @@ func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) g }, recvWithContext: func(ctx context.Context) (*MethodStreamingPayload, context.Context, error) { info := &LoggingInfo{ - Service: "StreamingInterceptors", - Method: "Method", - CallType: goa.InterceptorStreamingRecv, + service: "StreamingInterceptors", + method: "Method", + callType: goa.InterceptorStreamingRecv, } res, ctx, err := i.Logging(ctx, info, func(ctx context.Context, _ any) (any, context.Context, error) { return stream.RecvWithContext(ctx) @@ -71,10 +71,10 @@ func wrapClientMethodLogging(endpoint goa.InterceptorEndpoint, i ClientIntercept ctx: ctx, sendWithContext: func(ctx context.Context, req *MethodStreamingPayload) (context.Context, error) { info := &LoggingInfo{ - Service: "StreamingInterceptors", - Method: "Method", - CallType: goa.InterceptorStreamingSend, - RawPayload: req, + service: "StreamingInterceptors", + method: "Method", + callType: goa.InterceptorStreamingSend, + payload: req, } _, ctx, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, context.Context, error) { castReq, _ := req.(*MethodStreamingPayload) @@ -85,9 +85,9 @@ func wrapClientMethodLogging(endpoint goa.InterceptorEndpoint, i ClientIntercept }, recvWithContext: func(ctx context.Context) (*MethodResult, context.Context, error) { info := &LoggingInfo{ - Service: "StreamingInterceptors", - Method: "Method", - CallType: goa.InterceptorStreamingRecv, + service: "StreamingInterceptors", + method: "Method", + callType: goa.InterceptorStreamingRecv, } res, ctx, err := i.Logging(ctx, info, func(ctx context.Context, _ any) (any, context.Context, error) { return stream.RecvWithContext(ctx) diff --git a/codegen/service/testdata/interceptors/streaming-interceptors_service_interceptors.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors_service_interceptors.go.golden index f2004b0487..de9b3ee6fc 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors_service_interceptors.go.golden @@ -10,7 +10,12 @@ type ServerInterceptors interface { type ( // LoggingInfo provides metadata about the current interception. // It includes service name, method name, and access to the endpoint. - LoggingInfo goa.InterceptorInfo + LoggingInfo struct { + service string + method string + callType goa.InterceptorCallType + payload any + } // LoggingStreamingPayload provides type-safe access to the method streaming payload. // It allows reading and writing specific fields of the streaming payload as defined @@ -54,9 +59,30 @@ func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoin } // Public accessor methods for Info types + +// Service returns the name of the service handling the request. +func (info *LoggingInfo) Service() string { + return info.service +} + +// Method returns the name of the method handling the request. +func (info *LoggingInfo) Method() string { + return info.method +} + +// CallType returns the type of call the interceptor is handling. +func (info *LoggingInfo) CallType() goa.InterceptorCallType { + return info.callType +} + +// RawPayload returns the raw payload of the request. +func (info *LoggingInfo) RawPayload() any { + return info.payload +} + // StreamingPayload returns a type-safe accessor for the method streaming payload. func (info *LoggingInfo) StreamingPayload() LoggingStreamingPayload { - return &loggingMethodStreamingPayload{payload: info.RawPayload.(*MethodStreamingPayload)} + return &loggingMethodStreamingPayload{payload: info.RawPayload().(*MethodStreamingPayload)} } // StreamingResult returns a type-safe accessor for the method streaming result. diff --git a/pkg/interceptor.go b/pkg/interceptor.go index 368d9efd92..ff9d9948e8 100644 --- a/pkg/interceptor.go +++ b/pkg/interceptor.go @@ -7,15 +7,15 @@ type ( // all interceptors in the service chain. It provides access to the service name, // method name, the type of call the interceptor is handling (unary, streaming send, // or streaming recv), and the request payload. - InterceptorInfo struct { - // Name of service handling request - Service string - // Name of method handling request - Method string - // CallType is the type of call the interceptor is handling - CallType InterceptorCallType - // Payload of request - RawPayload any + InterceptorInfo interface { + // Service returns the name of the service handling the request. + Service() string + // Method returns the name of the method handling the request. + Method() string + // CallType returns the type of call the interceptor is handling. + CallType() InterceptorCallType + // RawPayload returns the raw payload of the request. + RawPayload() any } // InterceptorEndpoint is the endpoint function interface that interceptors call. It differs from the From 8035d6986989fa246851c88c9ff05325ac00a8b4 Mon Sep 17 00:00:00 2001 From: Douglas Thrift Date: Wed, 5 Feb 2025 15:18:26 -0800 Subject: [PATCH 20/23] Separate StreamingPayload and StreamingResult methods to Client and Server variations --- .../client_interceptor_wrappers.go.tpl | 6 +-- codegen/service/templates/interceptors.go.tpl | 46 +++++++++++++++++-- .../templates/interceptors_types.go.tpl | 8 ++-- .../server_interceptor_wrappers.go.tpl | 6 +-- ...ead-payload_interceptor_wrappers.go.golden | 16 +++---- ...ead-payload_service_interceptors.go.golden | 10 ++-- ...read-result_interceptor_wrappers.go.golden | 16 +++---- ...read-result_service_interceptors.go.golden | 10 ++-- ...ite-payload_interceptor_wrappers.go.golden | 16 +++---- ...ite-payload_service_interceptors.go.golden | 10 ++-- ...rite-result_interceptor_wrappers.go.golden | 16 +++---- ...rite-result_service_interceptors.go.golden | 10 ++-- ...ite-payload_interceptor_wrappers.go.golden | 16 +++---- ...ite-payload_service_interceptors.go.golden | 10 ++-- ...rite-result_interceptor_wrappers.go.golden | 16 +++---- ...rite-result_service_interceptors.go.golden | 10 ++-- ...interceptors_client_interceptors.go.golden | 16 +++---- ...nterceptors_interceptor_wrappers.go.golden | 32 ++++++------- ...nterceptors_service_interceptors.go.golden | 16 +++---- ...interceptor_interceptor_wrappers.go.golden | 16 +++---- ...interceptor_service_interceptors.go.golden | 8 ++-- ...-interceptor_client_interceptors.go.golden | 8 ++-- ...interceptor_interceptor_wrappers.go.golden | 8 ++-- ...interceptor_interceptor_wrappers.go.golden | 8 ++-- ...interceptor_service_interceptors.go.golden | 8 ++-- ...interceptor_interceptor_wrappers.go.golden | 16 +++---- ...interceptor_service_interceptors.go.golden | 8 ++-- ...ing-payload_interceptor_wrappers.go.golden | 24 +++++----- ...ing-payload_service_interceptors.go.golden | 19 +++++--- ...ead-payload_interceptor_wrappers.go.golden | 8 ++-- ...ead-payload_service_interceptors.go.golden | 10 ++-- ...read-result_interceptor_wrappers.go.golden | 8 ++-- ...read-result_service_interceptors.go.golden | 10 ++-- ...ming-result_interceptor_wrappers.go.golden | 8 ++-- ...ming-result_service_interceptors.go.golden | 19 +++++--- ...nterceptors_interceptor_wrappers.go.golden | 16 +++---- ...nterceptors_service_interceptors.go.golden | 28 +++++++---- 37 files changed, 286 insertions(+), 230 deletions(-) diff --git a/codegen/service/templates/client_interceptor_wrappers.go.tpl b/codegen/service/templates/client_interceptor_wrappers.go.tpl index 51a0802e93..3a6bd794c7 100644 --- a/codegen/service/templates/client_interceptor_wrappers.go.tpl +++ b/codegen/service/templates/client_interceptor_wrappers.go.tpl @@ -11,7 +11,7 @@ func wrapClient{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Interceptor service: "{{ $.Service }}", method: "{{ .MethodName }}", callType: goa.InterceptorUnary, - payload: req, + rawPayload: req, } res, ctx, err := i.{{ $interceptor.Name }}(ctx, info, endpoint) {{- else }} @@ -29,7 +29,7 @@ func wrapClient{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Interceptor service: "{{ $.Service }}", method: "{{ .MethodName }}", callType: goa.InterceptorStreamingSend, - payload: req, + rawPayload: req, } _, ctx, err := i.{{ $interceptor.Name }}(ctx, info, func(ctx context.Context, req any) (any, context.Context, error) { castReq, _ := req.({{ .ClientStream.SendTypeRef }}) @@ -60,7 +60,7 @@ func wrapClient{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Interceptor service: "{{ $.Service }}", method: "{{ .MethodName }}", callType: goa.InterceptorUnary, - payload: req, + rawPayload: req, } return i.{{ $interceptor.Name }}(ctx, info, endpoint) {{- end }} diff --git a/codegen/service/templates/interceptors.go.tpl b/codegen/service/templates/interceptors.go.tpl index e11b49bc9f..43f17a32dc 100644 --- a/codegen/service/templates/interceptors.go.tpl +++ b/codegen/service/templates/interceptors.go.tpl @@ -19,7 +19,7 @@ func (info *{{ .Name }}Info) CallType() goa.InterceptorCallType { // RawPayload returns the raw payload of the request. func (info *{{ .Name }}Info) RawPayload() any { - return info.payload + return info.rawPayload } {{- if .HasPayloadAccess }} @@ -59,8 +59,8 @@ func (info *{{ .Name }}Info) Result(res any) {{ .Name }}Result { {{- end }} {{- if .HasStreamingPayloadAccess }} -// StreamingPayload returns a type-safe accessor for the method streaming payload. -func (info *{{ .Name }}Info) StreamingPayload() {{ .Name }}StreamingPayload { +// ClientStreamingPayload returns a type-safe accessor for the method streaming payload for a client-side interceptor. +func (info *{{ .Name }}Info) ClientStreamingPayload() {{ .Name }}StreamingPayload { {{- if gt (len .Methods) 1 }} switch info.Method() { {{- range .Methods }} @@ -77,8 +77,8 @@ func (info *{{ .Name }}Info) StreamingPayload() {{ .Name }}StreamingPayload { {{- end }} {{- if .HasStreamingResultAccess }} -// StreamingResult returns a type-safe accessor for the method streaming result. -func (info *{{ .Name }}Info) StreamingResult(res any) {{ .Name }}StreamingResult { +// ClientStreamingResult returns a type-safe accessor for the method streaming result for a client-side interceptor. +func (info *{{ .Name }}Info) ClientStreamingResult(res any) {{ .Name }}StreamingResult { {{- if gt (len .Methods) 1 }} switch info.Method() { {{- range .Methods }} @@ -91,6 +91,42 @@ func (info *{{ .Name }}Info) StreamingResult(res any) {{ .Name }}StreamingResult {{- else }} return &{{ (index .Methods 0).StreamingResultAccess }}{result: res.({{ (index .Methods 0).StreamingResultRef }})} {{- end }} +} + {{- end }} + + {{- if .HasStreamingPayloadAccess }} +// ServerStreamingPayload returns a type-safe accessor for the method streaming payload for a server-side interceptor. +func (info *{{ .Name }}Info) ServerStreamingPayload(pay any) {{ .Name }}StreamingPayload { + {{- if gt (len .Methods) 1 }} + switch info.Method() { + {{- range .Methods }} + case "{{ .MethodName }}": + return &{{ .StreamingPayloadAccess }}{payload: pay.({{ .StreamingPayloadRef }})} + {{- end }} + default: + return nil + } + {{- else }} + return &{{ (index .Methods 0).StreamingPayloadAccess }}{payload: pay.({{ (index .Methods 0).StreamingPayloadRef }})} + {{- end }} +} + {{- end }} + + {{- if .HasStreamingResultAccess }} +// ServerStreamingResult returns a type-safe accessor for the method streaming result for a server-side interceptor. +func (info *{{ .Name }}Info) ServerStreamingResult() {{ .Name }}StreamingResult { + {{- if gt (len .Methods) 1 }} + switch info.Method() { + {{- range .Methods }} + case "{{ .MethodName }}": + return &{{ .StreamingResultAccess }}{result: info.RawPayload().({{ .StreamingResultRef }})} + {{- end }} + default: + return nil + } + {{- else }} + return &{{ (index .Methods 0).StreamingResultAccess }}{result: info.RawPayload().({{ (index .Methods 0).StreamingResultRef }})} + {{- end }} } {{- end }} {{- end }} diff --git a/codegen/service/templates/interceptors_types.go.tpl b/codegen/service/templates/interceptors_types.go.tpl index 2bc7deed92..10b890f470 100644 --- a/codegen/service/templates/interceptors_types.go.tpl +++ b/codegen/service/templates/interceptors_types.go.tpl @@ -5,10 +5,10 @@ type ( // {{ .Name }}Info provides metadata about the current interception. // It includes service name, method name, and access to the endpoint. {{ .Name }}Info struct { - service string - method string - callType goa.InterceptorCallType - payload any + service string + method string + callType goa.InterceptorCallType + rawPayload any } {{- if .HasPayloadAccess }} diff --git a/codegen/service/templates/server_interceptor_wrappers.go.tpl b/codegen/service/templates/server_interceptor_wrappers.go.tpl index 744da4bb9c..30b6fccbed 100644 --- a/codegen/service/templates/server_interceptor_wrappers.go.tpl +++ b/codegen/service/templates/server_interceptor_wrappers.go.tpl @@ -11,7 +11,7 @@ func wrap{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.InterceptorEndpoi service: "{{ $.Service }}", method: "{{ .MethodName }}", callType: goa.InterceptorUnary, - payload: req, + rawPayload: req, } res, ctx, err := i.{{ $interceptor.Name }}(ctx, info, endpoint) {{- else }} @@ -29,7 +29,7 @@ func wrap{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.InterceptorEndpoi service: "{{ $.Service }}", method: "{{ .MethodName }}", callType: goa.InterceptorStreamingSend, - payload: req, + rawPayload: req, } _, ctx, err := i.{{ $interceptor.Name }}(ctx, info, func(ctx context.Context, req any) (any, context.Context, error) { castReq, _ := req.({{ .ServerStream.SendTypeRef }}) @@ -60,7 +60,7 @@ func wrap{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.InterceptorEndpoi service: "{{ $.Service }}", method: "{{ .MethodName }}", callType: goa.InterceptorUnary, - payload: req, + rawPayload: req, } return i.{{ $interceptor.Name }}(ctx, info, endpoint) {{- end }} diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-payload_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-payload_interceptor_wrappers.go.golden index d897206376..d958a06c98 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-payload_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-payload_interceptor_wrappers.go.golden @@ -4,10 +4,10 @@ func wrapMethodValidation(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &ValidationInfo{ - service: "InterceptorWithReadPayload", - method: "Method", - callType: goa.InterceptorUnary, - payload: req, + service: "InterceptorWithReadPayload", + method: "Method", + callType: goa.InterceptorUnary, + rawPayload: req, } return i.Validation(ctx, info, endpoint) } @@ -18,10 +18,10 @@ func wrapMethodValidation(endpoint goa.InterceptorEndpoint, i ServerInterceptors func wrapClientMethodValidation(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &ValidationInfo{ - service: "InterceptorWithReadPayload", - method: "Method", - callType: goa.InterceptorUnary, - payload: req, + service: "InterceptorWithReadPayload", + method: "Method", + callType: goa.InterceptorUnary, + rawPayload: req, } return i.Validation(ctx, info, endpoint) } diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-payload_service_interceptors.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-payload_service_interceptors.go.golden index 45748140a1..003429e587 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-payload_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-payload_service_interceptors.go.golden @@ -11,10 +11,10 @@ type ( // ValidationInfo provides metadata about the current interception. // It includes service name, method name, and access to the endpoint. ValidationInfo struct { - service string - method string - callType goa.InterceptorCallType - payload any + service string + method string + callType goa.InterceptorCallType + rawPayload any } // ValidationPayload provides type-safe access to the method payload. @@ -65,7 +65,7 @@ func (info *ValidationInfo) CallType() goa.InterceptorCallType { // RawPayload returns the raw payload of the request. func (info *ValidationInfo) RawPayload() any { - return info.payload + return info.rawPayload } // Payload returns a type-safe accessor for the method payload. diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-result_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-result_interceptor_wrappers.go.golden index 109f07d9cc..d09f9368ce 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-result_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-result_interceptor_wrappers.go.golden @@ -4,10 +4,10 @@ func wrapMethodCaching(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &CachingInfo{ - service: "InterceptorWithReadResult", - method: "Method", - callType: goa.InterceptorUnary, - payload: req, + service: "InterceptorWithReadResult", + method: "Method", + callType: goa.InterceptorUnary, + rawPayload: req, } return i.Caching(ctx, info, endpoint) } @@ -17,10 +17,10 @@ func wrapMethodCaching(endpoint goa.InterceptorEndpoint, i ServerInterceptors) g func wrapClientMethodCaching(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &CachingInfo{ - service: "InterceptorWithReadResult", - method: "Method", - callType: goa.InterceptorUnary, - payload: req, + service: "InterceptorWithReadResult", + method: "Method", + callType: goa.InterceptorUnary, + rawPayload: req, } return i.Caching(ctx, info, endpoint) } diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-result_service_interceptors.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-result_service_interceptors.go.golden index a2ef88307d..d920902b55 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-result_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-result_service_interceptors.go.golden @@ -11,10 +11,10 @@ type ( // CachingInfo provides metadata about the current interception. // It includes service name, method name, and access to the endpoint. CachingInfo struct { - service string - method string - callType goa.InterceptorCallType - payload any + service string + method string + callType goa.InterceptorCallType + rawPayload any } // CachingResult provides type-safe access to the method result. @@ -65,7 +65,7 @@ func (info *CachingInfo) CallType() goa.InterceptorCallType { // RawPayload returns the raw payload of the request. func (info *CachingInfo) RawPayload() any { - return info.payload + return info.rawPayload } // Result returns a type-safe accessor for the method result. diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_interceptor_wrappers.go.golden index ed5d9bd672..18a9d5f81b 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_interceptor_wrappers.go.golden @@ -4,10 +4,10 @@ func wrapMethodValidation(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &ValidationInfo{ - service: "InterceptorWithReadWritePayload", - method: "Method", - callType: goa.InterceptorUnary, - payload: req, + service: "InterceptorWithReadWritePayload", + method: "Method", + callType: goa.InterceptorUnary, + rawPayload: req, } return i.Validation(ctx, info, endpoint) } @@ -18,10 +18,10 @@ func wrapMethodValidation(endpoint goa.InterceptorEndpoint, i ServerInterceptors func wrapClientMethodValidation(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &ValidationInfo{ - service: "InterceptorWithReadWritePayload", - method: "Method", - callType: goa.InterceptorUnary, - payload: req, + service: "InterceptorWithReadWritePayload", + method: "Method", + callType: goa.InterceptorUnary, + rawPayload: req, } return i.Validation(ctx, info, endpoint) } diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_service_interceptors.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_service_interceptors.go.golden index 05890a8824..f16a0e3826 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_service_interceptors.go.golden @@ -11,10 +11,10 @@ type ( // ValidationInfo provides metadata about the current interception. // It includes service name, method name, and access to the endpoint. ValidationInfo struct { - service string - method string - callType goa.InterceptorCallType - payload any + service string + method string + callType goa.InterceptorCallType + rawPayload any } // ValidationPayload provides type-safe access to the method payload. @@ -66,7 +66,7 @@ func (info *ValidationInfo) CallType() goa.InterceptorCallType { // RawPayload returns the raw payload of the request. func (info *ValidationInfo) RawPayload() any { - return info.payload + return info.rawPayload } // Payload returns a type-safe accessor for the method payload. diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-write-result_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-write-result_interceptor_wrappers.go.golden index af5078707b..5118a98823 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-write-result_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-write-result_interceptor_wrappers.go.golden @@ -4,10 +4,10 @@ func wrapMethodCaching(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &CachingInfo{ - service: "InterceptorWithReadWriteResult", - method: "Method", - callType: goa.InterceptorUnary, - payload: req, + service: "InterceptorWithReadWriteResult", + method: "Method", + callType: goa.InterceptorUnary, + rawPayload: req, } return i.Caching(ctx, info, endpoint) } @@ -17,10 +17,10 @@ func wrapMethodCaching(endpoint goa.InterceptorEndpoint, i ServerInterceptors) g func wrapClientMethodCaching(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &CachingInfo{ - service: "InterceptorWithReadWriteResult", - method: "Method", - callType: goa.InterceptorUnary, - payload: req, + service: "InterceptorWithReadWriteResult", + method: "Method", + callType: goa.InterceptorUnary, + rawPayload: req, } return i.Caching(ctx, info, endpoint) } diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-write-result_service_interceptors.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-write-result_service_interceptors.go.golden index 48ac781c30..12c83763be 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-write-result_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-write-result_service_interceptors.go.golden @@ -11,10 +11,10 @@ type ( // CachingInfo provides metadata about the current interception. // It includes service name, method name, and access to the endpoint. CachingInfo struct { - service string - method string - callType goa.InterceptorCallType - payload any + service string + method string + callType goa.InterceptorCallType + rawPayload any } // CachingResult provides type-safe access to the method result. @@ -66,7 +66,7 @@ func (info *CachingInfo) CallType() goa.InterceptorCallType { // RawPayload returns the raw payload of the request. func (info *CachingInfo) RawPayload() any { - return info.payload + return info.rawPayload } // Result returns a type-safe accessor for the method result. diff --git a/codegen/service/testdata/interceptors/interceptor-with-write-payload_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/interceptor-with-write-payload_interceptor_wrappers.go.golden index 04b7626d29..9f791496e8 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-write-payload_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-write-payload_interceptor_wrappers.go.golden @@ -4,10 +4,10 @@ func wrapMethodValidation(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &ValidationInfo{ - service: "InterceptorWithWritePayload", - method: "Method", - callType: goa.InterceptorUnary, - payload: req, + service: "InterceptorWithWritePayload", + method: "Method", + callType: goa.InterceptorUnary, + rawPayload: req, } return i.Validation(ctx, info, endpoint) } @@ -18,10 +18,10 @@ func wrapMethodValidation(endpoint goa.InterceptorEndpoint, i ServerInterceptors func wrapClientMethodValidation(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &ValidationInfo{ - service: "InterceptorWithWritePayload", - method: "Method", - callType: goa.InterceptorUnary, - payload: req, + service: "InterceptorWithWritePayload", + method: "Method", + callType: goa.InterceptorUnary, + rawPayload: req, } return i.Validation(ctx, info, endpoint) } diff --git a/codegen/service/testdata/interceptors/interceptor-with-write-payload_service_interceptors.go.golden b/codegen/service/testdata/interceptors/interceptor-with-write-payload_service_interceptors.go.golden index eaee77f00b..2294aa12db 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-write-payload_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-write-payload_service_interceptors.go.golden @@ -11,10 +11,10 @@ type ( // ValidationInfo provides metadata about the current interception. // It includes service name, method name, and access to the endpoint. ValidationInfo struct { - service string - method string - callType goa.InterceptorCallType - payload any + service string + method string + callType goa.InterceptorCallType + rawPayload any } // ValidationPayload provides type-safe access to the method payload. @@ -65,7 +65,7 @@ func (info *ValidationInfo) CallType() goa.InterceptorCallType { // RawPayload returns the raw payload of the request. func (info *ValidationInfo) RawPayload() any { - return info.payload + return info.rawPayload } // Payload returns a type-safe accessor for the method payload. diff --git a/codegen/service/testdata/interceptors/interceptor-with-write-result_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/interceptor-with-write-result_interceptor_wrappers.go.golden index 0844de7780..d8812a3595 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-write-result_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-write-result_interceptor_wrappers.go.golden @@ -4,10 +4,10 @@ func wrapMethodCaching(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &CachingInfo{ - service: "InterceptorWithWriteResult", - method: "Method", - callType: goa.InterceptorUnary, - payload: req, + service: "InterceptorWithWriteResult", + method: "Method", + callType: goa.InterceptorUnary, + rawPayload: req, } return i.Caching(ctx, info, endpoint) } @@ -17,10 +17,10 @@ func wrapMethodCaching(endpoint goa.InterceptorEndpoint, i ServerInterceptors) g func wrapClientMethodCaching(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &CachingInfo{ - service: "InterceptorWithWriteResult", - method: "Method", - callType: goa.InterceptorUnary, - payload: req, + service: "InterceptorWithWriteResult", + method: "Method", + callType: goa.InterceptorUnary, + rawPayload: req, } return i.Caching(ctx, info, endpoint) } diff --git a/codegen/service/testdata/interceptors/interceptor-with-write-result_service_interceptors.go.golden b/codegen/service/testdata/interceptors/interceptor-with-write-result_service_interceptors.go.golden index 11cb55d4e9..3e9976658c 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-write-result_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-write-result_service_interceptors.go.golden @@ -11,10 +11,10 @@ type ( // CachingInfo provides metadata about the current interception. // It includes service name, method name, and access to the endpoint. CachingInfo struct { - service string - method string - callType goa.InterceptorCallType - payload any + service string + method string + callType goa.InterceptorCallType + rawPayload any } // CachingResult provides type-safe access to the method result. @@ -65,7 +65,7 @@ func (info *CachingInfo) CallType() goa.InterceptorCallType { // RawPayload returns the raw payload of the request. func (info *CachingInfo) RawPayload() any { - return info.payload + return info.rawPayload } // Result returns a type-safe accessor for the method result. diff --git a/codegen/service/testdata/interceptors/multiple-interceptors_client_interceptors.go.golden b/codegen/service/testdata/interceptors/multiple-interceptors_client_interceptors.go.golden index 273d4023f3..2afd7972da 100644 --- a/codegen/service/testdata/interceptors/multiple-interceptors_client_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/multiple-interceptors_client_interceptors.go.golden @@ -12,18 +12,18 @@ type ( // Test2Info provides metadata about the current interception. // It includes service name, method name, and access to the endpoint. Test2Info struct { - service string - method string - callType goa.InterceptorCallType - payload any + service string + method string + callType goa.InterceptorCallType + rawPayload any } // Test4Info provides metadata about the current interception. // It includes service name, method name, and access to the endpoint. Test4Info struct { - service string - method string - callType goa.InterceptorCallType - payload any + service string + method string + callType goa.InterceptorCallType + rawPayload any } ) diff --git a/codegen/service/testdata/interceptors/multiple-interceptors_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/multiple-interceptors_interceptor_wrappers.go.golden index e9a124ba23..49c72914e3 100644 --- a/codegen/service/testdata/interceptors/multiple-interceptors_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/multiple-interceptors_interceptor_wrappers.go.golden @@ -4,10 +4,10 @@ func wrapMethodTest(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &TestInfo{ - service: "MultipleInterceptorsService", - method: "Method", - callType: goa.InterceptorUnary, - payload: req, + service: "MultipleInterceptorsService", + method: "Method", + callType: goa.InterceptorUnary, + rawPayload: req, } return i.Test(ctx, info, endpoint) } @@ -17,10 +17,10 @@ func wrapMethodTest(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa. func wrapMethodTest3(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &Test3Info{ - service: "MultipleInterceptorsService", - method: "Method", - callType: goa.InterceptorUnary, - payload: req, + service: "MultipleInterceptorsService", + method: "Method", + callType: goa.InterceptorUnary, + rawPayload: req, } return i.Test3(ctx, info, endpoint) } @@ -30,10 +30,10 @@ func wrapMethodTest3(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa func wrapClientMethodTest2(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &Test2Info{ - service: "MultipleInterceptorsService", - method: "Method", - callType: goa.InterceptorUnary, - payload: req, + service: "MultipleInterceptorsService", + method: "Method", + callType: goa.InterceptorUnary, + rawPayload: req, } return i.Test2(ctx, info, endpoint) } @@ -43,10 +43,10 @@ func wrapClientMethodTest2(endpoint goa.InterceptorEndpoint, i ClientInterceptor func wrapClientMethodTest4(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &Test4Info{ - service: "MultipleInterceptorsService", - method: "Method", - callType: goa.InterceptorUnary, - payload: req, + service: "MultipleInterceptorsService", + method: "Method", + callType: goa.InterceptorUnary, + rawPayload: req, } return i.Test4(ctx, info, endpoint) } diff --git a/codegen/service/testdata/interceptors/multiple-interceptors_service_interceptors.go.golden b/codegen/service/testdata/interceptors/multiple-interceptors_service_interceptors.go.golden index 744bd9c60f..5107c1d032 100644 --- a/codegen/service/testdata/interceptors/multiple-interceptors_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/multiple-interceptors_service_interceptors.go.golden @@ -12,18 +12,18 @@ type ( // TestInfo provides metadata about the current interception. // It includes service name, method name, and access to the endpoint. TestInfo struct { - service string - method string - callType goa.InterceptorCallType - payload any + service string + method string + callType goa.InterceptorCallType + rawPayload any } // Test3Info provides metadata about the current interception. // It includes service name, method name, and access to the endpoint. Test3Info struct { - service string - method string - callType goa.InterceptorCallType - payload any + service string + method string + callType goa.InterceptorCallType + rawPayload any } ) diff --git a/codegen/service/testdata/interceptors/single-api-server-interceptor_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/single-api-server-interceptor_interceptor_wrappers.go.golden index bd3a9c06fd..e9669889bd 100644 --- a/codegen/service/testdata/interceptors/single-api-server-interceptor_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/single-api-server-interceptor_interceptor_wrappers.go.golden @@ -4,10 +4,10 @@ func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &LoggingInfo{ - service: "SingleAPIServerInterceptor", - method: "Method", - callType: goa.InterceptorUnary, - payload: req, + service: "SingleAPIServerInterceptor", + method: "Method", + callType: goa.InterceptorUnary, + rawPayload: req, } return i.Logging(ctx, info, endpoint) } @@ -17,10 +17,10 @@ func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) g func wrapMethod2Logging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &LoggingInfo{ - service: "SingleAPIServerInterceptor", - method: "Method2", - callType: goa.InterceptorUnary, - payload: req, + service: "SingleAPIServerInterceptor", + method: "Method2", + callType: goa.InterceptorUnary, + rawPayload: req, } return i.Logging(ctx, info, endpoint) } diff --git a/codegen/service/testdata/interceptors/single-api-server-interceptor_service_interceptors.go.golden b/codegen/service/testdata/interceptors/single-api-server-interceptor_service_interceptors.go.golden index 4e8f5ea6b4..8c12e6c5b6 100644 --- a/codegen/service/testdata/interceptors/single-api-server-interceptor_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/single-api-server-interceptor_service_interceptors.go.golden @@ -11,10 +11,10 @@ type ( // LoggingInfo provides metadata about the current interception. // It includes service name, method name, and access to the endpoint. LoggingInfo struct { - service string - method string - callType goa.InterceptorCallType - payload any + service string + method string + callType goa.InterceptorCallType + rawPayload any } ) diff --git a/codegen/service/testdata/interceptors/single-client-interceptor_client_interceptors.go.golden b/codegen/service/testdata/interceptors/single-client-interceptor_client_interceptors.go.golden index 4d1d3d6438..8dc8774a8e 100644 --- a/codegen/service/testdata/interceptors/single-client-interceptor_client_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/single-client-interceptor_client_interceptors.go.golden @@ -11,10 +11,10 @@ type ( // TracingInfo provides metadata about the current interception. // It includes service name, method name, and access to the endpoint. TracingInfo struct { - service string - method string - callType goa.InterceptorCallType - payload any + service string + method string + callType goa.InterceptorCallType + rawPayload any } ) diff --git a/codegen/service/testdata/interceptors/single-client-interceptor_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/single-client-interceptor_interceptor_wrappers.go.golden index 60b26a481d..d4d82c0f89 100644 --- a/codegen/service/testdata/interceptors/single-client-interceptor_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/single-client-interceptor_interceptor_wrappers.go.golden @@ -4,10 +4,10 @@ func wrapClientMethodTracing(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &TracingInfo{ - service: "SingleClientInterceptor", - method: "Method", - callType: goa.InterceptorUnary, - payload: req, + service: "SingleClientInterceptor", + method: "Method", + callType: goa.InterceptorUnary, + rawPayload: req, } return i.Tracing(ctx, info, endpoint) } diff --git a/codegen/service/testdata/interceptors/single-method-server-interceptor_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/single-method-server-interceptor_interceptor_wrappers.go.golden index 146e75002d..0188370abf 100644 --- a/codegen/service/testdata/interceptors/single-method-server-interceptor_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/single-method-server-interceptor_interceptor_wrappers.go.golden @@ -4,10 +4,10 @@ func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &LoggingInfo{ - service: "SingleMethodServerInterceptor", - method: "Method", - callType: goa.InterceptorUnary, - payload: req, + service: "SingleMethodServerInterceptor", + method: "Method", + callType: goa.InterceptorUnary, + rawPayload: req, } return i.Logging(ctx, info, endpoint) } diff --git a/codegen/service/testdata/interceptors/single-method-server-interceptor_service_interceptors.go.golden b/codegen/service/testdata/interceptors/single-method-server-interceptor_service_interceptors.go.golden index 82065f7595..232b876dc8 100644 --- a/codegen/service/testdata/interceptors/single-method-server-interceptor_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/single-method-server-interceptor_service_interceptors.go.golden @@ -11,10 +11,10 @@ type ( // LoggingInfo provides metadata about the current interception. // It includes service name, method name, and access to the endpoint. LoggingInfo struct { - service string - method string - callType goa.InterceptorCallType - payload any + service string + method string + callType goa.InterceptorCallType + rawPayload any } ) diff --git a/codegen/service/testdata/interceptors/single-service-server-interceptor_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/single-service-server-interceptor_interceptor_wrappers.go.golden index 9df1a34dff..d662ee70ef 100644 --- a/codegen/service/testdata/interceptors/single-service-server-interceptor_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/single-service-server-interceptor_interceptor_wrappers.go.golden @@ -4,10 +4,10 @@ func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &LoggingInfo{ - service: "SingleServerInterceptor", - method: "Method", - callType: goa.InterceptorUnary, - payload: req, + service: "SingleServerInterceptor", + method: "Method", + callType: goa.InterceptorUnary, + rawPayload: req, } return i.Logging(ctx, info, endpoint) } @@ -17,10 +17,10 @@ func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) g func wrapMethod2Logging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &LoggingInfo{ - service: "SingleServerInterceptor", - method: "Method2", - callType: goa.InterceptorUnary, - payload: req, + service: "SingleServerInterceptor", + method: "Method2", + callType: goa.InterceptorUnary, + rawPayload: req, } return i.Logging(ctx, info, endpoint) } diff --git a/codegen/service/testdata/interceptors/single-service-server-interceptor_service_interceptors.go.golden b/codegen/service/testdata/interceptors/single-service-server-interceptor_service_interceptors.go.golden index 4e8f5ea6b4..8c12e6c5b6 100644 --- a/codegen/service/testdata/interceptors/single-service-server-interceptor_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/single-service-server-interceptor_service_interceptors.go.golden @@ -11,10 +11,10 @@ type ( // LoggingInfo provides metadata about the current interception. // It includes service name, method name, and access to the endpoint. LoggingInfo struct { - service string - method string - callType goa.InterceptorCallType - payload any + service string + method string + callType goa.InterceptorCallType + rawPayload any } ) diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_interceptor_wrappers.go.golden index 08f9bd55b0..2e24294df8 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_interceptor_wrappers.go.golden @@ -20,10 +20,10 @@ type wrappedMethodClientStream struct { func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &LoggingInfo{ - service: "StreamingInterceptorsWithReadPayloadAndReadStreamingPayload", - method: "Method", - callType: goa.InterceptorUnary, - payload: req, + service: "StreamingInterceptorsWithReadPayloadAndReadStreamingPayload", + method: "Method", + callType: goa.InterceptorUnary, + rawPayload: req, } res, ctx, err := i.Logging(ctx, info, endpoint) if err != nil { @@ -53,10 +53,10 @@ func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) g func wrapClientMethodLogging(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &LoggingInfo{ - service: "StreamingInterceptorsWithReadPayloadAndReadStreamingPayload", - method: "Method", - callType: goa.InterceptorUnary, - payload: req, + service: "StreamingInterceptorsWithReadPayloadAndReadStreamingPayload", + method: "Method", + callType: goa.InterceptorUnary, + rawPayload: req, } res, ctx, err := i.Logging(ctx, info, endpoint) if err != nil { @@ -67,10 +67,10 @@ func wrapClientMethodLogging(endpoint goa.InterceptorEndpoint, i ClientIntercept ctx: ctx, sendWithContext: func(ctx context.Context, req *MethodStreamingPayload) (context.Context, error) { info := &LoggingInfo{ - service: "StreamingInterceptorsWithReadPayloadAndReadStreamingPayload", - method: "Method", - callType: goa.InterceptorStreamingSend, - payload: req, + service: "StreamingInterceptorsWithReadPayloadAndReadStreamingPayload", + method: "Method", + callType: goa.InterceptorStreamingSend, + rawPayload: req, } _, ctx, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, context.Context, error) { castReq, _ := req.(*MethodStreamingPayload) diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_service_interceptors.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_service_interceptors.go.golden index 31ac7968e2..10fba38801 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_service_interceptors.go.golden @@ -11,10 +11,10 @@ type ( // LoggingInfo provides metadata about the current interception. // It includes service name, method name, and access to the endpoint. LoggingInfo struct { - service string - method string - callType goa.InterceptorCallType - payload any + service string + method string + callType goa.InterceptorCallType + rawPayload any } // LoggingPayload provides type-safe access to the method payload. @@ -75,7 +75,7 @@ func (info *LoggingInfo) CallType() goa.InterceptorCallType { // RawPayload returns the raw payload of the request. func (info *LoggingInfo) RawPayload() any { - return info.payload + return info.rawPayload } // Payload returns a type-safe accessor for the method payload. @@ -83,11 +83,16 @@ func (info *LoggingInfo) Payload() LoggingPayload { return &loggingMethodPayload{payload: info.RawPayload().(*MethodPayload)} } -// StreamingPayload returns a type-safe accessor for the method streaming payload. -func (info *LoggingInfo) StreamingPayload() LoggingStreamingPayload { +// ClientStreamingPayload returns a type-safe accessor for the method streaming payload for a client-side interceptor. +func (info *LoggingInfo) ClientStreamingPayload() LoggingStreamingPayload { return &loggingMethodStreamingPayload{payload: info.RawPayload().(*MethodStreamingPayload)} } +// ServerStreamingPayload returns a type-safe accessor for the method streaming payload for a server-side interceptor. +func (info *LoggingInfo) ServerStreamingPayload(pay any) LoggingStreamingPayload { + return &loggingMethodStreamingPayload{payload: pay.(*MethodStreamingPayload)} +} + // Private implementation methods func (p *loggingMethodPayload) Chunk() string { diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_interceptor_wrappers.go.golden index 11d355d6a5..da06efe990 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_interceptor_wrappers.go.golden @@ -4,10 +4,10 @@ func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &LoggingInfo{ - service: "StreamingInterceptorsWithReadPayload", - method: "Method", - callType: goa.InterceptorUnary, - payload: req, + service: "StreamingInterceptorsWithReadPayload", + method: "Method", + callType: goa.InterceptorUnary, + rawPayload: req, } return i.Logging(ctx, info, endpoint) } diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_service_interceptors.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_service_interceptors.go.golden index dfb547386b..e4d3b67a31 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_service_interceptors.go.golden @@ -11,10 +11,10 @@ type ( // LoggingInfo provides metadata about the current interception. // It includes service name, method name, and access to the endpoint. LoggingInfo struct { - service string - method string - callType goa.InterceptorCallType - payload any + service string + method string + callType goa.InterceptorCallType + rawPayload any } // LoggingPayload provides type-safe access to the method payload. @@ -65,7 +65,7 @@ func (info *LoggingInfo) CallType() goa.InterceptorCallType { // RawPayload returns the raw payload of the request. func (info *LoggingInfo) RawPayload() any { - return info.payload + return info.rawPayload } // Payload returns a type-safe accessor for the method payload. diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_interceptor_wrappers.go.golden index add4914dbd..38fc94186c 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_interceptor_wrappers.go.golden @@ -4,10 +4,10 @@ func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { return func(ctx context.Context, req any) (any, context.Context, error) { info := &LoggingInfo{ - service: "StreamingInterceptorsWithReadResult", - method: "Method", - callType: goa.InterceptorUnary, - payload: req, + service: "StreamingInterceptorsWithReadResult", + method: "Method", + callType: goa.InterceptorUnary, + rawPayload: req, } return i.Logging(ctx, info, endpoint) } diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_service_interceptors.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_service_interceptors.go.golden index d76b8adbc3..fbc576bf69 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_service_interceptors.go.golden @@ -11,10 +11,10 @@ type ( // LoggingInfo provides metadata about the current interception. // It includes service name, method name, and access to the endpoint. LoggingInfo struct { - service string - method string - callType goa.InterceptorCallType - payload any + service string + method string + callType goa.InterceptorCallType + rawPayload any } // LoggingResult provides type-safe access to the method result. @@ -65,7 +65,7 @@ func (info *LoggingInfo) CallType() goa.InterceptorCallType { // RawPayload returns the raw payload of the request. func (info *LoggingInfo) RawPayload() any { - return info.payload + return info.rawPayload } // Result returns a type-safe accessor for the method result. diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_interceptor_wrappers.go.golden index edb650ddb6..d23e8d68d3 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_interceptor_wrappers.go.golden @@ -28,10 +28,10 @@ func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) g ctx: ctx, sendWithContext: func(ctx context.Context, req *MethodResult) (context.Context, error) { info := &LoggingInfo{ - service: "StreamingInterceptorsWithReadStreamingResult", - method: "Method", - callType: goa.InterceptorStreamingSend, - payload: req, + service: "StreamingInterceptorsWithReadStreamingResult", + method: "Method", + callType: goa.InterceptorStreamingSend, + rawPayload: req, } _, ctx, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, context.Context, error) { castReq, _ := req.(*MethodResult) diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_service_interceptors.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_service_interceptors.go.golden index bec998ff1c..f0eb9871d5 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_service_interceptors.go.golden @@ -11,10 +11,10 @@ type ( // LoggingInfo provides metadata about the current interception. // It includes service name, method name, and access to the endpoint. LoggingInfo struct { - service string - method string - callType goa.InterceptorCallType - payload any + service string + method string + callType goa.InterceptorCallType + rawPayload any } // LoggingStreamingResult provides type-safe access to the method streaming result. @@ -65,14 +65,19 @@ func (info *LoggingInfo) CallType() goa.InterceptorCallType { // RawPayload returns the raw payload of the request. func (info *LoggingInfo) RawPayload() any { - return info.payload + return info.rawPayload } -// StreamingResult returns a type-safe accessor for the method streaming result. -func (info *LoggingInfo) StreamingResult(res any) LoggingStreamingResult { +// ClientStreamingResult returns a type-safe accessor for the method streaming result for a client-side interceptor. +func (info *LoggingInfo) ClientStreamingResult(res any) LoggingStreamingResult { return &loggingMethodStreamingResult{result: res.(*MethodResult)} } +// ServerStreamingResult returns a type-safe accessor for the method streaming result for a server-side interceptor. +func (info *LoggingInfo) ServerStreamingResult() LoggingStreamingResult { + return &loggingMethodStreamingResult{result: info.RawPayload().(*MethodResult)} +} + // Private implementation methods func (r *loggingMethodStreamingResult) Data() string { diff --git a/codegen/service/testdata/interceptors/streaming-interceptors_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors_interceptor_wrappers.go.golden index b4fe7c4238..3c9626f829 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors_interceptor_wrappers.go.golden @@ -30,10 +30,10 @@ func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) g ctx: ctx, sendWithContext: func(ctx context.Context, req *MethodResult) (context.Context, error) { info := &LoggingInfo{ - service: "StreamingInterceptors", - method: "Method", - callType: goa.InterceptorStreamingSend, - payload: req, + service: "StreamingInterceptors", + method: "Method", + callType: goa.InterceptorStreamingSend, + rawPayload: req, } _, ctx, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, context.Context, error) { castReq, _ := req.(*MethodResult) @@ -71,10 +71,10 @@ func wrapClientMethodLogging(endpoint goa.InterceptorEndpoint, i ClientIntercept ctx: ctx, sendWithContext: func(ctx context.Context, req *MethodStreamingPayload) (context.Context, error) { info := &LoggingInfo{ - service: "StreamingInterceptors", - method: "Method", - callType: goa.InterceptorStreamingSend, - payload: req, + service: "StreamingInterceptors", + method: "Method", + callType: goa.InterceptorStreamingSend, + rawPayload: req, } _, ctx, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, context.Context, error) { castReq, _ := req.(*MethodStreamingPayload) diff --git a/codegen/service/testdata/interceptors/streaming-interceptors_service_interceptors.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors_service_interceptors.go.golden index de9b3ee6fc..8eae956f38 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors_service_interceptors.go.golden @@ -11,10 +11,10 @@ type ( // LoggingInfo provides metadata about the current interception. // It includes service name, method name, and access to the endpoint. LoggingInfo struct { - service string - method string - callType goa.InterceptorCallType - payload any + service string + method string + callType goa.InterceptorCallType + rawPayload any } // LoggingStreamingPayload provides type-safe access to the method streaming payload. @@ -77,19 +77,29 @@ func (info *LoggingInfo) CallType() goa.InterceptorCallType { // RawPayload returns the raw payload of the request. func (info *LoggingInfo) RawPayload() any { - return info.payload + return info.rawPayload } -// StreamingPayload returns a type-safe accessor for the method streaming payload. -func (info *LoggingInfo) StreamingPayload() LoggingStreamingPayload { +// ClientStreamingPayload returns a type-safe accessor for the method streaming payload for a client-side interceptor. +func (info *LoggingInfo) ClientStreamingPayload() LoggingStreamingPayload { return &loggingMethodStreamingPayload{payload: info.RawPayload().(*MethodStreamingPayload)} } -// StreamingResult returns a type-safe accessor for the method streaming result. -func (info *LoggingInfo) StreamingResult(res any) LoggingStreamingResult { +// ClientStreamingResult returns a type-safe accessor for the method streaming result for a client-side interceptor. +func (info *LoggingInfo) ClientStreamingResult(res any) LoggingStreamingResult { return &loggingMethodStreamingResult{result: res.(*MethodResult)} } +// ServerStreamingPayload returns a type-safe accessor for the method streaming payload for a server-side interceptor. +func (info *LoggingInfo) ServerStreamingPayload(pay any) LoggingStreamingPayload { + return &loggingMethodStreamingPayload{payload: pay.(*MethodStreamingPayload)} +} + +// ServerStreamingResult returns a type-safe accessor for the method streaming result for a server-side interceptor. +func (info *LoggingInfo) ServerStreamingResult() LoggingStreamingResult { + return &loggingMethodStreamingResult{result: info.RawPayload().(*MethodResult)} +} + // Private implementation methods func (p *loggingMethodStreamingPayload) Chunk() string { From 2ba73aeb612eb289cd8c6253917c832855bcdc12 Mon Sep 17 00:00:00 2001 From: Douglas Thrift Date: Thu, 6 Feb 2025 14:57:30 -0800 Subject: [PATCH 21/23] Use goa.Endpoint for next again and do not return contexts from SendWithContext/ReceiveWithContext --- ...nt_interceptor_stream_wrapper_types.go.tpl | 4 +- .../client_interceptor_stream_wrappers.go.tpl | 10 +- .../client_interceptor_wrappers.go.tpl | 27 +- .../templates/client_interceptors.go.tpl | 2 +- .../service/templates/client_wrappers.go.tpl | 15 +- .../templates/endpoint_wrappers.go.tpl | 11 +- .../example_client_interceptor.go.tpl | 8 +- .../example_server_interceptor.go.tpl | 8 +- ...er_interceptor_stream_wrapper_types.go.tpl | 4 +- .../server_interceptor_stream_wrappers.go.tpl | 10 +- .../server_interceptor_wrappers.go.tpl | 27 +- .../templates/server_interceptors.go.tpl | 2 +- codegen/service/templates/service.go.tpl | 4 +- .../api_interceptor_service_client.golden | 8 +- .../api_interceptor_service_server.golden | 8 +- .../chained_interceptor_service_client.golden | 24 +- .../chained_interceptor_service_server.golden | 24 +- .../client_interceptor_service_client.golden | 8 +- ...ultiple_interceptors_service_client.golden | 16 +- ...ultiple_interceptors_service_server.golden | 16 +- ...rvices_interceptors_service2_client.golden | 16 +- ...rvices_interceptors_service2_server.golden | 16 +- ...ervices_interceptors_service_client.golden | 16 +- ...ervices_interceptors_service_server.golden | 16 +- ..._interceptor_by_name_service_server.golden | 8 +- .../server_interceptor_service_server.golden | 8 +- ...read-payload_client_interceptors.go.golden | 13 +- ...ead-payload_interceptor_wrappers.go.golden | 8 +- ...ead-payload_service_interceptors.go.golden | 13 +- ...-read-result_client_interceptors.go.golden | 13 +- ...read-result_interceptor_wrappers.go.golden | 8 +- ...read-result_service_interceptors.go.golden | 13 +- ...rite-payload_client_interceptors.go.golden | 13 +- ...ite-payload_interceptor_wrappers.go.golden | 8 +- ...ite-payload_service_interceptors.go.golden | 13 +- ...write-result_client_interceptors.go.golden | 13 +- ...rite-result_interceptor_wrappers.go.golden | 8 +- ...rite-result_service_interceptors.go.golden | 13 +- ...rite-payload_client_interceptors.go.golden | 13 +- ...ite-payload_interceptor_wrappers.go.golden | 8 +- ...ite-payload_service_interceptors.go.golden | 13 +- ...write-result_client_interceptors.go.golden | 13 +- ...rite-result_interceptor_wrappers.go.golden | 8 +- ...rite-result_service_interceptors.go.golden | 13 +- ...interceptors_client_interceptors.go.golden | 17 +- ...nterceptors_interceptor_wrappers.go.golden | 16 +- ...nterceptors_service_interceptors.go.golden | 17 +- ...interceptor_interceptor_wrappers.go.golden | 8 +- ...interceptor_service_interceptors.go.golden | 24 +- ...-interceptor_client_interceptors.go.golden | 13 +- ...interceptor_interceptor_wrappers.go.golden | 4 +- ...interceptor_interceptor_wrappers.go.golden | 4 +- ...interceptor_service_interceptors.go.golden | 13 +- ...interceptor_interceptor_wrappers.go.golden | 8 +- ...interceptor_service_interceptors.go.golden | 24 +- ...ming-payload_client_interceptors.go.golden | 13 +- ...ing-payload_interceptor_wrappers.go.golden | 49 +- ...ing-payload_service_interceptors.go.golden | 13 +- ...ead-payload_interceptor_wrappers.go.golden | 4 +- ...ead-payload_service_interceptors.go.golden | 13 +- ...read-result_interceptor_wrappers.go.golden | 4 +- ...read-result_service_interceptors.go.golden | 13 +- ...aming-result_client_interceptors.go.golden | 13 +- ...ming-result_interceptor_wrappers.go.golden | 49 +- ...ming-result_service_interceptors.go.golden | 13 +- ...interceptors_client_interceptors.go.golden | 13 +- ...nterceptors_interceptor_wrappers.go.golden | 78 ++- ...nterceptors_service_interceptors.go.golden | 13 +- codegen/service/testdata/service_code.go | 84 +-- grpc/codegen/templates/stream_recv.go.tpl | 5 +- grpc/codegen/templates/stream_send.go.tpl | 4 +- grpc/codegen/testdata/streaming_code.go | 100 ++-- http/codegen/templates/websocket_recv.go.tpl | 5 +- http/codegen/templates/websocket_send.go.tpl | 4 +- http/codegen/testdata/streaming_code.go | 477 ++++++++---------- pkg/interceptor.go | 9 +- 76 files changed, 671 insertions(+), 973 deletions(-) diff --git a/codegen/service/templates/client_interceptor_stream_wrapper_types.go.tpl b/codegen/service/templates/client_interceptor_stream_wrapper_types.go.tpl index 7c4f444fa1..9a250d08f6 100644 --- a/codegen/service/templates/client_interceptor_stream_wrapper_types.go.tpl +++ b/codegen/service/templates/client_interceptor_stream_wrapper_types.go.tpl @@ -4,10 +4,10 @@ type wrapped{{ .Interface }} struct { ctx context.Context {{- if ne .SendTypeRef "" }} - sendWithContext func(context.Context, {{ .SendTypeRef }}) (context.Context, error) + sendWithContext func(context.Context, {{ .SendTypeRef }}) error {{- end }} {{- if ne .RecvTypeRef "" }} - recvWithContext func(context.Context) ({{ .RecvTypeRef }}, context.Context, error) + recvWithContext func(context.Context) ({{ .RecvTypeRef }}, error) {{- end }} stream {{ .Interface }} } diff --git a/codegen/service/templates/client_interceptor_stream_wrappers.go.tpl b/codegen/service/templates/client_interceptor_stream_wrappers.go.tpl index 1a0c0b7e22..e1f3e2c5a2 100644 --- a/codegen/service/templates/client_interceptor_stream_wrappers.go.tpl +++ b/codegen/service/templates/client_interceptor_stream_wrappers.go.tpl @@ -4,12 +4,11 @@ {{ comment (printf "%s streams instances of \"%s\" after executing the applied interceptor." .SendName .Interface) }} func (w *wrapped{{ .Interface }}) {{ .SendName }}(v {{ .SendTypeRef }}) error { - _, err := w.SendWithContext(w.ctx, v) - return err + return w.SendWithContext(w.ctx, v) } {{ comment (printf "%s streams instances of \"%s\" after executing the applied interceptor with context." .SendWithContextName .Interface) }} -func (w *wrapped{{ .Interface }}) {{ .SendWithContextName }}(ctx context.Context, v {{ .SendTypeRef }}) (context.Context, error) { +func (w *wrapped{{ .Interface }}) {{ .SendWithContextName }}(ctx context.Context, v {{ .SendTypeRef }}) error { if w.sendWithContext == nil { return w.stream.{{ .SendWithContextName }}(ctx, v) } @@ -20,12 +19,11 @@ func (w *wrapped{{ .Interface }}) {{ .SendWithContextName }}(ctx context.Context {{ comment (printf "%s reads instances of \"%s\" from the stream after executing the applied interceptor." .RecvName .Interface) }} func (w *wrapped{{ .Interface }}) {{ .RecvName }}() ({{ .RecvTypeRef }}, error) { - res, _, err := w.RecvWithContext(w.ctx) - return res, err + return w.RecvWithContext(w.ctx) } {{ comment (printf "%s reads instances of \"%s\" from the stream after executing the applied interceptor with context." .RecvWithContextName .Interface) }} -func (w *wrapped{{ .Interface }}) {{ .RecvWithContextName }}(ctx context.Context) ({{ .RecvTypeRef }}, context.Context, error) { +func (w *wrapped{{ .Interface }}) {{ .RecvWithContextName }}(ctx context.Context) ({{ .RecvTypeRef }}, error) { if w.recvWithContext == nil { return w.stream.{{ .RecvWithContextName }}(ctx) } diff --git a/codegen/service/templates/client_interceptor_wrappers.go.tpl b/codegen/service/templates/client_interceptor_wrappers.go.tpl index 3a6bd794c7..c01590d59c 100644 --- a/codegen/service/templates/client_interceptor_wrappers.go.tpl +++ b/codegen/service/templates/client_interceptor_wrappers.go.tpl @@ -3,8 +3,8 @@ {{- range .Methods }} {{ comment (printf "wrapClient%s%s applies the %s client interceptor to endpoints." $interceptor.Name .MethodName $interceptor.DesignName) }} -func wrapClient{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { - return func(ctx context.Context, req any) (any, context.Context, error) { +func wrapClient{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { + return func(ctx context.Context, req any) (any, error) { {{- if or $interceptor.HasStreamingPayloadAccess $interceptor.HasStreamingResultAccess }} {{- if $interceptor.HasPayloadAccess }} info := &{{ $interceptor.Name }}Info{ @@ -13,48 +13,47 @@ func wrapClient{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Interceptor callType: goa.InterceptorUnary, rawPayload: req, } - res, ctx, err := i.{{ $interceptor.Name }}(ctx, info, endpoint) + res, err := i.{{ $interceptor.Name }}(ctx, info, endpoint) {{- else }} - res, ctx, err := endpoint(ctx, req) + res, err := endpoint(ctx, req) {{- end }} if err != nil { - return res, ctx, err + return res, err } stream := res.({{ .ClientStream.Interface }}) return &wrapped{{ .ClientStream.Interface }}{ ctx: ctx, {{- if $interceptor.HasStreamingPayloadAccess }} - sendWithContext: func(ctx context.Context, req {{ .ClientStream.SendTypeRef }}) (context.Context, error) { + sendWithContext: func(ctx context.Context, req {{ .ClientStream.SendTypeRef }}) error { info := &{{ $interceptor.Name }}Info{ service: "{{ $.Service }}", method: "{{ .MethodName }}", callType: goa.InterceptorStreamingSend, rawPayload: req, } - _, ctx, err := i.{{ $interceptor.Name }}(ctx, info, func(ctx context.Context, req any) (any, context.Context, error) { + _, err := i.{{ $interceptor.Name }}(ctx, info, func(ctx context.Context, req any) (any, error) { castReq, _ := req.({{ .ClientStream.SendTypeRef }}) - ctx, err = stream.{{ .ClientStream.SendWithContextName }}(ctx, castReq) - return nil, ctx, err + return nil, stream.{{ .ClientStream.SendWithContextName }}(ctx, castReq) }) - return ctx, err + return err }, {{- end }} {{- if $interceptor.HasStreamingResultAccess }} - recvWithContext: func(ctx context.Context) ({{ .ClientStream.RecvTypeRef }}, context.Context, error) { + recvWithContext: func(ctx context.Context) ({{ .ClientStream.RecvTypeRef }}, error) { info := &{{ $interceptor.Name }}Info{ service: "{{ $.Service }}", method: "{{ .MethodName }}", callType: goa.InterceptorStreamingRecv, } - res, ctx, err := i.{{ $interceptor.Name }}(ctx, info, func(ctx context.Context, _ any) (any, context.Context, error) { + res, err := i.{{ $interceptor.Name }}(ctx, info, func(ctx context.Context, _ any) (any, error) { return stream.{{ .ClientStream.RecvWithContextName }}(ctx) }) castRes, _ := res.({{ .ClientStream.RecvTypeRef }}) - return castRes, ctx, err + return castRes, err }, {{- end }} stream: stream, - }, ctx, nil + }, nil {{- else }} info := &{{ $interceptor.Name }}Info{ service: "{{ $.Service }}", diff --git a/codegen/service/templates/client_interceptors.go.tpl b/codegen/service/templates/client_interceptors.go.tpl index 8c4ea5432e..9528e3d123 100644 --- a/codegen/service/templates/client_interceptors.go.tpl +++ b/codegen/service/templates/client_interceptors.go.tpl @@ -7,6 +7,6 @@ type ClientInterceptors interface { {{- if .Description }} {{ comment .Description }} {{- end }} - {{ .Name }}(ctx context.Context, info *{{ .Name }}Info, next goa.InterceptorEndpoint) (any, context.Context, error) + {{ .Name }}(ctx context.Context, info *{{ .Name }}Info, next goa.Endpoint) (any, error) {{- end }} } diff --git a/codegen/service/templates/client_wrappers.go.tpl b/codegen/service/templates/client_wrappers.go.tpl index 683d1f3b49..711e632e72 100644 --- a/codegen/service/templates/client_wrappers.go.tpl +++ b/codegen/service/templates/client_wrappers.go.tpl @@ -1,15 +1,8 @@ {{ comment (printf "Wrap%sClientEndpoint wraps the %s endpoint with the client interceptors defined in the design." .MethodVarName .Method) }} func Wrap{{ .MethodVarName }}ClientEndpoint(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { - var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { - response, err := endpoint(ctx, request) - return response, ctx, err - } - {{- range .Interceptors }} - interceptorEndpoint = wrapClient{{ $.MethodVarName }}{{ . }}(interceptorEndpoint, i) - {{- end }} - return func(ctx context.Context, request any) (any, error) { - response, _, err := interceptorEndpoint(ctx, request) - return response, err - } + {{- range .Interceptors }} + endpoint = wrapClient{{ $.MethodVarName }}{{ . }}(endpoint, i) + {{- end }} + return endpoint } diff --git a/codegen/service/templates/endpoint_wrappers.go.tpl b/codegen/service/templates/endpoint_wrappers.go.tpl index 27c2e8264b..deffd14fc9 100644 --- a/codegen/service/templates/endpoint_wrappers.go.tpl +++ b/codegen/service/templates/endpoint_wrappers.go.tpl @@ -1,14 +1,7 @@ {{ comment (printf "Wrap%sEndpoint wraps the %s endpoint with the server-side interceptors defined in the design." .MethodVarName .Method) }} func Wrap{{ .MethodVarName }}Endpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { - response, err := endpoint(ctx, request) - return response, ctx, err - } {{- range .Interceptors }} - interceptorEndpoint = wrap{{ $.MethodVarName }}{{ . }}(interceptorEndpoint, i) + endpoint = wrap{{ $.MethodVarName }}{{ . }}(endpoint, i) {{- end }} - return func(ctx context.Context, request any) (any, error) { - response, _, err := interceptorEndpoint(ctx, request) - return response, err - } + return endpoint } diff --git a/codegen/service/templates/example_client_interceptor.go.tpl b/codegen/service/templates/example_client_interceptor.go.tpl index 1580286352..4dad48f184 100644 --- a/codegen/service/templates/example_client_interceptor.go.tpl +++ b/codegen/service/templates/example_client_interceptor.go.tpl @@ -11,14 +11,14 @@ func New{{ .StructName }}ClientInterceptors() *{{ .StructName }}ClientIntercepto {{- if .Description }} {{ comment .Description }} {{- end }} -func (i *{{ $.StructName }}ClientInterceptors) {{ .Name }}(ctx context.Context, info *{{ $.PkgName }}.{{ .Name }}Info, next goa.InterceptorEndpoint) (any, context.Context, error) { +func (i *{{ $.StructName }}ClientInterceptors) {{ .Name }}(ctx context.Context, info *{{ $.PkgName }}.{{ .Name }}Info, next goa.Endpoint) (any, error) { log.Printf(ctx, "[{{ .Name }}] Sending request: %v", info.RawPayload()) - resp, ctx, err := next(ctx, info.RawPayload()) + resp, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[{{ .Name }}] Error: %v", err) - return nil, ctx, err + return nil, err } log.Printf(ctx, "[{{ .Name }}] Received response: %v", resp) - return resp, ctx, nil + return resp, nil } {{- end }} diff --git a/codegen/service/templates/example_server_interceptor.go.tpl b/codegen/service/templates/example_server_interceptor.go.tpl index d2f0534219..9e1ed5086e 100644 --- a/codegen/service/templates/example_server_interceptor.go.tpl +++ b/codegen/service/templates/example_server_interceptor.go.tpl @@ -11,14 +11,14 @@ func New{{ .StructName }}ServerInterceptors() *{{ .StructName }}ServerIntercepto {{- if .Description }} {{ comment .Description }} {{- end }} -func (i *{{ $.StructName }}ServerInterceptors) {{ .Name }}(ctx context.Context, info *{{ $.PkgName }}.{{ .Name }}Info, next goa.InterceptorEndpoint) (any, context.Context, error) { +func (i *{{ $.StructName }}ServerInterceptors) {{ .Name }}(ctx context.Context, info *{{ $.PkgName }}.{{ .Name }}Info, next goa.Endpoint) (any, error) { log.Printf(ctx, "[{{ .Name }}] Processing request: %v", info.RawPayload()) - resp, ctx, err := next(ctx, info.RawPayload()) + resp, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[{{ .Name }}] Error: %v", err) - return nil, ctx, err + return nil, err } log.Printf(ctx, "[{{ .Name }}] Response: %v", resp) - return resp, ctx, nil + return resp, nil } {{- end }} diff --git a/codegen/service/templates/server_interceptor_stream_wrapper_types.go.tpl b/codegen/service/templates/server_interceptor_stream_wrapper_types.go.tpl index 659e21cf06..a33a45fa2a 100644 --- a/codegen/service/templates/server_interceptor_stream_wrapper_types.go.tpl +++ b/codegen/service/templates/server_interceptor_stream_wrapper_types.go.tpl @@ -4,10 +4,10 @@ type wrapped{{ .Interface }} struct { ctx context.Context {{- if ne .SendTypeRef "" }} - sendWithContext func(context.Context, {{ .SendTypeRef }}) (context.Context, error) + sendWithContext func(context.Context, {{ .SendTypeRef }}) error {{- end }} {{- if ne .RecvTypeRef "" }} - recvWithContext func(context.Context) ({{ .RecvTypeRef }}, context.Context, error) + recvWithContext func(context.Context) ({{ .RecvTypeRef }}, error) {{- end }} stream {{ .Interface }} } diff --git a/codegen/service/templates/server_interceptor_stream_wrappers.go.tpl b/codegen/service/templates/server_interceptor_stream_wrappers.go.tpl index 0c62bff3f5..f07af48ca7 100644 --- a/codegen/service/templates/server_interceptor_stream_wrappers.go.tpl +++ b/codegen/service/templates/server_interceptor_stream_wrappers.go.tpl @@ -4,12 +4,11 @@ {{ comment (printf "%s streams instances of \"%s\" after executing the applied interceptor." .SendName .Interface) }} func (w *wrapped{{ .Interface }}) {{ .SendName }}(v {{ .SendTypeRef }}) error { - _, err := w.SendWithContext(w.ctx, v) - return err + return w.SendWithContext(w.ctx, v) } {{ comment (printf "%s streams instances of \"%s\" after executing the applied interceptor with context." .SendWithContextName .Interface) }} -func (w *wrapped{{ .Interface }}) {{ .SendWithContextName }}(ctx context.Context, v {{ .SendTypeRef }}) (context.Context, error) { +func (w *wrapped{{ .Interface }}) {{ .SendWithContextName }}(ctx context.Context, v {{ .SendTypeRef }}) error { if w.sendWithContext == nil { return w.stream.{{ .SendWithContextName }}(ctx, v) } @@ -20,12 +19,11 @@ func (w *wrapped{{ .Interface }}) {{ .SendWithContextName }}(ctx context.Context {{ comment (printf "%s reads instances of \"%s\" from the stream after executing the applied interceptor." .RecvName .Interface) }} func (w *wrapped{{ .Interface }}) {{ .RecvName }}() ({{ .RecvTypeRef }}, error) { - res, _, err := w.RecvWithContext(w.ctx) - return res, err + return w.RecvWithContext(w.ctx) } {{ comment (printf "%s reads instances of \"%s\" from the stream after executing the applied interceptor with context." .RecvWithContextName .Interface) }} -func (w *wrapped{{ .Interface }}) {{ .RecvWithContextName }}(ctx context.Context) ({{ .RecvTypeRef }}, context.Context, error) { +func (w *wrapped{{ .Interface }}) {{ .RecvWithContextName }}(ctx context.Context) ({{ .RecvTypeRef }}, error) { if w.recvWithContext == nil { return w.stream.{{ .RecvWithContextName }}(ctx) } diff --git a/codegen/service/templates/server_interceptor_wrappers.go.tpl b/codegen/service/templates/server_interceptor_wrappers.go.tpl index 30b6fccbed..0fd7366a9a 100644 --- a/codegen/service/templates/server_interceptor_wrappers.go.tpl +++ b/codegen/service/templates/server_interceptor_wrappers.go.tpl @@ -3,8 +3,8 @@ {{- range .Methods }} {{ comment (printf "wrap%s%s applies the %s server interceptor to endpoints." $interceptor.Name .MethodName $interceptor.DesignName) }} -func wrap{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { - return func(ctx context.Context, req any) (any, context.Context, error) { +func wrap{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { + return func(ctx context.Context, req any) (any, error) { {{- if or $interceptor.HasStreamingPayloadAccess $interceptor.HasStreamingResultAccess }} {{- if $interceptor.HasPayloadAccess }} info := &{{ $interceptor.Name }}Info{ @@ -13,48 +13,47 @@ func wrap{{ .MethodName }}{{ $interceptor.Name }}(endpoint goa.InterceptorEndpoi callType: goa.InterceptorUnary, rawPayload: req, } - res, ctx, err := i.{{ $interceptor.Name }}(ctx, info, endpoint) + res, err := i.{{ $interceptor.Name }}(ctx, info, endpoint) {{- else }} - res, ctx, err := endpoint(ctx, req) + res, err := endpoint(ctx, req) {{- end }} if err != nil { - return res, ctx, err + return res, err } stream := res.({{ .ServerStream.Interface }}) return &wrapped{{ .ServerStream.Interface }}{ ctx: ctx, {{- if $interceptor.HasStreamingResultAccess }} - sendWithContext: func(ctx context.Context, req {{ .ServerStream.SendTypeRef }}) (context.Context, error) { + sendWithContext: func(ctx context.Context, req {{ .ServerStream.SendTypeRef }}) error { info := &{{ $interceptor.Name }}Info{ service: "{{ $.Service }}", method: "{{ .MethodName }}", callType: goa.InterceptorStreamingSend, rawPayload: req, } - _, ctx, err := i.{{ $interceptor.Name }}(ctx, info, func(ctx context.Context, req any) (any, context.Context, error) { + _, err := i.{{ $interceptor.Name }}(ctx, info, func(ctx context.Context, req any) (any, error) { castReq, _ := req.({{ .ServerStream.SendTypeRef }}) - ctx, err := stream.{{ .ServerStream.SendWithContextName }}(ctx, castReq) - return nil, ctx, err + return nil, stream.{{ .ServerStream.SendWithContextName }}(ctx, castReq) }) - return ctx, err + return err }, {{- end }} {{- if $interceptor.HasStreamingPayloadAccess }} - recvWithContext: func(ctx context.Context) ({{ .ServerStream.RecvTypeRef }}, context.Context, error) { + recvWithContext: func(ctx context.Context) ({{ .ServerStream.RecvTypeRef }}, error) { info := &{{ $interceptor.Name }}Info{ service: "{{ $.Service }}", method: "{{ .MethodName }}", callType: goa.InterceptorStreamingRecv, } - res, ctx, err := i.{{ $interceptor.Name }}(ctx, info, func(ctx context.Context, _ any) (any, context.Context, error) { + res, err := i.{{ $interceptor.Name }}(ctx, info, func(ctx context.Context, _ any) (any, error) { return stream.{{ .ServerStream.RecvWithContextName }}(ctx) }) castRes, _ := res.({{ .ServerStream.RecvTypeRef }}) - return castRes, ctx, err + return castRes, err }, {{- end }} stream: stream, - }, ctx, nil + }, nil {{- else }} info := &{{ $interceptor.Name }}Info{ service: "{{ $.Service }}", diff --git a/codegen/service/templates/server_interceptors.go.tpl b/codegen/service/templates/server_interceptors.go.tpl index e5d869622e..3bd263dc95 100644 --- a/codegen/service/templates/server_interceptors.go.tpl +++ b/codegen/service/templates/server_interceptors.go.tpl @@ -7,6 +7,6 @@ type ServerInterceptors interface { {{- if .Description }} {{ comment .Description }} {{- end }} - {{ .Name }}(ctx context.Context, info *{{ .Name }}Info, next goa.InterceptorEndpoint) (any, context.Context, error) + {{ .Name }}(ctx context.Context, info *{{ .Name }}Info, next goa.Endpoint) (any, error) {{- end }} } diff --git a/codegen/service/templates/service.go.tpl b/codegen/service/templates/service.go.tpl index 431769507e..6a3334a5bd 100644 --- a/codegen/service/templates/service.go.tpl +++ b/codegen/service/templates/service.go.tpl @@ -65,13 +65,13 @@ type {{ .Stream.Interface }} interface { {{ comment .Stream.SendDesc }} {{ .Stream.SendName }}({{ .Stream.SendTypeRef }}) error {{ comment .Stream.SendWithContextDesc }} - {{ .Stream.SendWithContextName }}(context.Context, {{ .Stream.SendTypeRef }}) (context.Context, error) + {{ .Stream.SendWithContextName }}(context.Context, {{ .Stream.SendTypeRef }}) error {{- end }} {{- if .Stream.RecvTypeRef }} {{ comment .Stream.RecvDesc }} {{ .Stream.RecvName }}() ({{ .Stream.RecvTypeRef }}, error) {{ comment .Stream.RecvWithContextDesc }} - {{ .Stream.RecvWithContextName }}(context.Context) ({{ .Stream.RecvTypeRef }}, context.Context, error) + {{ .Stream.RecvWithContextName }}(context.Context) ({{ .Stream.RecvTypeRef }}, error) {{- end }} {{- if .Stream.MustClose }} {{ comment "Close closes the stream." }} diff --git a/codegen/service/testdata/example_interceptors/api_interceptor_service_client.golden b/codegen/service/testdata/example_interceptors/api_interceptor_service_client.golden index 5cb6b71d33..57b92d14f2 100644 --- a/codegen/service/testdata/example_interceptors/api_interceptor_service_client.golden +++ b/codegen/service/testdata/example_interceptors/api_interceptor_service_client.golden @@ -23,13 +23,13 @@ type APIInterceptorServiceClientInterceptors struct { func NewAPIInterceptorServiceClientInterceptors() *APIInterceptorServiceClientInterceptors { return &APIInterceptorServiceClientInterceptors{} } -func (i *APIInterceptorServiceClientInterceptors) API(ctx context.Context, info *interceptors.APIInfo, next goa.InterceptorEndpoint) (any, context.Context, error) { +func (i *APIInterceptorServiceClientInterceptors) API(ctx context.Context, info *interceptors.APIInfo, next goa.Endpoint) (any, error) { log.Printf(ctx, "[API] Sending request: %v", info.RawPayload()) - resp, ctx, err := next(ctx, info.RawPayload()) + resp, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[API] Error: %v", err) - return nil, ctx, err + return nil, err } log.Printf(ctx, "[API] Received response: %v", resp) - return resp, ctx, nil + return resp, nil } diff --git a/codegen/service/testdata/example_interceptors/api_interceptor_service_server.golden b/codegen/service/testdata/example_interceptors/api_interceptor_service_server.golden index e193d8083f..4be7b616b5 100644 --- a/codegen/service/testdata/example_interceptors/api_interceptor_service_server.golden +++ b/codegen/service/testdata/example_interceptors/api_interceptor_service_server.golden @@ -23,13 +23,13 @@ type APIInterceptorServiceServerInterceptors struct { func NewAPIInterceptorServiceServerInterceptors() *APIInterceptorServiceServerInterceptors { return &APIInterceptorServiceServerInterceptors{} } -func (i *APIInterceptorServiceServerInterceptors) API(ctx context.Context, info *interceptors.APIInfo, next goa.InterceptorEndpoint) (any, context.Context, error) { +func (i *APIInterceptorServiceServerInterceptors) API(ctx context.Context, info *interceptors.APIInfo, next goa.Endpoint) (any, error) { log.Printf(ctx, "[API] Processing request: %v", info.RawPayload()) - resp, ctx, err := next(ctx, info.RawPayload()) + resp, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[API] Error: %v", err) - return nil, ctx, err + return nil, err } log.Printf(ctx, "[API] Response: %v", resp) - return resp, ctx, nil + return resp, nil } diff --git a/codegen/service/testdata/example_interceptors/chained_interceptor_service_client.golden b/codegen/service/testdata/example_interceptors/chained_interceptor_service_client.golden index ca3f13bb6a..303c529a4c 100644 --- a/codegen/service/testdata/example_interceptors/chained_interceptor_service_client.golden +++ b/codegen/service/testdata/example_interceptors/chained_interceptor_service_client.golden @@ -23,33 +23,33 @@ type ChainedInterceptorServiceClientInterceptors struct { func NewChainedInterceptorServiceClientInterceptors() *ChainedInterceptorServiceClientInterceptors { return &ChainedInterceptorServiceClientInterceptors{} } -func (i *ChainedInterceptorServiceClientInterceptors) API(ctx context.Context, info *interceptors.APIInfo, next goa.InterceptorEndpoint) (any, context.Context, error) { +func (i *ChainedInterceptorServiceClientInterceptors) API(ctx context.Context, info *interceptors.APIInfo, next goa.Endpoint) (any, error) { log.Printf(ctx, "[API] Sending request: %v", info.RawPayload()) - resp, ctx, err := next(ctx, info.RawPayload()) + resp, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[API] Error: %v", err) - return nil, ctx, err + return nil, err } log.Printf(ctx, "[API] Received response: %v", resp) - return resp, ctx, nil + return resp, nil } -func (i *ChainedInterceptorServiceClientInterceptors) Method(ctx context.Context, info *interceptors.MethodInfo, next goa.InterceptorEndpoint) (any, context.Context, error) { +func (i *ChainedInterceptorServiceClientInterceptors) Method(ctx context.Context, info *interceptors.MethodInfo, next goa.Endpoint) (any, error) { log.Printf(ctx, "[Method] Sending request: %v", info.RawPayload()) - resp, ctx, err := next(ctx, info.RawPayload()) + resp, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[Method] Error: %v", err) - return nil, ctx, err + return nil, err } log.Printf(ctx, "[Method] Received response: %v", resp) - return resp, ctx, nil + return resp, nil } -func (i *ChainedInterceptorServiceClientInterceptors) Service(ctx context.Context, info *interceptors.ServiceInfo, next goa.InterceptorEndpoint) (any, context.Context, error) { +func (i *ChainedInterceptorServiceClientInterceptors) Service(ctx context.Context, info *interceptors.ServiceInfo, next goa.Endpoint) (any, error) { log.Printf(ctx, "[Service] Sending request: %v", info.RawPayload()) - resp, ctx, err := next(ctx, info.RawPayload()) + resp, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[Service] Error: %v", err) - return nil, ctx, err + return nil, err } log.Printf(ctx, "[Service] Received response: %v", resp) - return resp, ctx, nil + return resp, nil } diff --git a/codegen/service/testdata/example_interceptors/chained_interceptor_service_server.golden b/codegen/service/testdata/example_interceptors/chained_interceptor_service_server.golden index baf6d5f9c8..cfec655426 100644 --- a/codegen/service/testdata/example_interceptors/chained_interceptor_service_server.golden +++ b/codegen/service/testdata/example_interceptors/chained_interceptor_service_server.golden @@ -23,33 +23,33 @@ type ChainedInterceptorServiceServerInterceptors struct { func NewChainedInterceptorServiceServerInterceptors() *ChainedInterceptorServiceServerInterceptors { return &ChainedInterceptorServiceServerInterceptors{} } -func (i *ChainedInterceptorServiceServerInterceptors) API(ctx context.Context, info *interceptors.APIInfo, next goa.InterceptorEndpoint) (any, context.Context, error) { +func (i *ChainedInterceptorServiceServerInterceptors) API(ctx context.Context, info *interceptors.APIInfo, next goa.Endpoint) (any, error) { log.Printf(ctx, "[API] Processing request: %v", info.RawPayload()) - resp, ctx, err := next(ctx, info.RawPayload()) + resp, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[API] Error: %v", err) - return nil, ctx, err + return nil, err } log.Printf(ctx, "[API] Response: %v", resp) - return resp, ctx, nil + return resp, nil } -func (i *ChainedInterceptorServiceServerInterceptors) Method(ctx context.Context, info *interceptors.MethodInfo, next goa.InterceptorEndpoint) (any, context.Context, error) { +func (i *ChainedInterceptorServiceServerInterceptors) Method(ctx context.Context, info *interceptors.MethodInfo, next goa.Endpoint) (any, error) { log.Printf(ctx, "[Method] Processing request: %v", info.RawPayload()) - resp, ctx, err := next(ctx, info.RawPayload()) + resp, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[Method] Error: %v", err) - return nil, ctx, err + return nil, err } log.Printf(ctx, "[Method] Response: %v", resp) - return resp, ctx, nil + return resp, nil } -func (i *ChainedInterceptorServiceServerInterceptors) Service(ctx context.Context, info *interceptors.ServiceInfo, next goa.InterceptorEndpoint) (any, context.Context, error) { +func (i *ChainedInterceptorServiceServerInterceptors) Service(ctx context.Context, info *interceptors.ServiceInfo, next goa.Endpoint) (any, error) { log.Printf(ctx, "[Service] Processing request: %v", info.RawPayload()) - resp, ctx, err := next(ctx, info.RawPayload()) + resp, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[Service] Error: %v", err) - return nil, ctx, err + return nil, err } log.Printf(ctx, "[Service] Response: %v", resp) - return resp, ctx, nil + return resp, nil } diff --git a/codegen/service/testdata/example_interceptors/client_interceptor_service_client.golden b/codegen/service/testdata/example_interceptors/client_interceptor_service_client.golden index c216cc8a4e..073621102b 100644 --- a/codegen/service/testdata/example_interceptors/client_interceptor_service_client.golden +++ b/codegen/service/testdata/example_interceptors/client_interceptor_service_client.golden @@ -23,13 +23,13 @@ type ClientInterceptorServiceClientInterceptors struct { func NewClientInterceptorServiceClientInterceptors() *ClientInterceptorServiceClientInterceptors { return &ClientInterceptorServiceClientInterceptors{} } -func (i *ClientInterceptorServiceClientInterceptors) Test(ctx context.Context, info *interceptors.TestInfo, next goa.InterceptorEndpoint) (any, context.Context, error) { +func (i *ClientInterceptorServiceClientInterceptors) Test(ctx context.Context, info *interceptors.TestInfo, next goa.Endpoint) (any, error) { log.Printf(ctx, "[Test] Sending request: %v", info.RawPayload()) - resp, ctx, err := next(ctx, info.RawPayload()) + resp, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[Test] Error: %v", err) - return nil, ctx, err + return nil, err } log.Printf(ctx, "[Test] Received response: %v", resp) - return resp, ctx, nil + return resp, nil } diff --git a/codegen/service/testdata/example_interceptors/multiple_interceptors_service_client.golden b/codegen/service/testdata/example_interceptors/multiple_interceptors_service_client.golden index c4ff52cd5d..37663e0c13 100644 --- a/codegen/service/testdata/example_interceptors/multiple_interceptors_service_client.golden +++ b/codegen/service/testdata/example_interceptors/multiple_interceptors_service_client.golden @@ -23,23 +23,23 @@ type MultipleInterceptorsServiceClientInterceptors struct { func NewMultipleInterceptorsServiceClientInterceptors() *MultipleInterceptorsServiceClientInterceptors { return &MultipleInterceptorsServiceClientInterceptors{} } -func (i *MultipleInterceptorsServiceClientInterceptors) Test2(ctx context.Context, info *interceptors.Test2Info, next goa.InterceptorEndpoint) (any, context.Context, error) { +func (i *MultipleInterceptorsServiceClientInterceptors) Test2(ctx context.Context, info *interceptors.Test2Info, next goa.Endpoint) (any, error) { log.Printf(ctx, "[Test2] Sending request: %v", info.RawPayload()) - resp, ctx, err := next(ctx, info.RawPayload()) + resp, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[Test2] Error: %v", err) - return nil, ctx, err + return nil, err } log.Printf(ctx, "[Test2] Received response: %v", resp) - return resp, ctx, nil + return resp, nil } -func (i *MultipleInterceptorsServiceClientInterceptors) Test4(ctx context.Context, info *interceptors.Test4Info, next goa.InterceptorEndpoint) (any, context.Context, error) { +func (i *MultipleInterceptorsServiceClientInterceptors) Test4(ctx context.Context, info *interceptors.Test4Info, next goa.Endpoint) (any, error) { log.Printf(ctx, "[Test4] Sending request: %v", info.RawPayload()) - resp, ctx, err := next(ctx, info.RawPayload()) + resp, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[Test4] Error: %v", err) - return nil, ctx, err + return nil, err } log.Printf(ctx, "[Test4] Received response: %v", resp) - return resp, ctx, nil + return resp, nil } diff --git a/codegen/service/testdata/example_interceptors/multiple_interceptors_service_server.golden b/codegen/service/testdata/example_interceptors/multiple_interceptors_service_server.golden index e5795aa7f7..3d51f2cbeb 100644 --- a/codegen/service/testdata/example_interceptors/multiple_interceptors_service_server.golden +++ b/codegen/service/testdata/example_interceptors/multiple_interceptors_service_server.golden @@ -23,23 +23,23 @@ type MultipleInterceptorsServiceServerInterceptors struct { func NewMultipleInterceptorsServiceServerInterceptors() *MultipleInterceptorsServiceServerInterceptors { return &MultipleInterceptorsServiceServerInterceptors{} } -func (i *MultipleInterceptorsServiceServerInterceptors) Test(ctx context.Context, info *interceptors.TestInfo, next goa.InterceptorEndpoint) (any, context.Context, error) { +func (i *MultipleInterceptorsServiceServerInterceptors) Test(ctx context.Context, info *interceptors.TestInfo, next goa.Endpoint) (any, error) { log.Printf(ctx, "[Test] Processing request: %v", info.RawPayload()) - resp, ctx, err := next(ctx, info.RawPayload()) + resp, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[Test] Error: %v", err) - return nil, ctx, err + return nil, err } log.Printf(ctx, "[Test] Response: %v", resp) - return resp, ctx, nil + return resp, nil } -func (i *MultipleInterceptorsServiceServerInterceptors) Test3(ctx context.Context, info *interceptors.Test3Info, next goa.InterceptorEndpoint) (any, context.Context, error) { +func (i *MultipleInterceptorsServiceServerInterceptors) Test3(ctx context.Context, info *interceptors.Test3Info, next goa.Endpoint) (any, error) { log.Printf(ctx, "[Test3] Processing request: %v", info.RawPayload()) - resp, ctx, err := next(ctx, info.RawPayload()) + resp, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[Test3] Error: %v", err) - return nil, ctx, err + return nil, err } log.Printf(ctx, "[Test3] Response: %v", resp) - return resp, ctx, nil + return resp, nil } diff --git a/codegen/service/testdata/example_interceptors/multiple_services_interceptors_service2_client.golden b/codegen/service/testdata/example_interceptors/multiple_services_interceptors_service2_client.golden index 2de5dfe09c..6c394d7ef0 100644 --- a/codegen/service/testdata/example_interceptors/multiple_services_interceptors_service2_client.golden +++ b/codegen/service/testdata/example_interceptors/multiple_services_interceptors_service2_client.golden @@ -23,23 +23,23 @@ type MultipleServicesInterceptorsService2ClientInterceptors struct { func NewMultipleServicesInterceptorsService2ClientInterceptors() *MultipleServicesInterceptorsService2ClientInterceptors { return &MultipleServicesInterceptorsService2ClientInterceptors{} } -func (i *MultipleServicesInterceptorsService2ClientInterceptors) Test2(ctx context.Context, info *interceptors.Test2Info, next goa.InterceptorEndpoint) (any, context.Context, error) { +func (i *MultipleServicesInterceptorsService2ClientInterceptors) Test2(ctx context.Context, info *interceptors.Test2Info, next goa.Endpoint) (any, error) { log.Printf(ctx, "[Test2] Sending request: %v", info.RawPayload()) - resp, ctx, err := next(ctx, info.RawPayload()) + resp, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[Test2] Error: %v", err) - return nil, ctx, err + return nil, err } log.Printf(ctx, "[Test2] Received response: %v", resp) - return resp, ctx, nil + return resp, nil } -func (i *MultipleServicesInterceptorsService2ClientInterceptors) Test4(ctx context.Context, info *interceptors.Test4Info, next goa.InterceptorEndpoint) (any, context.Context, error) { +func (i *MultipleServicesInterceptorsService2ClientInterceptors) Test4(ctx context.Context, info *interceptors.Test4Info, next goa.Endpoint) (any, error) { log.Printf(ctx, "[Test4] Sending request: %v", info.RawPayload()) - resp, ctx, err := next(ctx, info.RawPayload()) + resp, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[Test4] Error: %v", err) - return nil, ctx, err + return nil, err } log.Printf(ctx, "[Test4] Received response: %v", resp) - return resp, ctx, nil + return resp, nil } diff --git a/codegen/service/testdata/example_interceptors/multiple_services_interceptors_service2_server.golden b/codegen/service/testdata/example_interceptors/multiple_services_interceptors_service2_server.golden index e6988dcd6f..c17c39709b 100644 --- a/codegen/service/testdata/example_interceptors/multiple_services_interceptors_service2_server.golden +++ b/codegen/service/testdata/example_interceptors/multiple_services_interceptors_service2_server.golden @@ -23,23 +23,23 @@ type MultipleServicesInterceptorsService2ServerInterceptors struct { func NewMultipleServicesInterceptorsService2ServerInterceptors() *MultipleServicesInterceptorsService2ServerInterceptors { return &MultipleServicesInterceptorsService2ServerInterceptors{} } -func (i *MultipleServicesInterceptorsService2ServerInterceptors) Test(ctx context.Context, info *interceptors.TestInfo, next goa.InterceptorEndpoint) (any, context.Context, error) { +func (i *MultipleServicesInterceptorsService2ServerInterceptors) Test(ctx context.Context, info *interceptors.TestInfo, next goa.Endpoint) (any, error) { log.Printf(ctx, "[Test] Processing request: %v", info.RawPayload()) - resp, ctx, err := next(ctx, info.RawPayload()) + resp, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[Test] Error: %v", err) - return nil, ctx, err + return nil, err } log.Printf(ctx, "[Test] Response: %v", resp) - return resp, ctx, nil + return resp, nil } -func (i *MultipleServicesInterceptorsService2ServerInterceptors) Test3(ctx context.Context, info *interceptors.Test3Info, next goa.InterceptorEndpoint) (any, context.Context, error) { +func (i *MultipleServicesInterceptorsService2ServerInterceptors) Test3(ctx context.Context, info *interceptors.Test3Info, next goa.Endpoint) (any, error) { log.Printf(ctx, "[Test3] Processing request: %v", info.RawPayload()) - resp, ctx, err := next(ctx, info.RawPayload()) + resp, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[Test3] Error: %v", err) - return nil, ctx, err + return nil, err } log.Printf(ctx, "[Test3] Response: %v", resp) - return resp, ctx, nil + return resp, nil } diff --git a/codegen/service/testdata/example_interceptors/multiple_services_interceptors_service_client.golden b/codegen/service/testdata/example_interceptors/multiple_services_interceptors_service_client.golden index ae0d6c70b6..f773c4ee6c 100644 --- a/codegen/service/testdata/example_interceptors/multiple_services_interceptors_service_client.golden +++ b/codegen/service/testdata/example_interceptors/multiple_services_interceptors_service_client.golden @@ -23,23 +23,23 @@ type MultipleServicesInterceptorsServiceClientInterceptors struct { func NewMultipleServicesInterceptorsServiceClientInterceptors() *MultipleServicesInterceptorsServiceClientInterceptors { return &MultipleServicesInterceptorsServiceClientInterceptors{} } -func (i *MultipleServicesInterceptorsServiceClientInterceptors) Test2(ctx context.Context, info *interceptors.Test2Info, next goa.InterceptorEndpoint) (any, context.Context, error) { +func (i *MultipleServicesInterceptorsServiceClientInterceptors) Test2(ctx context.Context, info *interceptors.Test2Info, next goa.Endpoint) (any, error) { log.Printf(ctx, "[Test2] Sending request: %v", info.RawPayload()) - resp, ctx, err := next(ctx, info.RawPayload()) + resp, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[Test2] Error: %v", err) - return nil, ctx, err + return nil, err } log.Printf(ctx, "[Test2] Received response: %v", resp) - return resp, ctx, nil + return resp, nil } -func (i *MultipleServicesInterceptorsServiceClientInterceptors) Test4(ctx context.Context, info *interceptors.Test4Info, next goa.InterceptorEndpoint) (any, context.Context, error) { +func (i *MultipleServicesInterceptorsServiceClientInterceptors) Test4(ctx context.Context, info *interceptors.Test4Info, next goa.Endpoint) (any, error) { log.Printf(ctx, "[Test4] Sending request: %v", info.RawPayload()) - resp, ctx, err := next(ctx, info.RawPayload()) + resp, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[Test4] Error: %v", err) - return nil, ctx, err + return nil, err } log.Printf(ctx, "[Test4] Received response: %v", resp) - return resp, ctx, nil + return resp, nil } diff --git a/codegen/service/testdata/example_interceptors/multiple_services_interceptors_service_server.golden b/codegen/service/testdata/example_interceptors/multiple_services_interceptors_service_server.golden index 47d45b2270..94c67c5d41 100644 --- a/codegen/service/testdata/example_interceptors/multiple_services_interceptors_service_server.golden +++ b/codegen/service/testdata/example_interceptors/multiple_services_interceptors_service_server.golden @@ -23,23 +23,23 @@ type MultipleServicesInterceptorsServiceServerInterceptors struct { func NewMultipleServicesInterceptorsServiceServerInterceptors() *MultipleServicesInterceptorsServiceServerInterceptors { return &MultipleServicesInterceptorsServiceServerInterceptors{} } -func (i *MultipleServicesInterceptorsServiceServerInterceptors) Test(ctx context.Context, info *interceptors.TestInfo, next goa.InterceptorEndpoint) (any, context.Context, error) { +func (i *MultipleServicesInterceptorsServiceServerInterceptors) Test(ctx context.Context, info *interceptors.TestInfo, next goa.Endpoint) (any, error) { log.Printf(ctx, "[Test] Processing request: %v", info.RawPayload()) - resp, ctx, err := next(ctx, info.RawPayload()) + resp, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[Test] Error: %v", err) - return nil, ctx, err + return nil, err } log.Printf(ctx, "[Test] Response: %v", resp) - return resp, ctx, nil + return resp, nil } -func (i *MultipleServicesInterceptorsServiceServerInterceptors) Test3(ctx context.Context, info *interceptors.Test3Info, next goa.InterceptorEndpoint) (any, context.Context, error) { +func (i *MultipleServicesInterceptorsServiceServerInterceptors) Test3(ctx context.Context, info *interceptors.Test3Info, next goa.Endpoint) (any, error) { log.Printf(ctx, "[Test3] Processing request: %v", info.RawPayload()) - resp, ctx, err := next(ctx, info.RawPayload()) + resp, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[Test3] Error: %v", err) - return nil, ctx, err + return nil, err } log.Printf(ctx, "[Test3] Response: %v", resp) - return resp, ctx, nil + return resp, nil } diff --git a/codegen/service/testdata/example_interceptors/server_interceptor_by_name_service_server.golden b/codegen/service/testdata/example_interceptors/server_interceptor_by_name_service_server.golden index aacac9a275..4136d5f9ec 100644 --- a/codegen/service/testdata/example_interceptors/server_interceptor_by_name_service_server.golden +++ b/codegen/service/testdata/example_interceptors/server_interceptor_by_name_service_server.golden @@ -23,13 +23,13 @@ type ServerInterceptorByNameServiceServerInterceptors struct { func NewServerInterceptorByNameServiceServerInterceptors() *ServerInterceptorByNameServiceServerInterceptors { return &ServerInterceptorByNameServiceServerInterceptors{} } -func (i *ServerInterceptorByNameServiceServerInterceptors) Test(ctx context.Context, info *interceptors.TestInfo, next goa.InterceptorEndpoint) (any, context.Context, error) { +func (i *ServerInterceptorByNameServiceServerInterceptors) Test(ctx context.Context, info *interceptors.TestInfo, next goa.Endpoint) (any, error) { log.Printf(ctx, "[Test] Processing request: %v", info.RawPayload()) - resp, ctx, err := next(ctx, info.RawPayload()) + resp, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[Test] Error: %v", err) - return nil, ctx, err + return nil, err } log.Printf(ctx, "[Test] Response: %v", resp) - return resp, ctx, nil + return resp, nil } diff --git a/codegen/service/testdata/example_interceptors/server_interceptor_service_server.golden b/codegen/service/testdata/example_interceptors/server_interceptor_service_server.golden index bbedae66fd..6f5d89a40d 100644 --- a/codegen/service/testdata/example_interceptors/server_interceptor_service_server.golden +++ b/codegen/service/testdata/example_interceptors/server_interceptor_service_server.golden @@ -23,13 +23,13 @@ type ServerInterceptorServiceServerInterceptors struct { func NewServerInterceptorServiceServerInterceptors() *ServerInterceptorServiceServerInterceptors { return &ServerInterceptorServiceServerInterceptors{} } -func (i *ServerInterceptorServiceServerInterceptors) Test(ctx context.Context, info *interceptors.TestInfo, next goa.InterceptorEndpoint) (any, context.Context, error) { +func (i *ServerInterceptorServiceServerInterceptors) Test(ctx context.Context, info *interceptors.TestInfo, next goa.Endpoint) (any, error) { log.Printf(ctx, "[Test] Processing request: %v", info.RawPayload()) - resp, ctx, err := next(ctx, info.RawPayload()) + resp, err := next(ctx, info.RawPayload()) if err != nil { log.Printf(ctx, "[Test] Error: %v", err) - return nil, ctx, err + return nil, err } log.Printf(ctx, "[Test] Response: %v", resp) - return resp, ctx, nil + return resp, nil } diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-payload_client_interceptors.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-payload_client_interceptors.go.golden index 3c2f41b687..5b21e6d339 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-payload_client_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-payload_client_interceptors.go.golden @@ -3,19 +3,12 @@ // is sent to the server. The implementation is responsible for calling next to // complete the request. type ClientInterceptors interface { - Validation(ctx context.Context, info *ValidationInfo, next goa.InterceptorEndpoint) (any, context.Context, error) + Validation(ctx context.Context, info *ValidationInfo, next goa.Endpoint) (any, error) } // WrapMethodClientEndpoint wraps the Method endpoint with the client // interceptors defined in the design. func WrapMethodClientEndpoint(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { - var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { - response, err := endpoint(ctx, request) - return response, ctx, err - } - interceptorEndpoint = wrapClientMethodvalidation(interceptorEndpoint, i) - return func(ctx context.Context, request any) (any, error) { - response, _, err := interceptorEndpoint(ctx, request) - return response, err - } + endpoint = wrapClientMethodvalidation(endpoint, i) + return endpoint } diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-payload_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-payload_interceptor_wrappers.go.golden index d958a06c98..0cde37225c 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-payload_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-payload_interceptor_wrappers.go.golden @@ -1,8 +1,8 @@ // wrapValidationMethod applies the validation server interceptor to endpoints. -func wrapMethodValidation(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { - return func(ctx context.Context, req any) (any, context.Context, error) { +func wrapMethodValidation(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { + return func(ctx context.Context, req any) (any, error) { info := &ValidationInfo{ service: "InterceptorWithReadPayload", method: "Method", @@ -15,8 +15,8 @@ func wrapMethodValidation(endpoint goa.InterceptorEndpoint, i ServerInterceptors // wrapClientValidationMethod applies the validation client interceptor to // endpoints. -func wrapClientMethodValidation(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { - return func(ctx context.Context, req any) (any, context.Context, error) { +func wrapClientMethodValidation(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { + return func(ctx context.Context, req any) (any, error) { info := &ValidationInfo{ service: "InterceptorWithReadPayload", method: "Method", diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-payload_service_interceptors.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-payload_service_interceptors.go.golden index 003429e587..3acc1de99c 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-payload_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-payload_service_interceptors.go.golden @@ -3,7 +3,7 @@ // payload is sent to the service. The implementation is responsible for calling // next to complete the request. type ServerInterceptors interface { - Validation(ctx context.Context, info *ValidationInfo, next goa.InterceptorEndpoint) (any, context.Context, error) + Validation(ctx context.Context, info *ValidationInfo, next goa.Endpoint) (any, error) } // Access interfaces for interceptor payloads and results @@ -35,15 +35,8 @@ type ( // WrapMethodEndpoint wraps the Method endpoint with the server-side // interceptors defined in the design. func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { - response, err := endpoint(ctx, request) - return response, ctx, err - } - interceptorEndpoint = wrapMethodvalidation(interceptorEndpoint, i) - return func(ctx context.Context, request any) (any, error) { - response, _, err := interceptorEndpoint(ctx, request) - return response, err - } + endpoint = wrapMethodvalidation(endpoint, i) + return endpoint } // Public accessor methods for Info types diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-result_client_interceptors.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-result_client_interceptors.go.golden index 91c9e06107..7bf0271866 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-result_client_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-result_client_interceptors.go.golden @@ -3,19 +3,12 @@ // is sent to the server. The implementation is responsible for calling next to // complete the request. type ClientInterceptors interface { - Caching(ctx context.Context, info *CachingInfo, next goa.InterceptorEndpoint) (any, context.Context, error) + Caching(ctx context.Context, info *CachingInfo, next goa.Endpoint) (any, error) } // WrapMethodClientEndpoint wraps the Method endpoint with the client // interceptors defined in the design. func WrapMethodClientEndpoint(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { - var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { - response, err := endpoint(ctx, request) - return response, ctx, err - } - interceptorEndpoint = wrapClientMethodcaching(interceptorEndpoint, i) - return func(ctx context.Context, request any) (any, error) { - response, _, err := interceptorEndpoint(ctx, request) - return response, err - } + endpoint = wrapClientMethodcaching(endpoint, i) + return endpoint } diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-result_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-result_interceptor_wrappers.go.golden index d09f9368ce..431b0789ce 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-result_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-result_interceptor_wrappers.go.golden @@ -1,8 +1,8 @@ // wrapCachingMethod applies the caching server interceptor to endpoints. -func wrapMethodCaching(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { - return func(ctx context.Context, req any) (any, context.Context, error) { +func wrapMethodCaching(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { + return func(ctx context.Context, req any) (any, error) { info := &CachingInfo{ service: "InterceptorWithReadResult", method: "Method", @@ -14,8 +14,8 @@ func wrapMethodCaching(endpoint goa.InterceptorEndpoint, i ServerInterceptors) g } // wrapClientCachingMethod applies the caching client interceptor to endpoints. -func wrapClientMethodCaching(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { - return func(ctx context.Context, req any) (any, context.Context, error) { +func wrapClientMethodCaching(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { + return func(ctx context.Context, req any) (any, error) { info := &CachingInfo{ service: "InterceptorWithReadResult", method: "Method", diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-result_service_interceptors.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-result_service_interceptors.go.golden index d920902b55..acbf42db74 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-result_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-result_service_interceptors.go.golden @@ -3,7 +3,7 @@ // payload is sent to the service. The implementation is responsible for calling // next to complete the request. type ServerInterceptors interface { - Caching(ctx context.Context, info *CachingInfo, next goa.InterceptorEndpoint) (any, context.Context, error) + Caching(ctx context.Context, info *CachingInfo, next goa.Endpoint) (any, error) } // Access interfaces for interceptor payloads and results @@ -35,15 +35,8 @@ type ( // WrapMethodEndpoint wraps the Method endpoint with the server-side // interceptors defined in the design. func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { - response, err := endpoint(ctx, request) - return response, ctx, err - } - interceptorEndpoint = wrapMethodcaching(interceptorEndpoint, i) - return func(ctx context.Context, request any) (any, error) { - response, _, err := interceptorEndpoint(ctx, request) - return response, err - } + endpoint = wrapMethodcaching(endpoint, i) + return endpoint } // Public accessor methods for Info types diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_client_interceptors.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_client_interceptors.go.golden index 3c2f41b687..5b21e6d339 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_client_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_client_interceptors.go.golden @@ -3,19 +3,12 @@ // is sent to the server. The implementation is responsible for calling next to // complete the request. type ClientInterceptors interface { - Validation(ctx context.Context, info *ValidationInfo, next goa.InterceptorEndpoint) (any, context.Context, error) + Validation(ctx context.Context, info *ValidationInfo, next goa.Endpoint) (any, error) } // WrapMethodClientEndpoint wraps the Method endpoint with the client // interceptors defined in the design. func WrapMethodClientEndpoint(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { - var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { - response, err := endpoint(ctx, request) - return response, ctx, err - } - interceptorEndpoint = wrapClientMethodvalidation(interceptorEndpoint, i) - return func(ctx context.Context, request any) (any, error) { - response, _, err := interceptorEndpoint(ctx, request) - return response, err - } + endpoint = wrapClientMethodvalidation(endpoint, i) + return endpoint } diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_interceptor_wrappers.go.golden index 18a9d5f81b..8a1d529196 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_interceptor_wrappers.go.golden @@ -1,8 +1,8 @@ // wrapValidationMethod applies the validation server interceptor to endpoints. -func wrapMethodValidation(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { - return func(ctx context.Context, req any) (any, context.Context, error) { +func wrapMethodValidation(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { + return func(ctx context.Context, req any) (any, error) { info := &ValidationInfo{ service: "InterceptorWithReadWritePayload", method: "Method", @@ -15,8 +15,8 @@ func wrapMethodValidation(endpoint goa.InterceptorEndpoint, i ServerInterceptors // wrapClientValidationMethod applies the validation client interceptor to // endpoints. -func wrapClientMethodValidation(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { - return func(ctx context.Context, req any) (any, context.Context, error) { +func wrapClientMethodValidation(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { + return func(ctx context.Context, req any) (any, error) { info := &ValidationInfo{ service: "InterceptorWithReadWritePayload", method: "Method", diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_service_interceptors.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_service_interceptors.go.golden index f16a0e3826..424a697488 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-write-payload_service_interceptors.go.golden @@ -3,7 +3,7 @@ // payload is sent to the service. The implementation is responsible for calling // next to complete the request. type ServerInterceptors interface { - Validation(ctx context.Context, info *ValidationInfo, next goa.InterceptorEndpoint) (any, context.Context, error) + Validation(ctx context.Context, info *ValidationInfo, next goa.Endpoint) (any, error) } // Access interfaces for interceptor payloads and results @@ -36,15 +36,8 @@ type ( // WrapMethodEndpoint wraps the Method endpoint with the server-side // interceptors defined in the design. func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { - response, err := endpoint(ctx, request) - return response, ctx, err - } - interceptorEndpoint = wrapMethodvalidation(interceptorEndpoint, i) - return func(ctx context.Context, request any) (any, error) { - response, _, err := interceptorEndpoint(ctx, request) - return response, err - } + endpoint = wrapMethodvalidation(endpoint, i) + return endpoint } // Public accessor methods for Info types diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-write-result_client_interceptors.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-write-result_client_interceptors.go.golden index 91c9e06107..7bf0271866 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-write-result_client_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-write-result_client_interceptors.go.golden @@ -3,19 +3,12 @@ // is sent to the server. The implementation is responsible for calling next to // complete the request. type ClientInterceptors interface { - Caching(ctx context.Context, info *CachingInfo, next goa.InterceptorEndpoint) (any, context.Context, error) + Caching(ctx context.Context, info *CachingInfo, next goa.Endpoint) (any, error) } // WrapMethodClientEndpoint wraps the Method endpoint with the client // interceptors defined in the design. func WrapMethodClientEndpoint(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { - var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { - response, err := endpoint(ctx, request) - return response, ctx, err - } - interceptorEndpoint = wrapClientMethodcaching(interceptorEndpoint, i) - return func(ctx context.Context, request any) (any, error) { - response, _, err := interceptorEndpoint(ctx, request) - return response, err - } + endpoint = wrapClientMethodcaching(endpoint, i) + return endpoint } diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-write-result_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-write-result_interceptor_wrappers.go.golden index 5118a98823..40be57c66d 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-write-result_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-write-result_interceptor_wrappers.go.golden @@ -1,8 +1,8 @@ // wrapCachingMethod applies the caching server interceptor to endpoints. -func wrapMethodCaching(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { - return func(ctx context.Context, req any) (any, context.Context, error) { +func wrapMethodCaching(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { + return func(ctx context.Context, req any) (any, error) { info := &CachingInfo{ service: "InterceptorWithReadWriteResult", method: "Method", @@ -14,8 +14,8 @@ func wrapMethodCaching(endpoint goa.InterceptorEndpoint, i ServerInterceptors) g } // wrapClientCachingMethod applies the caching client interceptor to endpoints. -func wrapClientMethodCaching(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { - return func(ctx context.Context, req any) (any, context.Context, error) { +func wrapClientMethodCaching(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { + return func(ctx context.Context, req any) (any, error) { info := &CachingInfo{ service: "InterceptorWithReadWriteResult", method: "Method", diff --git a/codegen/service/testdata/interceptors/interceptor-with-read-write-result_service_interceptors.go.golden b/codegen/service/testdata/interceptors/interceptor-with-read-write-result_service_interceptors.go.golden index 12c83763be..cebda374e6 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-read-write-result_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-read-write-result_service_interceptors.go.golden @@ -3,7 +3,7 @@ // payload is sent to the service. The implementation is responsible for calling // next to complete the request. type ServerInterceptors interface { - Caching(ctx context.Context, info *CachingInfo, next goa.InterceptorEndpoint) (any, context.Context, error) + Caching(ctx context.Context, info *CachingInfo, next goa.Endpoint) (any, error) } // Access interfaces for interceptor payloads and results @@ -36,15 +36,8 @@ type ( // WrapMethodEndpoint wraps the Method endpoint with the server-side // interceptors defined in the design. func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { - response, err := endpoint(ctx, request) - return response, ctx, err - } - interceptorEndpoint = wrapMethodcaching(interceptorEndpoint, i) - return func(ctx context.Context, request any) (any, error) { - response, _, err := interceptorEndpoint(ctx, request) - return response, err - } + endpoint = wrapMethodcaching(endpoint, i) + return endpoint } // Public accessor methods for Info types diff --git a/codegen/service/testdata/interceptors/interceptor-with-write-payload_client_interceptors.go.golden b/codegen/service/testdata/interceptors/interceptor-with-write-payload_client_interceptors.go.golden index 3c2f41b687..5b21e6d339 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-write-payload_client_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-write-payload_client_interceptors.go.golden @@ -3,19 +3,12 @@ // is sent to the server. The implementation is responsible for calling next to // complete the request. type ClientInterceptors interface { - Validation(ctx context.Context, info *ValidationInfo, next goa.InterceptorEndpoint) (any, context.Context, error) + Validation(ctx context.Context, info *ValidationInfo, next goa.Endpoint) (any, error) } // WrapMethodClientEndpoint wraps the Method endpoint with the client // interceptors defined in the design. func WrapMethodClientEndpoint(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { - var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { - response, err := endpoint(ctx, request) - return response, ctx, err - } - interceptorEndpoint = wrapClientMethodvalidation(interceptorEndpoint, i) - return func(ctx context.Context, request any) (any, error) { - response, _, err := interceptorEndpoint(ctx, request) - return response, err - } + endpoint = wrapClientMethodvalidation(endpoint, i) + return endpoint } diff --git a/codegen/service/testdata/interceptors/interceptor-with-write-payload_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/interceptor-with-write-payload_interceptor_wrappers.go.golden index 9f791496e8..d7059393aa 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-write-payload_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-write-payload_interceptor_wrappers.go.golden @@ -1,8 +1,8 @@ // wrapValidationMethod applies the validation server interceptor to endpoints. -func wrapMethodValidation(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { - return func(ctx context.Context, req any) (any, context.Context, error) { +func wrapMethodValidation(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { + return func(ctx context.Context, req any) (any, error) { info := &ValidationInfo{ service: "InterceptorWithWritePayload", method: "Method", @@ -15,8 +15,8 @@ func wrapMethodValidation(endpoint goa.InterceptorEndpoint, i ServerInterceptors // wrapClientValidationMethod applies the validation client interceptor to // endpoints. -func wrapClientMethodValidation(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { - return func(ctx context.Context, req any) (any, context.Context, error) { +func wrapClientMethodValidation(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { + return func(ctx context.Context, req any) (any, error) { info := &ValidationInfo{ service: "InterceptorWithWritePayload", method: "Method", diff --git a/codegen/service/testdata/interceptors/interceptor-with-write-payload_service_interceptors.go.golden b/codegen/service/testdata/interceptors/interceptor-with-write-payload_service_interceptors.go.golden index 2294aa12db..e9b7d863fb 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-write-payload_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-write-payload_service_interceptors.go.golden @@ -3,7 +3,7 @@ // payload is sent to the service. The implementation is responsible for calling // next to complete the request. type ServerInterceptors interface { - Validation(ctx context.Context, info *ValidationInfo, next goa.InterceptorEndpoint) (any, context.Context, error) + Validation(ctx context.Context, info *ValidationInfo, next goa.Endpoint) (any, error) } // Access interfaces for interceptor payloads and results @@ -35,15 +35,8 @@ type ( // WrapMethodEndpoint wraps the Method endpoint with the server-side // interceptors defined in the design. func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { - response, err := endpoint(ctx, request) - return response, ctx, err - } - interceptorEndpoint = wrapMethodvalidation(interceptorEndpoint, i) - return func(ctx context.Context, request any) (any, error) { - response, _, err := interceptorEndpoint(ctx, request) - return response, err - } + endpoint = wrapMethodvalidation(endpoint, i) + return endpoint } // Public accessor methods for Info types diff --git a/codegen/service/testdata/interceptors/interceptor-with-write-result_client_interceptors.go.golden b/codegen/service/testdata/interceptors/interceptor-with-write-result_client_interceptors.go.golden index 91c9e06107..7bf0271866 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-write-result_client_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-write-result_client_interceptors.go.golden @@ -3,19 +3,12 @@ // is sent to the server. The implementation is responsible for calling next to // complete the request. type ClientInterceptors interface { - Caching(ctx context.Context, info *CachingInfo, next goa.InterceptorEndpoint) (any, context.Context, error) + Caching(ctx context.Context, info *CachingInfo, next goa.Endpoint) (any, error) } // WrapMethodClientEndpoint wraps the Method endpoint with the client // interceptors defined in the design. func WrapMethodClientEndpoint(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { - var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { - response, err := endpoint(ctx, request) - return response, ctx, err - } - interceptorEndpoint = wrapClientMethodcaching(interceptorEndpoint, i) - return func(ctx context.Context, request any) (any, error) { - response, _, err := interceptorEndpoint(ctx, request) - return response, err - } + endpoint = wrapClientMethodcaching(endpoint, i) + return endpoint } diff --git a/codegen/service/testdata/interceptors/interceptor-with-write-result_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/interceptor-with-write-result_interceptor_wrappers.go.golden index d8812a3595..89854d6c95 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-write-result_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-write-result_interceptor_wrappers.go.golden @@ -1,8 +1,8 @@ // wrapCachingMethod applies the caching server interceptor to endpoints. -func wrapMethodCaching(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { - return func(ctx context.Context, req any) (any, context.Context, error) { +func wrapMethodCaching(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { + return func(ctx context.Context, req any) (any, error) { info := &CachingInfo{ service: "InterceptorWithWriteResult", method: "Method", @@ -14,8 +14,8 @@ func wrapMethodCaching(endpoint goa.InterceptorEndpoint, i ServerInterceptors) g } // wrapClientCachingMethod applies the caching client interceptor to endpoints. -func wrapClientMethodCaching(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { - return func(ctx context.Context, req any) (any, context.Context, error) { +func wrapClientMethodCaching(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { + return func(ctx context.Context, req any) (any, error) { info := &CachingInfo{ service: "InterceptorWithWriteResult", method: "Method", diff --git a/codegen/service/testdata/interceptors/interceptor-with-write-result_service_interceptors.go.golden b/codegen/service/testdata/interceptors/interceptor-with-write-result_service_interceptors.go.golden index 3e9976658c..161c5e8a3a 100644 --- a/codegen/service/testdata/interceptors/interceptor-with-write-result_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/interceptor-with-write-result_service_interceptors.go.golden @@ -3,7 +3,7 @@ // payload is sent to the service. The implementation is responsible for calling // next to complete the request. type ServerInterceptors interface { - Caching(ctx context.Context, info *CachingInfo, next goa.InterceptorEndpoint) (any, context.Context, error) + Caching(ctx context.Context, info *CachingInfo, next goa.Endpoint) (any, error) } // Access interfaces for interceptor payloads and results @@ -35,15 +35,8 @@ type ( // WrapMethodEndpoint wraps the Method endpoint with the server-side // interceptors defined in the design. func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { - response, err := endpoint(ctx, request) - return response, ctx, err - } - interceptorEndpoint = wrapMethodcaching(interceptorEndpoint, i) - return func(ctx context.Context, request any) (any, error) { - response, _, err := interceptorEndpoint(ctx, request) - return response, err - } + endpoint = wrapMethodcaching(endpoint, i) + return endpoint } // Public accessor methods for Info types diff --git a/codegen/service/testdata/interceptors/multiple-interceptors_client_interceptors.go.golden b/codegen/service/testdata/interceptors/multiple-interceptors_client_interceptors.go.golden index 2afd7972da..e99e5b6ed6 100644 --- a/codegen/service/testdata/interceptors/multiple-interceptors_client_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/multiple-interceptors_client_interceptors.go.golden @@ -3,8 +3,8 @@ // is sent to the server. The implementation is responsible for calling next to // complete the request. type ClientInterceptors interface { - Test2(ctx context.Context, info *Test2Info, next goa.InterceptorEndpoint) (any, context.Context, error) - Test4(ctx context.Context, info *Test4Info, next goa.InterceptorEndpoint) (any, context.Context, error) + Test2(ctx context.Context, info *Test2Info, next goa.Endpoint) (any, error) + Test4(ctx context.Context, info *Test4Info, next goa.Endpoint) (any, error) } // Access interfaces for interceptor payloads and results @@ -30,15 +30,8 @@ type ( // WrapMethodClientEndpoint wraps the Method endpoint with the client // interceptors defined in the design. func WrapMethodClientEndpoint(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { - var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { - response, err := endpoint(ctx, request) - return response, ctx, err - } - interceptorEndpoint = wrapClientMethodtest2(interceptorEndpoint, i) - interceptorEndpoint = wrapClientMethodtest4(interceptorEndpoint, i) - return func(ctx context.Context, request any) (any, error) { - response, _, err := interceptorEndpoint(ctx, request) - return response, err - } + endpoint = wrapClientMethodtest2(endpoint, i) + endpoint = wrapClientMethodtest4(endpoint, i) + return endpoint } diff --git a/codegen/service/testdata/interceptors/multiple-interceptors_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/multiple-interceptors_interceptor_wrappers.go.golden index 49c72914e3..cfabf2905f 100644 --- a/codegen/service/testdata/interceptors/multiple-interceptors_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/multiple-interceptors_interceptor_wrappers.go.golden @@ -1,8 +1,8 @@ // wrapTestMethod applies the test server interceptor to endpoints. -func wrapMethodTest(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { - return func(ctx context.Context, req any) (any, context.Context, error) { +func wrapMethodTest(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { + return func(ctx context.Context, req any) (any, error) { info := &TestInfo{ service: "MultipleInterceptorsService", method: "Method", @@ -14,8 +14,8 @@ func wrapMethodTest(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa. } // wrapTest3Method applies the test3 server interceptor to endpoints. -func wrapMethodTest3(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { - return func(ctx context.Context, req any) (any, context.Context, error) { +func wrapMethodTest3(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { + return func(ctx context.Context, req any) (any, error) { info := &Test3Info{ service: "MultipleInterceptorsService", method: "Method", @@ -27,8 +27,8 @@ func wrapMethodTest3(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa } // wrapClientTest2Method applies the test2 client interceptor to endpoints. -func wrapClientMethodTest2(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { - return func(ctx context.Context, req any) (any, context.Context, error) { +func wrapClientMethodTest2(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { + return func(ctx context.Context, req any) (any, error) { info := &Test2Info{ service: "MultipleInterceptorsService", method: "Method", @@ -40,8 +40,8 @@ func wrapClientMethodTest2(endpoint goa.InterceptorEndpoint, i ClientInterceptor } // wrapClientTest4Method applies the test4 client interceptor to endpoints. -func wrapClientMethodTest4(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { - return func(ctx context.Context, req any) (any, context.Context, error) { +func wrapClientMethodTest4(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { + return func(ctx context.Context, req any) (any, error) { info := &Test4Info{ service: "MultipleInterceptorsService", method: "Method", diff --git a/codegen/service/testdata/interceptors/multiple-interceptors_service_interceptors.go.golden b/codegen/service/testdata/interceptors/multiple-interceptors_service_interceptors.go.golden index 5107c1d032..c69d0297a0 100644 --- a/codegen/service/testdata/interceptors/multiple-interceptors_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/multiple-interceptors_service_interceptors.go.golden @@ -3,8 +3,8 @@ // payload is sent to the service. The implementation is responsible for calling // next to complete the request. type ServerInterceptors interface { - Test(ctx context.Context, info *TestInfo, next goa.InterceptorEndpoint) (any, context.Context, error) - Test3(ctx context.Context, info *Test3Info, next goa.InterceptorEndpoint) (any, context.Context, error) + Test(ctx context.Context, info *TestInfo, next goa.Endpoint) (any, error) + Test3(ctx context.Context, info *Test3Info, next goa.Endpoint) (any, error) } // Access interfaces for interceptor payloads and results @@ -30,15 +30,8 @@ type ( // WrapMethodEndpoint wraps the Method endpoint with the server-side // interceptors defined in the design. func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { - response, err := endpoint(ctx, request) - return response, ctx, err - } - interceptorEndpoint = wrapMethodtest(interceptorEndpoint, i) - interceptorEndpoint = wrapMethodtest3(interceptorEndpoint, i) - return func(ctx context.Context, request any) (any, error) { - response, _, err := interceptorEndpoint(ctx, request) - return response, err - } + endpoint = wrapMethodtest(endpoint, i) + endpoint = wrapMethodtest3(endpoint, i) + return endpoint } diff --git a/codegen/service/testdata/interceptors/single-api-server-interceptor_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/single-api-server-interceptor_interceptor_wrappers.go.golden index e9669889bd..498cc404ca 100644 --- a/codegen/service/testdata/interceptors/single-api-server-interceptor_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/single-api-server-interceptor_interceptor_wrappers.go.golden @@ -1,8 +1,8 @@ // wrapLoggingMethod applies the logging server interceptor to endpoints. -func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { - return func(ctx context.Context, req any) (any, context.Context, error) { +func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { + return func(ctx context.Context, req any) (any, error) { info := &LoggingInfo{ service: "SingleAPIServerInterceptor", method: "Method", @@ -14,8 +14,8 @@ func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) g } // wrapLoggingMethod2 applies the logging server interceptor to endpoints. -func wrapMethod2Logging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { - return func(ctx context.Context, req any) (any, context.Context, error) { +func wrapMethod2Logging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { + return func(ctx context.Context, req any) (any, error) { info := &LoggingInfo{ service: "SingleAPIServerInterceptor", method: "Method2", diff --git a/codegen/service/testdata/interceptors/single-api-server-interceptor_service_interceptors.go.golden b/codegen/service/testdata/interceptors/single-api-server-interceptor_service_interceptors.go.golden index 8c12e6c5b6..9ee4f5833c 100644 --- a/codegen/service/testdata/interceptors/single-api-server-interceptor_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/single-api-server-interceptor_service_interceptors.go.golden @@ -3,7 +3,7 @@ // payload is sent to the service. The implementation is responsible for calling // next to complete the request. type ServerInterceptors interface { - Logging(ctx context.Context, info *LoggingInfo, next goa.InterceptorEndpoint) (any, context.Context, error) + Logging(ctx context.Context, info *LoggingInfo, next goa.Endpoint) (any, error) } // Access interfaces for interceptor payloads and results @@ -21,28 +21,14 @@ type ( // WrapMethodEndpoint wraps the Method endpoint with the server-side // interceptors defined in the design. func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { - response, err := endpoint(ctx, request) - return response, ctx, err - } - interceptorEndpoint = wrapMethodlogging(interceptorEndpoint, i) - return func(ctx context.Context, request any) (any, error) { - response, _, err := interceptorEndpoint(ctx, request) - return response, err - } + endpoint = wrapMethodlogging(endpoint, i) + return endpoint } // WrapMethod2Endpoint wraps the Method2 endpoint with the server-side // interceptors defined in the design. func WrapMethod2Endpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { - response, err := endpoint(ctx, request) - return response, ctx, err - } - interceptorEndpoint = wrapMethod2logging(interceptorEndpoint, i) - return func(ctx context.Context, request any) (any, error) { - response, _, err := interceptorEndpoint(ctx, request) - return response, err - } + endpoint = wrapMethod2logging(endpoint, i) + return endpoint } diff --git a/codegen/service/testdata/interceptors/single-client-interceptor_client_interceptors.go.golden b/codegen/service/testdata/interceptors/single-client-interceptor_client_interceptors.go.golden index 8dc8774a8e..8ff2ec6478 100644 --- a/codegen/service/testdata/interceptors/single-client-interceptor_client_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/single-client-interceptor_client_interceptors.go.golden @@ -3,7 +3,7 @@ // is sent to the server. The implementation is responsible for calling next to // complete the request. type ClientInterceptors interface { - Tracing(ctx context.Context, info *TracingInfo, next goa.InterceptorEndpoint) (any, context.Context, error) + Tracing(ctx context.Context, info *TracingInfo, next goa.Endpoint) (any, error) } // Access interfaces for interceptor payloads and results @@ -21,14 +21,7 @@ type ( // WrapMethodClientEndpoint wraps the Method endpoint with the client // interceptors defined in the design. func WrapMethodClientEndpoint(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { - var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { - response, err := endpoint(ctx, request) - return response, ctx, err - } - interceptorEndpoint = wrapClientMethodtracing(interceptorEndpoint, i) - return func(ctx context.Context, request any) (any, error) { - response, _, err := interceptorEndpoint(ctx, request) - return response, err - } + endpoint = wrapClientMethodtracing(endpoint, i) + return endpoint } diff --git a/codegen/service/testdata/interceptors/single-client-interceptor_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/single-client-interceptor_interceptor_wrappers.go.golden index d4d82c0f89..b72e20a2e2 100644 --- a/codegen/service/testdata/interceptors/single-client-interceptor_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/single-client-interceptor_interceptor_wrappers.go.golden @@ -1,8 +1,8 @@ // wrapClientTracingMethod applies the tracing client interceptor to endpoints. -func wrapClientMethodTracing(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { - return func(ctx context.Context, req any) (any, context.Context, error) { +func wrapClientMethodTracing(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { + return func(ctx context.Context, req any) (any, error) { info := &TracingInfo{ service: "SingleClientInterceptor", method: "Method", diff --git a/codegen/service/testdata/interceptors/single-method-server-interceptor_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/single-method-server-interceptor_interceptor_wrappers.go.golden index 0188370abf..58c5f96d45 100644 --- a/codegen/service/testdata/interceptors/single-method-server-interceptor_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/single-method-server-interceptor_interceptor_wrappers.go.golden @@ -1,8 +1,8 @@ // wrapLoggingMethod applies the logging server interceptor to endpoints. -func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { - return func(ctx context.Context, req any) (any, context.Context, error) { +func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { + return func(ctx context.Context, req any) (any, error) { info := &LoggingInfo{ service: "SingleMethodServerInterceptor", method: "Method", diff --git a/codegen/service/testdata/interceptors/single-method-server-interceptor_service_interceptors.go.golden b/codegen/service/testdata/interceptors/single-method-server-interceptor_service_interceptors.go.golden index 232b876dc8..b533e544c0 100644 --- a/codegen/service/testdata/interceptors/single-method-server-interceptor_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/single-method-server-interceptor_service_interceptors.go.golden @@ -3,7 +3,7 @@ // payload is sent to the service. The implementation is responsible for calling // next to complete the request. type ServerInterceptors interface { - Logging(ctx context.Context, info *LoggingInfo, next goa.InterceptorEndpoint) (any, context.Context, error) + Logging(ctx context.Context, info *LoggingInfo, next goa.Endpoint) (any, error) } // Access interfaces for interceptor payloads and results @@ -21,14 +21,7 @@ type ( // WrapMethodEndpoint wraps the Method endpoint with the server-side // interceptors defined in the design. func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { - response, err := endpoint(ctx, request) - return response, ctx, err - } - interceptorEndpoint = wrapMethodlogging(interceptorEndpoint, i) - return func(ctx context.Context, request any) (any, error) { - response, _, err := interceptorEndpoint(ctx, request) - return response, err - } + endpoint = wrapMethodlogging(endpoint, i) + return endpoint } diff --git a/codegen/service/testdata/interceptors/single-service-server-interceptor_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/single-service-server-interceptor_interceptor_wrappers.go.golden index d662ee70ef..a73b41c30c 100644 --- a/codegen/service/testdata/interceptors/single-service-server-interceptor_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/single-service-server-interceptor_interceptor_wrappers.go.golden @@ -1,8 +1,8 @@ // wrapLoggingMethod applies the logging server interceptor to endpoints. -func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { - return func(ctx context.Context, req any) (any, context.Context, error) { +func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { + return func(ctx context.Context, req any) (any, error) { info := &LoggingInfo{ service: "SingleServerInterceptor", method: "Method", @@ -14,8 +14,8 @@ func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) g } // wrapLoggingMethod2 applies the logging server interceptor to endpoints. -func wrapMethod2Logging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { - return func(ctx context.Context, req any) (any, context.Context, error) { +func wrapMethod2Logging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { + return func(ctx context.Context, req any) (any, error) { info := &LoggingInfo{ service: "SingleServerInterceptor", method: "Method2", diff --git a/codegen/service/testdata/interceptors/single-service-server-interceptor_service_interceptors.go.golden b/codegen/service/testdata/interceptors/single-service-server-interceptor_service_interceptors.go.golden index 8c12e6c5b6..9ee4f5833c 100644 --- a/codegen/service/testdata/interceptors/single-service-server-interceptor_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/single-service-server-interceptor_service_interceptors.go.golden @@ -3,7 +3,7 @@ // payload is sent to the service. The implementation is responsible for calling // next to complete the request. type ServerInterceptors interface { - Logging(ctx context.Context, info *LoggingInfo, next goa.InterceptorEndpoint) (any, context.Context, error) + Logging(ctx context.Context, info *LoggingInfo, next goa.Endpoint) (any, error) } // Access interfaces for interceptor payloads and results @@ -21,28 +21,14 @@ type ( // WrapMethodEndpoint wraps the Method endpoint with the server-side // interceptors defined in the design. func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { - response, err := endpoint(ctx, request) - return response, ctx, err - } - interceptorEndpoint = wrapMethodlogging(interceptorEndpoint, i) - return func(ctx context.Context, request any) (any, error) { - response, _, err := interceptorEndpoint(ctx, request) - return response, err - } + endpoint = wrapMethodlogging(endpoint, i) + return endpoint } // WrapMethod2Endpoint wraps the Method2 endpoint with the server-side // interceptors defined in the design. func WrapMethod2Endpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { - response, err := endpoint(ctx, request) - return response, ctx, err - } - interceptorEndpoint = wrapMethod2logging(interceptorEndpoint, i) - return func(ctx context.Context, request any) (any, error) { - response, _, err := interceptorEndpoint(ctx, request) - return response, err - } + endpoint = wrapMethod2logging(endpoint, i) + return endpoint } diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_client_interceptors.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_client_interceptors.go.golden index 705ce41ebc..3790fd8cde 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_client_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_client_interceptors.go.golden @@ -3,19 +3,12 @@ // is sent to the server. The implementation is responsible for calling next to // complete the request. type ClientInterceptors interface { - Logging(ctx context.Context, info *LoggingInfo, next goa.InterceptorEndpoint) (any, context.Context, error) + Logging(ctx context.Context, info *LoggingInfo, next goa.Endpoint) (any, error) } // WrapMethodClientEndpoint wraps the Method endpoint with the client // interceptors defined in the design. func WrapMethodClientEndpoint(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { - var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { - response, err := endpoint(ctx, request) - return response, ctx, err - } - interceptorEndpoint = wrapClientMethodlogging(interceptorEndpoint, i) - return func(ctx context.Context, request any) (any, error) { - response, _, err := interceptorEndpoint(ctx, request) - return response, err - } + endpoint = wrapClientMethodlogging(endpoint, i) + return endpoint } diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_interceptor_wrappers.go.golden index 2e24294df8..e7c93363c3 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_interceptor_wrappers.go.golden @@ -4,7 +4,7 @@ // MethodServerStream stream. type wrappedMethodServerStream struct { ctx context.Context - recvWithContext func(context.Context) (*MethodStreamingPayload, context.Context, error) + recvWithContext func(context.Context) (*MethodStreamingPayload, error) stream MethodServerStream } @@ -12,88 +12,86 @@ type wrappedMethodServerStream struct { // MethodClientStream stream. type wrappedMethodClientStream struct { ctx context.Context - sendWithContext func(context.Context, *MethodStreamingPayload) (context.Context, error) + sendWithContext func(context.Context, *MethodStreamingPayload) error stream MethodClientStream } // wrapLoggingMethod applies the logging server interceptor to endpoints. -func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { - return func(ctx context.Context, req any) (any, context.Context, error) { +func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { + return func(ctx context.Context, req any) (any, error) { info := &LoggingInfo{ service: "StreamingInterceptorsWithReadPayloadAndReadStreamingPayload", method: "Method", callType: goa.InterceptorUnary, rawPayload: req, } - res, ctx, err := i.Logging(ctx, info, endpoint) + res, err := i.Logging(ctx, info, endpoint) if err != nil { - return res, ctx, err + return res, err } stream := res.(MethodServerStream) return &wrappedMethodServerStream{ ctx: ctx, - recvWithContext: func(ctx context.Context) (*MethodStreamingPayload, context.Context, error) { + recvWithContext: func(ctx context.Context) (*MethodStreamingPayload, error) { info := &LoggingInfo{ service: "StreamingInterceptorsWithReadPayloadAndReadStreamingPayload", method: "Method", callType: goa.InterceptorStreamingRecv, } - res, ctx, err := i.Logging(ctx, info, func(ctx context.Context, _ any) (any, context.Context, error) { + res, err := i.Logging(ctx, info, func(ctx context.Context, _ any) (any, error) { return stream.RecvWithContext(ctx) }) castRes, _ := res.(*MethodStreamingPayload) - return castRes, ctx, err + return castRes, err }, stream: stream, - }, ctx, nil + }, nil } } // wrapClientLoggingMethod applies the logging client interceptor to endpoints. -func wrapClientMethodLogging(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { - return func(ctx context.Context, req any) (any, context.Context, error) { +func wrapClientMethodLogging(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { + return func(ctx context.Context, req any) (any, error) { info := &LoggingInfo{ service: "StreamingInterceptorsWithReadPayloadAndReadStreamingPayload", method: "Method", callType: goa.InterceptorUnary, rawPayload: req, } - res, ctx, err := i.Logging(ctx, info, endpoint) + res, err := i.Logging(ctx, info, endpoint) if err != nil { - return res, ctx, err + return res, err } stream := res.(MethodClientStream) return &wrappedMethodClientStream{ ctx: ctx, - sendWithContext: func(ctx context.Context, req *MethodStreamingPayload) (context.Context, error) { + sendWithContext: func(ctx context.Context, req *MethodStreamingPayload) error { info := &LoggingInfo{ service: "StreamingInterceptorsWithReadPayloadAndReadStreamingPayload", method: "Method", callType: goa.InterceptorStreamingSend, rawPayload: req, } - _, ctx, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, context.Context, error) { + _, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, error) { castReq, _ := req.(*MethodStreamingPayload) - ctx, err = stream.SendWithContext(ctx, castReq) - return nil, ctx, err + return nil, stream.SendWithContext(ctx, castReq) }) - return ctx, err + return err }, stream: stream, - }, ctx, nil + }, nil } } // Recv reads instances of "MethodServerStream" from the stream after executing // the applied interceptor. func (w *wrappedMethodServerStream) Recv() (*MethodStreamingPayload, error) { - res, _, err := w.RecvWithContext(w.ctx) - return res, err + return w.RecvWithContext(w.ctx) } // RecvWithContext reads instances of "MethodServerStream" from the stream // after executing the applied interceptor with context. -func (w *wrappedMethodServerStream) RecvWithContext(ctx context.Context) (*MethodStreamingPayload, context.Context, error) { +func (w *wrappedMethodServerStream) RecvWithContext(ctx context.Context) (*MethodStreamingPayload, error) { if w.recvWithContext == nil { return w.stream.RecvWithContext(ctx) } @@ -108,13 +106,12 @@ func (w *wrappedMethodServerStream) Close() error { // Send streams instances of "MethodClientStream" after executing the applied // interceptor. func (w *wrappedMethodClientStream) Send(v *MethodStreamingPayload) error { - _, err := w.SendWithContext(w.ctx, v) - return err + return w.SendWithContext(w.ctx, v) } // SendWithContext streams instances of "MethodClientStream" after executing // the applied interceptor with context. -func (w *wrappedMethodClientStream) SendWithContext(ctx context.Context, v *MethodStreamingPayload) (context.Context, error) { +func (w *wrappedMethodClientStream) SendWithContext(ctx context.Context, v *MethodStreamingPayload) error { if w.sendWithContext == nil { return w.stream.SendWithContext(ctx, v) } diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_service_interceptors.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_service_interceptors.go.golden index 10fba38801..f9f66d5eac 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload-and-read-streaming-payload_service_interceptors.go.golden @@ -3,7 +3,7 @@ // payload is sent to the service. The implementation is responsible for calling // next to complete the request. type ServerInterceptors interface { - Logging(ctx context.Context, info *LoggingInfo, next goa.InterceptorEndpoint) (any, context.Context, error) + Logging(ctx context.Context, info *LoggingInfo, next goa.Endpoint) (any, error) } // Access interfaces for interceptor payloads and results @@ -45,15 +45,8 @@ type ( // WrapMethodEndpoint wraps the Method endpoint with the server-side // interceptors defined in the design. func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { - response, err := endpoint(ctx, request) - return response, ctx, err - } - interceptorEndpoint = wrapMethodlogging(interceptorEndpoint, i) - return func(ctx context.Context, request any) (any, error) { - response, _, err := interceptorEndpoint(ctx, request) - return response, err - } + endpoint = wrapMethodlogging(endpoint, i) + return endpoint } // Public accessor methods for Info types diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_interceptor_wrappers.go.golden index da06efe990..b4f94826cd 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_interceptor_wrappers.go.golden @@ -1,8 +1,8 @@ // wrapLoggingMethod applies the logging server interceptor to endpoints. -func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { - return func(ctx context.Context, req any) (any, context.Context, error) { +func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { + return func(ctx context.Context, req any) (any, error) { info := &LoggingInfo{ service: "StreamingInterceptorsWithReadPayload", method: "Method", diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_service_interceptors.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_service_interceptors.go.golden index e4d3b67a31..aeced16360 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-payload_service_interceptors.go.golden @@ -3,7 +3,7 @@ // payload is sent to the service. The implementation is responsible for calling // next to complete the request. type ServerInterceptors interface { - Logging(ctx context.Context, info *LoggingInfo, next goa.InterceptorEndpoint) (any, context.Context, error) + Logging(ctx context.Context, info *LoggingInfo, next goa.Endpoint) (any, error) } // Access interfaces for interceptor payloads and results @@ -35,15 +35,8 @@ type ( // WrapMethodEndpoint wraps the Method endpoint with the server-side // interceptors defined in the design. func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { - response, err := endpoint(ctx, request) - return response, ctx, err - } - interceptorEndpoint = wrapMethodlogging(interceptorEndpoint, i) - return func(ctx context.Context, request any) (any, error) { - response, _, err := interceptorEndpoint(ctx, request) - return response, err - } + endpoint = wrapMethodlogging(endpoint, i) + return endpoint } // Public accessor methods for Info types diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_interceptor_wrappers.go.golden index 38fc94186c..b6e8f62cc2 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_interceptor_wrappers.go.golden @@ -1,8 +1,8 @@ // wrapLoggingMethod applies the logging server interceptor to endpoints. -func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { - return func(ctx context.Context, req any) (any, context.Context, error) { +func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { + return func(ctx context.Context, req any) (any, error) { info := &LoggingInfo{ service: "StreamingInterceptorsWithReadResult", method: "Method", diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_service_interceptors.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_service_interceptors.go.golden index fbc576bf69..3bbb27f3db 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-result_service_interceptors.go.golden @@ -3,7 +3,7 @@ // payload is sent to the service. The implementation is responsible for calling // next to complete the request. type ServerInterceptors interface { - Logging(ctx context.Context, info *LoggingInfo, next goa.InterceptorEndpoint) (any, context.Context, error) + Logging(ctx context.Context, info *LoggingInfo, next goa.Endpoint) (any, error) } // Access interfaces for interceptor payloads and results @@ -35,15 +35,8 @@ type ( // WrapMethodEndpoint wraps the Method endpoint with the server-side // interceptors defined in the design. func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { - response, err := endpoint(ctx, request) - return response, ctx, err - } - interceptorEndpoint = wrapMethodlogging(interceptorEndpoint, i) - return func(ctx context.Context, request any) (any, error) { - response, _, err := interceptorEndpoint(ctx, request) - return response, err - } + endpoint = wrapMethodlogging(endpoint, i) + return endpoint } // Public accessor methods for Info types diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_client_interceptors.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_client_interceptors.go.golden index 705ce41ebc..3790fd8cde 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_client_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_client_interceptors.go.golden @@ -3,19 +3,12 @@ // is sent to the server. The implementation is responsible for calling next to // complete the request. type ClientInterceptors interface { - Logging(ctx context.Context, info *LoggingInfo, next goa.InterceptorEndpoint) (any, context.Context, error) + Logging(ctx context.Context, info *LoggingInfo, next goa.Endpoint) (any, error) } // WrapMethodClientEndpoint wraps the Method endpoint with the client // interceptors defined in the design. func WrapMethodClientEndpoint(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { - var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { - response, err := endpoint(ctx, request) - return response, ctx, err - } - interceptorEndpoint = wrapClientMethodlogging(interceptorEndpoint, i) - return func(ctx context.Context, request any) (any, error) { - response, _, err := interceptorEndpoint(ctx, request) - return response, err - } + endpoint = wrapClientMethodlogging(endpoint, i) + return endpoint } diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_interceptor_wrappers.go.golden index d23e8d68d3..61210965f6 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_interceptor_wrappers.go.golden @@ -4,7 +4,7 @@ // MethodServerStream stream. type wrappedMethodServerStream struct { ctx context.Context - sendWithContext func(context.Context, *MethodResult) (context.Context, error) + sendWithContext func(context.Context, *MethodResult) error stream MethodServerStream } @@ -12,76 +12,74 @@ type wrappedMethodServerStream struct { // MethodClientStream stream. type wrappedMethodClientStream struct { ctx context.Context - recvWithContext func(context.Context) (*MethodResult, context.Context, error) + recvWithContext func(context.Context) (*MethodResult, error) stream MethodClientStream } // wrapLoggingMethod applies the logging server interceptor to endpoints. -func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { - return func(ctx context.Context, req any) (any, context.Context, error) { - res, ctx, err := endpoint(ctx, req) +func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { + return func(ctx context.Context, req any) (any, error) { + res, err := endpoint(ctx, req) if err != nil { - return res, ctx, err + return res, err } stream := res.(MethodServerStream) return &wrappedMethodServerStream{ ctx: ctx, - sendWithContext: func(ctx context.Context, req *MethodResult) (context.Context, error) { + sendWithContext: func(ctx context.Context, req *MethodResult) error { info := &LoggingInfo{ service: "StreamingInterceptorsWithReadStreamingResult", method: "Method", callType: goa.InterceptorStreamingSend, rawPayload: req, } - _, ctx, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, context.Context, error) { + _, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, error) { castReq, _ := req.(*MethodResult) - ctx, err := stream.SendWithContext(ctx, castReq) - return nil, ctx, err + return nil, stream.SendWithContext(ctx, castReq) }) - return ctx, err + return err }, stream: stream, - }, ctx, nil + }, nil } } // wrapClientLoggingMethod applies the logging client interceptor to endpoints. -func wrapClientMethodLogging(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { - return func(ctx context.Context, req any) (any, context.Context, error) { - res, ctx, err := endpoint(ctx, req) +func wrapClientMethodLogging(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { + return func(ctx context.Context, req any) (any, error) { + res, err := endpoint(ctx, req) if err != nil { - return res, ctx, err + return res, err } stream := res.(MethodClientStream) return &wrappedMethodClientStream{ ctx: ctx, - recvWithContext: func(ctx context.Context) (*MethodResult, context.Context, error) { + recvWithContext: func(ctx context.Context) (*MethodResult, error) { info := &LoggingInfo{ service: "StreamingInterceptorsWithReadStreamingResult", method: "Method", callType: goa.InterceptorStreamingRecv, } - res, ctx, err := i.Logging(ctx, info, func(ctx context.Context, _ any) (any, context.Context, error) { + res, err := i.Logging(ctx, info, func(ctx context.Context, _ any) (any, error) { return stream.RecvWithContext(ctx) }) castRes, _ := res.(*MethodResult) - return castRes, ctx, err + return castRes, err }, stream: stream, - }, ctx, nil + }, nil } } // Send streams instances of "MethodServerStream" after executing the applied // interceptor. func (w *wrappedMethodServerStream) Send(v *MethodResult) error { - _, err := w.SendWithContext(w.ctx, v) - return err + return w.SendWithContext(w.ctx, v) } // SendWithContext streams instances of "MethodServerStream" after executing // the applied interceptor with context. -func (w *wrappedMethodServerStream) SendWithContext(ctx context.Context, v *MethodResult) (context.Context, error) { +func (w *wrappedMethodServerStream) SendWithContext(ctx context.Context, v *MethodResult) error { if w.sendWithContext == nil { return w.stream.SendWithContext(ctx, v) } @@ -96,13 +94,12 @@ func (w *wrappedMethodServerStream) Close() error { // Recv reads instances of "MethodClientStream" from the stream after executing // the applied interceptor. func (w *wrappedMethodClientStream) Recv() (*MethodResult, error) { - res, _, err := w.RecvWithContext(w.ctx) - return res, err + return w.RecvWithContext(w.ctx) } // RecvWithContext reads instances of "MethodClientStream" from the stream // after executing the applied interceptor with context. -func (w *wrappedMethodClientStream) RecvWithContext(ctx context.Context) (*MethodResult, context.Context, error) { +func (w *wrappedMethodClientStream) RecvWithContext(ctx context.Context) (*MethodResult, error) { if w.recvWithContext == nil { return w.stream.RecvWithContext(ctx) } diff --git a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_service_interceptors.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_service_interceptors.go.golden index f0eb9871d5..c074c15cca 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors-with-read-streaming-result_service_interceptors.go.golden @@ -3,7 +3,7 @@ // payload is sent to the service. The implementation is responsible for calling // next to complete the request. type ServerInterceptors interface { - Logging(ctx context.Context, info *LoggingInfo, next goa.InterceptorEndpoint) (any, context.Context, error) + Logging(ctx context.Context, info *LoggingInfo, next goa.Endpoint) (any, error) } // Access interfaces for interceptor payloads and results @@ -35,15 +35,8 @@ type ( // WrapMethodEndpoint wraps the Method endpoint with the server-side // interceptors defined in the design. func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { - response, err := endpoint(ctx, request) - return response, ctx, err - } - interceptorEndpoint = wrapMethodlogging(interceptorEndpoint, i) - return func(ctx context.Context, request any) (any, error) { - response, _, err := interceptorEndpoint(ctx, request) - return response, err - } + endpoint = wrapMethodlogging(endpoint, i) + return endpoint } // Public accessor methods for Info types diff --git a/codegen/service/testdata/interceptors/streaming-interceptors_client_interceptors.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors_client_interceptors.go.golden index 705ce41ebc..3790fd8cde 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors_client_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors_client_interceptors.go.golden @@ -3,19 +3,12 @@ // is sent to the server. The implementation is responsible for calling next to // complete the request. type ClientInterceptors interface { - Logging(ctx context.Context, info *LoggingInfo, next goa.InterceptorEndpoint) (any, context.Context, error) + Logging(ctx context.Context, info *LoggingInfo, next goa.Endpoint) (any, error) } // WrapMethodClientEndpoint wraps the Method endpoint with the client // interceptors defined in the design. func WrapMethodClientEndpoint(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { - var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { - response, err := endpoint(ctx, request) - return response, ctx, err - } - interceptorEndpoint = wrapClientMethodlogging(interceptorEndpoint, i) - return func(ctx context.Context, request any) (any, error) { - response, _, err := interceptorEndpoint(ctx, request) - return response, err - } + endpoint = wrapClientMethodlogging(endpoint, i) + return endpoint } diff --git a/codegen/service/testdata/interceptors/streaming-interceptors_interceptor_wrappers.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors_interceptor_wrappers.go.golden index 3c9626f829..1e5bd18489 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors_interceptor_wrappers.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors_interceptor_wrappers.go.golden @@ -4,8 +4,8 @@ // MethodServerStream stream. type wrappedMethodServerStream struct { ctx context.Context - sendWithContext func(context.Context, *MethodResult) (context.Context, error) - recvWithContext func(context.Context) (*MethodStreamingPayload, context.Context, error) + sendWithContext func(context.Context, *MethodResult) error + recvWithContext func(context.Context) (*MethodStreamingPayload, error) stream MethodServerStream } @@ -13,103 +13,100 @@ type wrappedMethodServerStream struct { // MethodClientStream stream. type wrappedMethodClientStream struct { ctx context.Context - sendWithContext func(context.Context, *MethodStreamingPayload) (context.Context, error) - recvWithContext func(context.Context) (*MethodResult, context.Context, error) + sendWithContext func(context.Context, *MethodStreamingPayload) error + recvWithContext func(context.Context) (*MethodResult, error) stream MethodClientStream } // wrapLoggingMethod applies the logging server interceptor to endpoints. -func wrapMethodLogging(endpoint goa.InterceptorEndpoint, i ServerInterceptors) goa.InterceptorEndpoint { - return func(ctx context.Context, req any) (any, context.Context, error) { - res, ctx, err := endpoint(ctx, req) +func wrapMethodLogging(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { + return func(ctx context.Context, req any) (any, error) { + res, err := endpoint(ctx, req) if err != nil { - return res, ctx, err + return res, err } stream := res.(MethodServerStream) return &wrappedMethodServerStream{ ctx: ctx, - sendWithContext: func(ctx context.Context, req *MethodResult) (context.Context, error) { + sendWithContext: func(ctx context.Context, req *MethodResult) error { info := &LoggingInfo{ service: "StreamingInterceptors", method: "Method", callType: goa.InterceptorStreamingSend, rawPayload: req, } - _, ctx, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, context.Context, error) { + _, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, error) { castReq, _ := req.(*MethodResult) - ctx, err := stream.SendWithContext(ctx, castReq) - return nil, ctx, err + return nil, stream.SendWithContext(ctx, castReq) }) - return ctx, err + return err }, - recvWithContext: func(ctx context.Context) (*MethodStreamingPayload, context.Context, error) { + recvWithContext: func(ctx context.Context) (*MethodStreamingPayload, error) { info := &LoggingInfo{ service: "StreamingInterceptors", method: "Method", callType: goa.InterceptorStreamingRecv, } - res, ctx, err := i.Logging(ctx, info, func(ctx context.Context, _ any) (any, context.Context, error) { + res, err := i.Logging(ctx, info, func(ctx context.Context, _ any) (any, error) { return stream.RecvWithContext(ctx) }) castRes, _ := res.(*MethodStreamingPayload) - return castRes, ctx, err + return castRes, err }, stream: stream, - }, ctx, nil + }, nil } } // wrapClientLoggingMethod applies the logging client interceptor to endpoints. -func wrapClientMethodLogging(endpoint goa.InterceptorEndpoint, i ClientInterceptors) goa.InterceptorEndpoint { - return func(ctx context.Context, req any) (any, context.Context, error) { - res, ctx, err := endpoint(ctx, req) +func wrapClientMethodLogging(endpoint goa.Endpoint, i ClientInterceptors) goa.Endpoint { + return func(ctx context.Context, req any) (any, error) { + res, err := endpoint(ctx, req) if err != nil { - return res, ctx, err + return res, err } stream := res.(MethodClientStream) return &wrappedMethodClientStream{ ctx: ctx, - sendWithContext: func(ctx context.Context, req *MethodStreamingPayload) (context.Context, error) { + sendWithContext: func(ctx context.Context, req *MethodStreamingPayload) error { info := &LoggingInfo{ service: "StreamingInterceptors", method: "Method", callType: goa.InterceptorStreamingSend, rawPayload: req, } - _, ctx, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, context.Context, error) { + _, err := i.Logging(ctx, info, func(ctx context.Context, req any) (any, error) { castReq, _ := req.(*MethodStreamingPayload) - ctx, err = stream.SendWithContext(ctx, castReq) - return nil, ctx, err + return nil, stream.SendWithContext(ctx, castReq) }) - return ctx, err + return err }, - recvWithContext: func(ctx context.Context) (*MethodResult, context.Context, error) { + recvWithContext: func(ctx context.Context) (*MethodResult, error) { info := &LoggingInfo{ service: "StreamingInterceptors", method: "Method", callType: goa.InterceptorStreamingRecv, } - res, ctx, err := i.Logging(ctx, info, func(ctx context.Context, _ any) (any, context.Context, error) { + res, err := i.Logging(ctx, info, func(ctx context.Context, _ any) (any, error) { return stream.RecvWithContext(ctx) }) castRes, _ := res.(*MethodResult) - return castRes, ctx, err + return castRes, err }, stream: stream, - }, ctx, nil + }, nil } } // Send streams instances of "MethodServerStream" after executing the applied // interceptor. func (w *wrappedMethodServerStream) Send(v *MethodResult) error { - _, err := w.SendWithContext(w.ctx, v) - return err + return w.SendWithContext(w.ctx, v) } // SendWithContext streams instances of "MethodServerStream" after executing // the applied interceptor with context. -func (w *wrappedMethodServerStream) SendWithContext(ctx context.Context, v *MethodResult) (context.Context, error) { +func (w *wrappedMethodServerStream) SendWithContext(ctx context.Context, v *MethodResult) error { if w.sendWithContext == nil { return w.stream.SendWithContext(ctx, v) } @@ -119,13 +116,12 @@ func (w *wrappedMethodServerStream) SendWithContext(ctx context.Context, v *Meth // Recv reads instances of "MethodServerStream" from the stream after executing // the applied interceptor. func (w *wrappedMethodServerStream) Recv() (*MethodStreamingPayload, error) { - res, _, err := w.RecvWithContext(w.ctx) - return res, err + return w.RecvWithContext(w.ctx) } // RecvWithContext reads instances of "MethodServerStream" from the stream // after executing the applied interceptor with context. -func (w *wrappedMethodServerStream) RecvWithContext(ctx context.Context) (*MethodStreamingPayload, context.Context, error) { +func (w *wrappedMethodServerStream) RecvWithContext(ctx context.Context) (*MethodStreamingPayload, error) { if w.recvWithContext == nil { return w.stream.RecvWithContext(ctx) } @@ -140,13 +136,12 @@ func (w *wrappedMethodServerStream) Close() error { // Send streams instances of "MethodClientStream" after executing the applied // interceptor. func (w *wrappedMethodClientStream) Send(v *MethodStreamingPayload) error { - _, err := w.SendWithContext(w.ctx, v) - return err + return w.SendWithContext(w.ctx, v) } // SendWithContext streams instances of "MethodClientStream" after executing // the applied interceptor with context. -func (w *wrappedMethodClientStream) SendWithContext(ctx context.Context, v *MethodStreamingPayload) (context.Context, error) { +func (w *wrappedMethodClientStream) SendWithContext(ctx context.Context, v *MethodStreamingPayload) error { if w.sendWithContext == nil { return w.stream.SendWithContext(ctx, v) } @@ -156,13 +151,12 @@ func (w *wrappedMethodClientStream) SendWithContext(ctx context.Context, v *Meth // Recv reads instances of "MethodClientStream" from the stream after executing // the applied interceptor. func (w *wrappedMethodClientStream) Recv() (*MethodResult, error) { - res, _, err := w.RecvWithContext(w.ctx) - return res, err + return w.RecvWithContext(w.ctx) } // RecvWithContext reads instances of "MethodClientStream" from the stream // after executing the applied interceptor with context. -func (w *wrappedMethodClientStream) RecvWithContext(ctx context.Context) (*MethodResult, context.Context, error) { +func (w *wrappedMethodClientStream) RecvWithContext(ctx context.Context) (*MethodResult, error) { if w.recvWithContext == nil { return w.stream.RecvWithContext(ctx) } diff --git a/codegen/service/testdata/interceptors/streaming-interceptors_service_interceptors.go.golden b/codegen/service/testdata/interceptors/streaming-interceptors_service_interceptors.go.golden index 8eae956f38..3424b0a6ba 100644 --- a/codegen/service/testdata/interceptors/streaming-interceptors_service_interceptors.go.golden +++ b/codegen/service/testdata/interceptors/streaming-interceptors_service_interceptors.go.golden @@ -3,7 +3,7 @@ // payload is sent to the service. The implementation is responsible for calling // next to complete the request. type ServerInterceptors interface { - Logging(ctx context.Context, info *LoggingInfo, next goa.InterceptorEndpoint) (any, context.Context, error) + Logging(ctx context.Context, info *LoggingInfo, next goa.Endpoint) (any, error) } // Access interfaces for interceptor payloads and results @@ -47,15 +47,8 @@ type ( // WrapMethodEndpoint wraps the Method endpoint with the server-side // interceptors defined in the design. func WrapMethodEndpoint(endpoint goa.Endpoint, i ServerInterceptors) goa.Endpoint { - var interceptorEndpoint goa.InterceptorEndpoint = func(ctx context.Context, request any) (any, context.Context, error) { - response, err := endpoint(ctx, request) - return response, ctx, err - } - interceptorEndpoint = wrapMethodlogging(interceptorEndpoint, i) - return func(ctx context.Context, request any) (any, error) { - response, _, err := interceptorEndpoint(ctx, request) - return response, err - } + endpoint = wrapMethodlogging(endpoint, i) + return endpoint } // Public accessor methods for Info types diff --git a/codegen/service/testdata/service_code.go b/codegen/service/testdata/service_code.go index ce22cd38d1..b2d92cdf43 100644 --- a/codegen/service/testdata/service_code.go +++ b/codegen/service/testdata/service_code.go @@ -1815,7 +1815,7 @@ type StreamingResultMethodServerStream interface { // Send streams instances of "AResult". Send(*AResult) error // SendWithContext streams instances of "AResult" with context. - SendWithContext(context.Context, *AResult) (context.Context, error) + SendWithContext(context.Context, *AResult) error // Close closes the stream. Close() error } @@ -1826,7 +1826,7 @@ type StreamingResultMethodClientStream interface { // Recv reads instances of "AResult" from the stream. Recv() (*AResult, error) // RecvWithContext reads instances of "AResult" from the stream with context. - RecvWithContext(context.Context) (*AResult, context.Context, error) + RecvWithContext(context.Context) (*AResult, error) } // APayload is the payload type of the StreamingResultService service @@ -1882,7 +1882,7 @@ type StreamingResultWithViewsMethodServerStream interface { // Send streams instances of "MultipleViews". Send(*MultipleViews) error // SendWithContext streams instances of "MultipleViews" with context. - SendWithContext(context.Context, *MultipleViews) (context.Context, error) + SendWithContext(context.Context, *MultipleViews) error // Close closes the stream. Close() error // SetView sets the view used to render the result before streaming. @@ -1896,7 +1896,7 @@ type StreamingResultWithViewsMethodClientStream interface { Recv() (*MultipleViews, error) // RecvWithContext reads instances of "MultipleViews" from the stream with // context. - RecvWithContext(context.Context) (*MultipleViews, context.Context, error) + RecvWithContext(context.Context) (*MultipleViews, error) } // MultipleViews is the result type of the StreamingResultWithViewsService @@ -2003,7 +2003,7 @@ type StreamingResultWithExplicitViewMethodServerStream interface { // Send streams instances of "MultipleViews". Send(*MultipleViews) error // SendWithContext streams instances of "MultipleViews" with context. - SendWithContext(context.Context, *MultipleViews) (context.Context, error) + SendWithContext(context.Context, *MultipleViews) error // Close closes the stream. Close() error } @@ -2015,7 +2015,7 @@ type StreamingResultWithExplicitViewMethodClientStream interface { Recv() (*MultipleViews, error) // RecvWithContext reads instances of "MultipleViews" from the stream with // context. - RecvWithContext(context.Context) (*MultipleViews, context.Context, error) + RecvWithContext(context.Context) (*MultipleViews, error) } // MultipleViews is the result type of the @@ -2122,7 +2122,7 @@ type StreamingResultNoPayloadMethodServerStream interface { // Send streams instances of "AResult". Send(*AResult) error // SendWithContext streams instances of "AResult" with context. - SendWithContext(context.Context, *AResult) (context.Context, error) + SendWithContext(context.Context, *AResult) error // Close closes the stream. Close() error } @@ -2133,7 +2133,7 @@ type StreamingResultNoPayloadMethodClientStream interface { // Recv reads instances of "AResult" from the stream. Recv() (*AResult, error) // RecvWithContext reads instances of "AResult" from the stream with context. - RecvWithContext(context.Context) (*AResult, context.Context, error) + RecvWithContext(context.Context) (*AResult, error) } // AResult is the result type of the StreamingResultNoPayloadService service @@ -2177,11 +2177,11 @@ type StreamingPayloadMethodServerStream interface { SendAndClose(*AResult) error // SendAndCloseWithContext streams instances of "AResult" and closes the stream // with context. - SendAndCloseWithContext(context.Context, *AResult) (context.Context, error) + SendAndCloseWithContext(context.Context, *AResult) error // Recv reads instances of "APayload" from the stream. Recv() (*APayload, error) // RecvWithContext reads instances of "APayload" from the stream with context. - RecvWithContext(context.Context) (*APayload, context.Context, error) + RecvWithContext(context.Context) (*APayload, error) } // StreamingPayloadMethodClientStream is the interface a @@ -2190,13 +2190,13 @@ type StreamingPayloadMethodClientStream interface { // Send streams instances of "APayload". Send(*APayload) error // SendWithContext streams instances of "APayload" with context. - SendWithContext(context.Context, *APayload) (context.Context, error) + SendWithContext(context.Context, *APayload) error // CloseAndRecv stops sending messages to the stream and reads instances of // "AResult" from the stream. CloseAndRecv() (*AResult, error) // CloseAndRecvWithContext stops sending messages to the stream and reads // instances of "AResult" from the stream with context. - CloseAndRecvWithContext(context.Context) (*AResult, context.Context, error) + CloseAndRecvWithContext(context.Context) (*AResult, error) } // APayload is the streaming payload type of the StreamingPayloadService @@ -2270,11 +2270,11 @@ type StreamingPayloadNoPayloadMethodServerStream interface { SendAndClose(string) error // SendAndCloseWithContext streams instances of "string" and closes the stream // with context. - SendAndCloseWithContext(context.Context, string) (context.Context, error) + SendAndCloseWithContext(context.Context, string) error // Recv reads instances of "any" from the stream. Recv() (any, error) // RecvWithContext reads instances of "any" from the stream with context. - RecvWithContext(context.Context) (any, context.Context, error) + RecvWithContext(context.Context) (any, error) } // StreamingPayloadNoPayloadMethodClientStream is the interface a @@ -2283,13 +2283,13 @@ type StreamingPayloadNoPayloadMethodClientStream interface { // Send streams instances of "any". Send(any) error // SendWithContext streams instances of "any" with context. - SendWithContext(context.Context, any) (context.Context, error) + SendWithContext(context.Context, any) error // CloseAndRecv stops sending messages to the stream and reads instances of // "string" from the stream. CloseAndRecv() (string, error) // CloseAndRecvWithContext stops sending messages to the stream and reads // instances of "string" from the stream with context. - CloseAndRecvWithContext(context.Context) (string, context.Context, error) + CloseAndRecvWithContext(context.Context) (string, error) } ` @@ -2322,7 +2322,7 @@ type StreamingPayloadNoResultMethodServerStream interface { // Recv reads instances of "int" from the stream. Recv() (int, error) // RecvWithContext reads instances of "int" from the stream with context. - RecvWithContext(context.Context) (int, context.Context, error) + RecvWithContext(context.Context) (int, error) // Close closes the stream. Close() error } @@ -2333,7 +2333,7 @@ type StreamingPayloadNoResultMethodClientStream interface { // Send streams instances of "int". Send(int) error // SendWithContext streams instances of "int" with context. - SendWithContext(context.Context, int) (context.Context, error) + SendWithContext(context.Context, int) error // Close closes the stream. Close() error } @@ -2373,11 +2373,11 @@ type StreamingPayloadResultWithViewsMethodServerStream interface { SendAndClose(*MultipleViews) error // SendAndCloseWithContext streams instances of "MultipleViews" and closes the // stream with context. - SendAndCloseWithContext(context.Context, *MultipleViews) (context.Context, error) + SendAndCloseWithContext(context.Context, *MultipleViews) error // Recv reads instances of "APayload" from the stream. Recv() (*APayload, error) // RecvWithContext reads instances of "APayload" from the stream with context. - RecvWithContext(context.Context) (*APayload, context.Context, error) + RecvWithContext(context.Context) (*APayload, error) // SetView sets the view used to render the result before streaming. SetView(view string) } @@ -2388,13 +2388,13 @@ type StreamingPayloadResultWithViewsMethodClientStream interface { // Send streams instances of "APayload". Send(*APayload) error // SendWithContext streams instances of "APayload" with context. - SendWithContext(context.Context, *APayload) (context.Context, error) + SendWithContext(context.Context, *APayload) error // CloseAndRecv stops sending messages to the stream and reads instances of // "MultipleViews" from the stream. CloseAndRecv() (*MultipleViews, error) // CloseAndRecvWithContext stops sending messages to the stream and reads // instances of "MultipleViews" from the stream with context. - CloseAndRecvWithContext(context.Context) (*MultipleViews, context.Context, error) + CloseAndRecvWithContext(context.Context) (*MultipleViews, error) } // APayload is the streaming payload type of the @@ -2516,11 +2516,11 @@ type StreamingPayloadResultWithExplicitViewMethodServerStream interface { SendAndClose(*MultipleViews) error // SendAndCloseWithContext streams instances of "MultipleViews" and closes the // stream with context. - SendAndCloseWithContext(context.Context, *MultipleViews) (context.Context, error) + SendAndCloseWithContext(context.Context, *MultipleViews) error // Recv reads instances of "[]string" from the stream. Recv() ([]string, error) // RecvWithContext reads instances of "[]string" from the stream with context. - RecvWithContext(context.Context) ([]string, context.Context, error) + RecvWithContext(context.Context) ([]string, error) } // StreamingPayloadResultWithExplicitViewMethodClientStream is the interface a @@ -2530,13 +2530,13 @@ type StreamingPayloadResultWithExplicitViewMethodClientStream interface { // Send streams instances of "[]string". Send([]string) error // SendWithContext streams instances of "[]string" with context. - SendWithContext(context.Context, []string) (context.Context, error) + SendWithContext(context.Context, []string) error // CloseAndRecv stops sending messages to the stream and reads instances of // "MultipleViews" from the stream. CloseAndRecv() (*MultipleViews, error) // CloseAndRecvWithContext stops sending messages to the stream and reads // instances of "MultipleViews" from the stream with context. - CloseAndRecvWithContext(context.Context) (*MultipleViews, context.Context, error) + CloseAndRecvWithContext(context.Context) (*MultipleViews, error) } // MultipleViews is the result type of the @@ -2643,11 +2643,11 @@ type BidirectionalStreamingMethodServerStream interface { // Send streams instances of "AResult". Send(*AResult) error // SendWithContext streams instances of "AResult" with context. - SendWithContext(context.Context, *AResult) (context.Context, error) + SendWithContext(context.Context, *AResult) error // Recv reads instances of "APayload" from the stream. Recv() (*APayload, error) // RecvWithContext reads instances of "APayload" from the stream with context. - RecvWithContext(context.Context) (*APayload, context.Context, error) + RecvWithContext(context.Context) (*APayload, error) // Close closes the stream. Close() error } @@ -2658,11 +2658,11 @@ type BidirectionalStreamingMethodClientStream interface { // Send streams instances of "APayload". Send(*APayload) error // SendWithContext streams instances of "APayload" with context. - SendWithContext(context.Context, *APayload) (context.Context, error) + SendWithContext(context.Context, *APayload) error // Recv reads instances of "AResult" from the stream. Recv() (*AResult, error) // RecvWithContext reads instances of "AResult" from the stream with context. - RecvWithContext(context.Context) (*AResult, context.Context, error) + RecvWithContext(context.Context) (*AResult, error) // Close closes the stream. Close() error } @@ -2738,11 +2738,11 @@ type BidirectionalStreamingNoPayloadMethodServerStream interface { // Send streams instances of "int". Send(int) error // SendWithContext streams instances of "int" with context. - SendWithContext(context.Context, int) (context.Context, error) + SendWithContext(context.Context, int) error // Recv reads instances of "string" from the stream. Recv() (string, error) // RecvWithContext reads instances of "string" from the stream with context. - RecvWithContext(context.Context) (string, context.Context, error) + RecvWithContext(context.Context) (string, error) // Close closes the stream. Close() error } @@ -2753,11 +2753,11 @@ type BidirectionalStreamingNoPayloadMethodClientStream interface { // Send streams instances of "string". Send(string) error // SendWithContext streams instances of "string" with context. - SendWithContext(context.Context, string) (context.Context, error) + SendWithContext(context.Context, string) error // Recv reads instances of "int" from the stream. Recv() (int, error) // RecvWithContext reads instances of "int" from the stream with context. - RecvWithContext(context.Context) (int, context.Context, error) + RecvWithContext(context.Context) (int, error) // Close closes the stream. Close() error } @@ -2798,11 +2798,11 @@ type BidirectionalStreamingResultWithViewsMethodServerStream interface { // Send streams instances of "MultipleViews". Send(*MultipleViews) error // SendWithContext streams instances of "MultipleViews" with context. - SendWithContext(context.Context, *MultipleViews) (context.Context, error) + SendWithContext(context.Context, *MultipleViews) error // Recv reads instances of "APayload" from the stream. Recv() (*APayload, error) // RecvWithContext reads instances of "APayload" from the stream with context. - RecvWithContext(context.Context) (*APayload, context.Context, error) + RecvWithContext(context.Context) (*APayload, error) // Close closes the stream. Close() error // SetView sets the view used to render the result before streaming. @@ -2816,12 +2816,12 @@ type BidirectionalStreamingResultWithViewsMethodClientStream interface { // Send streams instances of "APayload". Send(*APayload) error // SendWithContext streams instances of "APayload" with context. - SendWithContext(context.Context, *APayload) (context.Context, error) + SendWithContext(context.Context, *APayload) error // Recv reads instances of "MultipleViews" from the stream. Recv() (*MultipleViews, error) // RecvWithContext reads instances of "MultipleViews" from the stream with // context. - RecvWithContext(context.Context) (*MultipleViews, context.Context, error) + RecvWithContext(context.Context) (*MultipleViews, error) // Close closes the stream. Close() error } @@ -2944,11 +2944,11 @@ type BidirectionalStreamingResultWithExplicitViewMethodServerStream interface { // Send streams instances of "MultipleViews". Send(*MultipleViews) error // SendWithContext streams instances of "MultipleViews" with context. - SendWithContext(context.Context, *MultipleViews) (context.Context, error) + SendWithContext(context.Context, *MultipleViews) error // Recv reads instances of "[][]byte" from the stream. Recv() ([][]byte, error) // RecvWithContext reads instances of "[][]byte" from the stream with context. - RecvWithContext(context.Context) ([][]byte, context.Context, error) + RecvWithContext(context.Context) ([][]byte, error) // Close closes the stream. Close() error } @@ -2960,12 +2960,12 @@ type BidirectionalStreamingResultWithExplicitViewMethodClientStream interface { // Send streams instances of "[][]byte". Send([][]byte) error // SendWithContext streams instances of "[][]byte" with context. - SendWithContext(context.Context, [][]byte) (context.Context, error) + SendWithContext(context.Context, [][]byte) error // Recv reads instances of "MultipleViews" from the stream. Recv() (*MultipleViews, error) // RecvWithContext reads instances of "MultipleViews" from the stream with // context. - RecvWithContext(context.Context) (*MultipleViews, context.Context, error) + RecvWithContext(context.Context) (*MultipleViews, error) // Close closes the stream. Close() error } diff --git a/grpc/codegen/templates/stream_recv.go.tpl b/grpc/codegen/templates/stream_recv.go.tpl index 89b1c0cc81..93215633a5 100644 --- a/grpc/codegen/templates/stream_recv.go.tpl +++ b/grpc/codegen/templates/stream_recv.go.tpl @@ -23,7 +23,6 @@ func (s *{{ .VarName }}) {{ .RecvName }}() ({{ .RecvRef }}, error) { } {{ comment .RecvWithContextDesc }} -func (s *{{ .VarName }}) {{ .RecvWithContextName }}(ctx context.Context) ({{ .RecvRef }}, context.Context, error) { - res, err := s.{{ .RecvName }}() - return res, ctx, err +func (s *{{ .VarName }}) {{ .RecvWithContextName }}(ctx context.Context) ({{ .RecvRef }}, error) { + return s.{{ .RecvName }}() } diff --git a/grpc/codegen/templates/stream_send.go.tpl b/grpc/codegen/templates/stream_send.go.tpl index f723057d96..e873121a22 100644 --- a/grpc/codegen/templates/stream_send.go.tpl +++ b/grpc/codegen/templates/stream_send.go.tpl @@ -12,6 +12,6 @@ func (s *{{ .VarName }}) {{ .SendName }}(res {{ .SendRef }}) error { } {{ comment .SendWithContextDesc }} -func (s *{{ .VarName }}) {{ .SendWithContextName }}(ctx context.Context, res {{ .SendRef }}) (context.Context, error) { - return ctx, s.{{ .SendName }}(res) +func (s *{{ .VarName }}) {{ .SendWithContextName }}(ctx context.Context, res {{ .SendRef }}) error { + return s.{{ .SendName }}(res) } diff --git a/grpc/codegen/testdata/streaming_code.go b/grpc/codegen/testdata/streaming_code.go index 3ce5baef9b..0a13907ff6 100644 --- a/grpc/codegen/testdata/streaming_code.go +++ b/grpc/codegen/testdata/streaming_code.go @@ -19,8 +19,8 @@ func (s *MethodServerStreamingUserTypeRPCServerStream) Send(res *serviceserverst // SendWithContext streams instances of // "service_server_streaming_user_type_rpcpb.MethodServerStreamingUserTypeRPCResponse" // to the "MethodServerStreamingUserTypeRPC" endpoint gRPC stream with context. -func (s *MethodServerStreamingUserTypeRPCServerStream) SendWithContext(ctx context.Context, res *serviceserverstreamingusertyperpc.UserType) (context.Context, error) { - return ctx, s.Send(res) +func (s *MethodServerStreamingUserTypeRPCServerStream) SendWithContext(ctx context.Context, res *serviceserverstreamingusertyperpc.UserType) error { + return s.Send(res) } ` @@ -54,9 +54,8 @@ func (s *MethodServerStreamingUserTypeRPCClientStream) Recv() (*serviceserverstr // "service_server_streaming_user_type_rpcpb.MethodServerStreamingUserTypeRPCResponse" // from the "MethodServerStreamingUserTypeRPC" endpoint gRPC stream with // context. -func (s *MethodServerStreamingUserTypeRPCClientStream) RecvWithContext(ctx context.Context) (*serviceserverstreamingusertyperpc.UserType, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *MethodServerStreamingUserTypeRPCClientStream) RecvWithContext(ctx context.Context) (*serviceserverstreamingusertyperpc.UserType, error) { + return s.Recv() } ` @@ -81,8 +80,8 @@ func (s *MethodServerStreamingUserTypeRPCServerStream) Send(res *serviceserverst // SendWithContext streams instances of // "service_server_streaming_user_type_rpcpb.MethodServerStreamingUserTypeRPCResponse" // to the "MethodServerStreamingUserTypeRPC" endpoint gRPC stream with context. -func (s *MethodServerStreamingUserTypeRPCServerStream) SendWithContext(ctx context.Context, res *serviceserverstreamingusertyperpc.ResultType) (context.Context, error) { - return ctx, s.Send(res) +func (s *MethodServerStreamingUserTypeRPCServerStream) SendWithContext(ctx context.Context, res *serviceserverstreamingusertyperpc.ResultType) error { + return s.Send(res) } ` @@ -122,9 +121,8 @@ func (s *MethodServerStreamingUserTypeRPCClientStream) Recv() (*serviceserverstr // "service_server_streaming_user_type_rpcpb.MethodServerStreamingUserTypeRPCResponse" // from the "MethodServerStreamingUserTypeRPC" endpoint gRPC stream with // context. -func (s *MethodServerStreamingUserTypeRPCClientStream) RecvWithContext(ctx context.Context) (*serviceserverstreamingusertyperpc.ResultType, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *MethodServerStreamingUserTypeRPCClientStream) RecvWithContext(ctx context.Context) (*serviceserverstreamingusertyperpc.ResultType, error) { + return s.Recv() } ` @@ -148,8 +146,8 @@ func (s *MethodServerStreamingResultTypeCollectionWithExplicitViewServerStream) // "service_server_streaming_result_type_collection_with_explicit_viewpb.ResultTypeCollection" // to the "MethodServerStreamingResultTypeCollectionWithExplicitView" endpoint // gRPC stream with context. -func (s *MethodServerStreamingResultTypeCollectionWithExplicitViewServerStream) SendWithContext(ctx context.Context, res serviceserverstreamingresulttypecollectionwithexplicitview.ResultTypeCollection) (context.Context, error) { - return ctx, s.Send(res) +func (s *MethodServerStreamingResultTypeCollectionWithExplicitViewServerStream) SendWithContext(ctx context.Context, res serviceserverstreamingresulttypecollectionwithexplicitview.ResultTypeCollection) error { + return s.Send(res) } ` @@ -175,9 +173,8 @@ func (s *MethodServerStreamingResultTypeCollectionWithExplicitViewClientStream) // "service_server_streaming_result_type_collection_with_explicit_viewpb.ResultTypeCollection" // from the "MethodServerStreamingResultTypeCollectionWithExplicitView" // endpoint gRPC stream with context. -func (s *MethodServerStreamingResultTypeCollectionWithExplicitViewClientStream) RecvWithContext(ctx context.Context) (serviceserverstreamingresulttypecollectionwithexplicitview.ResultTypeCollection, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *MethodServerStreamingResultTypeCollectionWithExplicitViewClientStream) RecvWithContext(ctx context.Context) (serviceserverstreamingresulttypecollectionwithexplicitview.ResultTypeCollection, error) { + return s.Recv() } ` @@ -192,8 +189,8 @@ func (s *MethodServerStreamingRPCServerStream) Send(res string) error { // SendWithContext streams instances of // "service_server_streaming_rpcpb.MethodServerStreamingRPCResponse" to the // "MethodServerStreamingRPC" endpoint gRPC stream with context. -func (s *MethodServerStreamingRPCServerStream) SendWithContext(ctx context.Context, res string) (context.Context, error) { - return ctx, s.Send(res) +func (s *MethodServerStreamingRPCServerStream) SendWithContext(ctx context.Context, res string) error { + return s.Send(res) } ` @@ -212,9 +209,8 @@ func (s *MethodServerStreamingRPCClientStream) Recv() (string, error) { // RecvWithContext reads instances of // "service_server_streaming_rpcpb.MethodServerStreamingRPCResponse" from the // "MethodServerStreamingRPC" endpoint gRPC stream with context. -func (s *MethodServerStreamingRPCClientStream) RecvWithContext(ctx context.Context) (string, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *MethodServerStreamingRPCClientStream) RecvWithContext(ctx context.Context) (string, error) { + return s.Recv() } ` @@ -229,8 +225,8 @@ func (s *MethodServerStreamingArrayServerStream) Send(res []int) error { // SendWithContext streams instances of // "service_server_streaming_arraypb.MethodServerStreamingArrayResponse" to the // "MethodServerStreamingArray" endpoint gRPC stream with context. -func (s *MethodServerStreamingArrayServerStream) SendWithContext(ctx context.Context, res []int) (context.Context, error) { - return ctx, s.Send(res) +func (s *MethodServerStreamingArrayServerStream) SendWithContext(ctx context.Context, res []int) error { + return s.Send(res) } ` @@ -249,9 +245,8 @@ func (s *MethodServerStreamingArrayClientStream) Recv() ([]int, error) { // RecvWithContext reads instances of // "service_server_streaming_arraypb.MethodServerStreamingArrayResponse" from // the "MethodServerStreamingArray" endpoint gRPC stream with context. -func (s *MethodServerStreamingArrayClientStream) RecvWithContext(ctx context.Context) ([]int, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *MethodServerStreamingArrayClientStream) RecvWithContext(ctx context.Context) ([]int, error) { + return s.Recv() } ` @@ -266,8 +261,8 @@ func (s *MethodServerStreamingMapServerStream) Send(res map[string]*serviceserve // SendWithContext streams instances of // "service_server_streaming_mappb.MethodServerStreamingMapResponse" to the // "MethodServerStreamingMap" endpoint gRPC stream with context. -func (s *MethodServerStreamingMapServerStream) SendWithContext(ctx context.Context, res map[string]*serviceserverstreamingmap.UserType) (context.Context, error) { - return ctx, s.Send(res) +func (s *MethodServerStreamingMapServerStream) SendWithContext(ctx context.Context, res map[string]*serviceserverstreamingmap.UserType) error { + return s.Send(res) } ` @@ -286,9 +281,8 @@ func (s *MethodServerStreamingMapClientStream) Recv() (map[string]*serviceserver // RecvWithContext reads instances of // "service_server_streaming_mappb.MethodServerStreamingMapResponse" from the // "MethodServerStreamingMap" endpoint gRPC stream with context. -func (s *MethodServerStreamingMapClientStream) RecvWithContext(ctx context.Context) (map[string]*serviceserverstreamingmap.UserType, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *MethodServerStreamingMapClientStream) RecvWithContext(ctx context.Context) (map[string]*serviceserverstreamingmap.UserType, error) { + return s.Recv() } ` @@ -307,9 +301,8 @@ func (s *MethodServerStreamingRPCClientStream) Recv() (*serviceserverstreamingrp // RecvWithContext reads instances of // "service_server_streaming_rpcpb.MethodServerStreamingRPCResponse" from the // "MethodServerStreamingRPC" endpoint gRPC stream with context. -func (s *MethodServerStreamingRPCClientStream) RecvWithContext(ctx context.Context) (*serviceserverstreamingrpc.UserType, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *MethodServerStreamingRPCClientStream) RecvWithContext(ctx context.Context) (*serviceserverstreamingrpc.UserType, error) { + return s.Recv() } // Recv reads instances of @@ -327,9 +320,8 @@ func (s *OtherMethodServerStreamingRPCClientStream) Recv() (*serviceserverstream // RecvWithContext reads instances of // "service_server_streaming_rpcpb.OtherMethodServerStreamingRPCResponse" from // the "OtherMethodServerStreamingRPC" endpoint gRPC stream with context. -func (s *OtherMethodServerStreamingRPCClientStream) RecvWithContext(ctx context.Context) (*serviceserverstreamingrpc.UserType, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *OtherMethodServerStreamingRPCClientStream) RecvWithContext(ctx context.Context) (*serviceserverstreamingrpc.UserType, error) { + return s.Recv() } ` @@ -351,8 +343,8 @@ func (s *MethodClientStreamingRPCServerStream) SendAndClose(res string) error { // SendAndCloseWithContext streams instances of // "service_client_streaming_rpcpb.MethodClientStreamingRPCResponse" to the // "MethodClientStreamingRPC" endpoint gRPC stream with context. -func (s *MethodClientStreamingRPCServerStream) SendAndCloseWithContext(ctx context.Context, res string) (context.Context, error) { - return ctx, s.SendAndClose(res) +func (s *MethodClientStreamingRPCServerStream) SendAndCloseWithContext(ctx context.Context, res string) error { + return s.SendAndClose(res) } ` @@ -371,9 +363,8 @@ func (s *MethodClientStreamingRPCServerStream) Recv() (int, error) { // RecvWithContext reads instances of // "service_client_streaming_rpcpb.MethodClientStreamingRPCStreamingRequest" // from the "MethodClientStreamingRPC" endpoint gRPC stream with context. -func (s *MethodClientStreamingRPCServerStream) RecvWithContext(ctx context.Context) (int, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *MethodClientStreamingRPCServerStream) RecvWithContext(ctx context.Context) (int, error) { + return s.Recv() } ` @@ -395,8 +386,8 @@ func (s *MethodClientStreamingRPCClientStream) Send(res int) error { // SendWithContext streams instances of // "service_client_streaming_rpcpb.MethodClientStreamingRPCStreamingRequest" to // the "MethodClientStreamingRPC" endpoint gRPC stream with context. -func (s *MethodClientStreamingRPCClientStream) SendWithContext(ctx context.Context, res int) (context.Context, error) { - return ctx, s.Send(res) +func (s *MethodClientStreamingRPCClientStream) SendWithContext(ctx context.Context, res int) error { + return s.Send(res) } ` @@ -415,9 +406,8 @@ func (s *MethodClientStreamingRPCClientStream) CloseAndRecv() (string, error) { // CloseAndRecvWithContext reads instances of // "service_client_streaming_rpcpb.MethodClientStreamingRPCResponse" from the // "MethodClientStreamingRPC" endpoint gRPC stream with context. -func (s *MethodClientStreamingRPCClientStream) CloseAndRecvWithContext(ctx context.Context) (string, context.Context, error) { - res, err := s.CloseAndRecv() - return res, ctx, err +func (s *MethodClientStreamingRPCClientStream) CloseAndRecvWithContext(ctx context.Context) (string, error) { + return s.CloseAndRecv() } ` @@ -455,8 +445,8 @@ func (s *MethodBidirectionalStreamingRPCServerStream) Send(res *servicebidirecti // SendWithContext streams instances of // "service_bidirectional_streaming_rpcpb.MethodBidirectionalStreamingRPCResponse" // to the "MethodBidirectionalStreamingRPC" endpoint gRPC stream with context. -func (s *MethodBidirectionalStreamingRPCServerStream) SendWithContext(ctx context.Context, res *servicebidirectionalstreamingrpc.ID) (context.Context, error) { - return ctx, s.Send(res) +func (s *MethodBidirectionalStreamingRPCServerStream) SendWithContext(ctx context.Context, res *servicebidirectionalstreamingrpc.ID) error { + return s.Send(res) } ` @@ -475,9 +465,8 @@ func (s *MethodBidirectionalStreamingRPCServerStream) Recv() (int, error) { // RecvWithContext reads instances of // "service_bidirectional_streaming_rpcpb.MethodBidirectionalStreamingRPCStreamingRequest" // from the "MethodBidirectionalStreamingRPC" endpoint gRPC stream with context. -func (s *MethodBidirectionalStreamingRPCServerStream) RecvWithContext(ctx context.Context) (int, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *MethodBidirectionalStreamingRPCServerStream) RecvWithContext(ctx context.Context) (int, error) { + return s.Recv() } ` @@ -507,8 +496,8 @@ func (s *MethodBidirectionalStreamingRPCClientStream) Send(res int) error { // SendWithContext streams instances of // "service_bidirectional_streaming_rpcpb.MethodBidirectionalStreamingRPCStreamingRequest" // to the "MethodBidirectionalStreamingRPC" endpoint gRPC stream with context. -func (s *MethodBidirectionalStreamingRPCClientStream) SendWithContext(ctx context.Context, res int) (context.Context, error) { - return ctx, s.Send(res) +func (s *MethodBidirectionalStreamingRPCClientStream) SendWithContext(ctx context.Context, res int) error { + return s.Send(res) } ` @@ -532,9 +521,8 @@ func (s *MethodBidirectionalStreamingRPCClientStream) Recv() (*servicebidirectio // RecvWithContext reads instances of // "service_bidirectional_streaming_rpcpb.MethodBidirectionalStreamingRPCResponse" // from the "MethodBidirectionalStreamingRPC" endpoint gRPC stream with context. -func (s *MethodBidirectionalStreamingRPCClientStream) RecvWithContext(ctx context.Context) (*servicebidirectionalstreamingrpc.ID, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *MethodBidirectionalStreamingRPCClientStream) RecvWithContext(ctx context.Context) (*servicebidirectionalstreamingrpc.ID, error) { + return s.Recv() } ` diff --git a/http/codegen/templates/websocket_recv.go.tpl b/http/codegen/templates/websocket_recv.go.tpl index 5096dd791c..f6c1a8067c 100644 --- a/http/codegen/templates/websocket_recv.go.tpl +++ b/http/codegen/templates/websocket_recv.go.tpl @@ -85,7 +85,6 @@ func (s *{{ .VarName }}) {{ .RecvName }}() ({{ .RecvTypeRef }}, error) { } {{ comment .RecvWithContextDesc }} -func (s *{{ .VarName }}) {{ .RecvWithContextName }}(ctx context.Context) ({{ .RecvTypeRef }}, context.Context, error) { - res, err := s.{{ .RecvName }}() - return res, ctx, err +func (s *{{ .VarName }}) {{ .RecvWithContextName }}(ctx context.Context) ({{ .RecvTypeRef }}, error) { + return s.{{ .RecvName }}() } diff --git a/http/codegen/templates/websocket_send.go.tpl b/http/codegen/templates/websocket_send.go.tpl index 6272150830..11f2f02b22 100644 --- a/http/codegen/templates/websocket_send.go.tpl +++ b/http/codegen/templates/websocket_send.go.tpl @@ -54,6 +54,6 @@ func (s *{{ .VarName }}) {{ .SendName }}(v {{ .SendTypeRef }}) error { } {{ comment .SendWithContextDesc }} -func (s *{{ .VarName }}) {{ .SendWithContextName }}(ctx context.Context, v {{ .SendTypeRef }}) (context.Context, error) { - return ctx, s.{{ .SendName }}(v) +func (s *{{ .VarName }}) {{ .SendWithContextName }}(ctx context.Context, v {{ .SendTypeRef }}) error { + return s.{{ .SendName }}(v) } diff --git a/http/codegen/testdata/streaming_code.go b/http/codegen/testdata/streaming_code.go index fe0431bc2a..8feb4abaa5 100644 --- a/http/codegen/testdata/streaming_code.go +++ b/http/codegen/testdata/streaming_code.go @@ -100,8 +100,8 @@ func (s *StreamingResultMethodServerStream) Send(v *streamingresultservice.UserT // SendWithContext streams instances of "streamingresultservice.UserType" to // the "StreamingResultMethod" endpoint websocket connection with context. -func (s *StreamingResultMethodServerStream) SendWithContext(ctx context.Context, v *streamingresultservice.UserType) (context.Context, error) { - return ctx, s.Send(v) +func (s *StreamingResultMethodServerStream) SendWithContext(ctx context.Context, v *streamingresultservice.UserType) error { + return s.Send(v) } ` @@ -161,8 +161,8 @@ func (s *StreamingResultWithViewsMethodServerStream) Send(v *streamingresultwith // SendWithContext streams instances of // "streamingresultwithviewsservice.Usertype" to the // "StreamingResultWithViewsMethod" endpoint websocket connection with context. -func (s *StreamingResultWithViewsMethodServerStream) SendWithContext(ctx context.Context, v *streamingresultwithviewsservice.Usertype) (context.Context, error) { - return ctx, s.Send(v) +func (s *StreamingResultWithViewsMethodServerStream) SendWithContext(ctx context.Context, v *streamingresultwithviewsservice.Usertype) error { + return s.Send(v) } ` @@ -300,9 +300,8 @@ func (s *StreamingResultMethodClientStream) Recv() (*streamingresultservice.User // RecvWithContext reads instances of "streamingresultservice.UserType" from // the "StreamingResultMethod" endpoint websocket connection with context. -func (s *StreamingResultMethodClientStream) RecvWithContext(ctx context.Context) (*streamingresultservice.UserType, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *StreamingResultMethodClientStream) RecvWithContext(ctx context.Context) (*streamingresultservice.UserType, error) { + return s.Recv() } ` @@ -374,9 +373,8 @@ func (s *StreamingResultWithViewsMethodClientStream) Recv() (*streamingresultwit // RecvWithContext reads instances of // "streamingresultwithviewsservice.Usertype" from the // "StreamingResultWithViewsMethod" endpoint websocket connection with context. -func (s *StreamingResultWithViewsMethodClientStream) RecvWithContext(ctx context.Context) (*streamingresultwithviewsservice.Usertype, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *StreamingResultWithViewsMethodClientStream) RecvWithContext(ctx context.Context) (*streamingresultwithviewsservice.Usertype, error) { + return s.Recv() } ` @@ -455,9 +453,8 @@ func (s *StreamingResultWithExplicitViewMethodClientStream) Recv() (*streamingre // "streamingresultwithexplicitviewservice.Usertype" from the // "StreamingResultWithExplicitViewMethod" endpoint websocket connection with // context. -func (s *StreamingResultWithExplicitViewMethodClientStream) RecvWithContext(ctx context.Context) (*streamingresultwithexplicitviewservice.Usertype, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *StreamingResultWithExplicitViewMethodClientStream) RecvWithContext(ctx context.Context) (*streamingresultwithexplicitviewservice.Usertype, error) { + return s.Recv() } ` @@ -491,8 +488,8 @@ func (s *StreamingResultWithExplicitViewMethodServerStream) Send(v *streamingres // "streamingresultwithexplicitviewservice.Usertype" to the // "StreamingResultWithExplicitViewMethod" endpoint websocket connection with // context. -func (s *StreamingResultWithExplicitViewMethodServerStream) SendWithContext(ctx context.Context, v *streamingresultwithexplicitviewservice.Usertype) (context.Context, error) { - return ctx, s.Send(v) +func (s *StreamingResultWithExplicitViewMethodServerStream) SendWithContext(ctx context.Context, v *streamingresultwithexplicitviewservice.Usertype) error { + return s.Send(v) } ` @@ -537,8 +534,8 @@ func (s *StreamingResultCollectionWithViewsMethodServerStream) Send(v streamingr // "streamingresultcollectionwithviewsservice.UsertypeCollection" to the // "StreamingResultCollectionWithViewsMethod" endpoint websocket connection // with context. -func (s *StreamingResultCollectionWithViewsMethodServerStream) SendWithContext(ctx context.Context, v streamingresultcollectionwithviewsservice.UsertypeCollection) (context.Context, error) { - return ctx, s.Send(v) +func (s *StreamingResultCollectionWithViewsMethodServerStream) SendWithContext(ctx context.Context, v streamingresultcollectionwithviewsservice.UsertypeCollection) error { + return s.Send(v) } ` @@ -580,9 +577,8 @@ func (s *StreamingResultCollectionWithViewsMethodClientStream) Recv() (streaming // "streamingresultcollectionwithviewsservice.UsertypeCollection" from the // "StreamingResultCollectionWithViewsMethod" endpoint websocket connection // with context. -func (s *StreamingResultCollectionWithViewsMethodClientStream) RecvWithContext(ctx context.Context) (streamingresultcollectionwithviewsservice.UsertypeCollection, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *StreamingResultCollectionWithViewsMethodClientStream) RecvWithContext(ctx context.Context) (streamingresultcollectionwithviewsservice.UsertypeCollection, error) { + return s.Recv() } ` @@ -625,8 +621,8 @@ func (s *StreamingResultCollectionWithExplicitViewMethodServerStream) Send(v str // "streamingresultcollectionwithexplicitviewservice.UsertypeCollection" to the // "StreamingResultCollectionWithExplicitViewMethod" endpoint websocket // connection with context. -func (s *StreamingResultCollectionWithExplicitViewMethodServerStream) SendWithContext(ctx context.Context, v streamingresultcollectionwithexplicitviewservice.UsertypeCollection) (context.Context, error) { - return ctx, s.Send(v) +func (s *StreamingResultCollectionWithExplicitViewMethodServerStream) SendWithContext(ctx context.Context, v streamingresultcollectionwithexplicitviewservice.UsertypeCollection) error { + return s.Send(v) } ` var StreamingResultCollectionWithExplicitViewClientEndpointCode = `// StreamingResultCollectionWithExplicitViewMethod returns an endpoint that @@ -698,9 +694,8 @@ func (s *StreamingResultCollectionWithExplicitViewMethodClientStream) Recv() (st // "streamingresultcollectionwithexplicitviewservice.UsertypeCollection" from // the "StreamingResultCollectionWithExplicitViewMethod" endpoint websocket // connection with context. -func (s *StreamingResultCollectionWithExplicitViewMethodClientStream) RecvWithContext(ctx context.Context) (streamingresultcollectionwithexplicitviewservice.UsertypeCollection, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *StreamingResultCollectionWithExplicitViewMethodClientStream) RecvWithContext(ctx context.Context) (streamingresultcollectionwithexplicitviewservice.UsertypeCollection, error) { + return s.Recv() } ` @@ -731,8 +726,8 @@ func (s *StreamingResultPrimitiveMethodServerStream) Send(v string) error { // SendWithContext streams instances of "string" to the // "StreamingResultPrimitiveMethod" endpoint websocket connection with context. -func (s *StreamingResultPrimitiveMethodServerStream) SendWithContext(ctx context.Context, v string) (context.Context, error) { - return ctx, s.Send(v) +func (s *StreamingResultPrimitiveMethodServerStream) SendWithContext(ctx context.Context, v string) error { + return s.Send(v) } ` @@ -757,9 +752,8 @@ func (s *StreamingResultPrimitiveMethodClientStream) Recv() (string, error) { // RecvWithContext reads instances of "string" from the // "StreamingResultPrimitiveMethod" endpoint websocket connection with context. -func (s *StreamingResultPrimitiveMethodClientStream) RecvWithContext(ctx context.Context) (string, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *StreamingResultPrimitiveMethodClientStream) RecvWithContext(ctx context.Context) (string, error) { + return s.Recv() } ` @@ -791,8 +785,8 @@ func (s *StreamingResultPrimitiveArrayMethodServerStream) Send(v []int32) error // SendWithContext streams instances of "[]int32" to the // "StreamingResultPrimitiveArrayMethod" endpoint websocket connection with // context. -func (s *StreamingResultPrimitiveArrayMethodServerStream) SendWithContext(ctx context.Context, v []int32) (context.Context, error) { - return ctx, s.Send(v) +func (s *StreamingResultPrimitiveArrayMethodServerStream) SendWithContext(ctx context.Context, v []int32) error { + return s.Send(v) } ` @@ -818,9 +812,8 @@ func (s *StreamingResultPrimitiveArrayMethodClientStream) Recv() ([]int32, error // RecvWithContext reads instances of "[]int32" from the // "StreamingResultPrimitiveArrayMethod" endpoint websocket connection with // context. -func (s *StreamingResultPrimitiveArrayMethodClientStream) RecvWithContext(ctx context.Context) ([]int32, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *StreamingResultPrimitiveArrayMethodClientStream) RecvWithContext(ctx context.Context) ([]int32, error) { + return s.Recv() } ` @@ -852,8 +845,8 @@ func (s *StreamingResultPrimitiveMapMethodServerStream) Send(v map[int32]string) // SendWithContext streams instances of "map[int32]string" to the // "StreamingResultPrimitiveMapMethod" endpoint websocket connection with // context. -func (s *StreamingResultPrimitiveMapMethodServerStream) SendWithContext(ctx context.Context, v map[int32]string) (context.Context, error) { - return ctx, s.Send(v) +func (s *StreamingResultPrimitiveMapMethodServerStream) SendWithContext(ctx context.Context, v map[int32]string) error { + return s.Send(v) } ` @@ -879,9 +872,8 @@ func (s *StreamingResultPrimitiveMapMethodClientStream) Recv() (map[int32]string // RecvWithContext reads instances of "map[int32]string" from the // "StreamingResultPrimitiveMapMethod" endpoint websocket connection with // context. -func (s *StreamingResultPrimitiveMapMethodClientStream) RecvWithContext(ctx context.Context) (map[int32]string, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *StreamingResultPrimitiveMapMethodClientStream) RecvWithContext(ctx context.Context) (map[int32]string, error) { + return s.Recv() } ` @@ -915,8 +907,8 @@ func (s *StreamingResultUserTypeArrayMethodServerStream) Send(v []*streamingresu // "[]*streamingresultusertypearrayservice.UserType" to the // "StreamingResultUserTypeArrayMethod" endpoint websocket connection with // context. -func (s *StreamingResultUserTypeArrayMethodServerStream) SendWithContext(ctx context.Context, v []*streamingresultusertypearrayservice.UserType) (context.Context, error) { - return ctx, s.Send(v) +func (s *StreamingResultUserTypeArrayMethodServerStream) SendWithContext(ctx context.Context, v []*streamingresultusertypearrayservice.UserType) error { + return s.Send(v) } ` @@ -944,9 +936,8 @@ func (s *StreamingResultUserTypeArrayMethodClientStream) Recv() ([]*streamingres // "[]*streamingresultusertypearrayservice.UserType" from the // "StreamingResultUserTypeArrayMethod" endpoint websocket connection with // context. -func (s *StreamingResultUserTypeArrayMethodClientStream) RecvWithContext(ctx context.Context) ([]*streamingresultusertypearrayservice.UserType, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *StreamingResultUserTypeArrayMethodClientStream) RecvWithContext(ctx context.Context) ([]*streamingresultusertypearrayservice.UserType, error) { + return s.Recv() } ` @@ -981,8 +972,8 @@ func (s *StreamingResultUserTypeMapMethodServerStream) Send(v map[string]*stream // "map[string]*streamingresultusertypemapservice.UserType" to the // "StreamingResultUserTypeMapMethod" endpoint websocket connection with // context. -func (s *StreamingResultUserTypeMapMethodServerStream) SendWithContext(ctx context.Context, v map[string]*streamingresultusertypemapservice.UserType) (context.Context, error) { - return ctx, s.Send(v) +func (s *StreamingResultUserTypeMapMethodServerStream) SendWithContext(ctx context.Context, v map[string]*streamingresultusertypemapservice.UserType) error { + return s.Send(v) } ` @@ -1011,9 +1002,8 @@ func (s *StreamingResultUserTypeMapMethodClientStream) Recv() (map[string]*strea // "map[string]*streamingresultusertypemapservice.UserType" from the // "StreamingResultUserTypeMapMethod" endpoint websocket connection with // context. -func (s *StreamingResultUserTypeMapMethodClientStream) RecvWithContext(ctx context.Context) (map[string]*streamingresultusertypemapservice.UserType, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *StreamingResultUserTypeMapMethodClientStream) RecvWithContext(ctx context.Context) (map[string]*streamingresultusertypemapservice.UserType, error) { + return s.Recv() } ` @@ -1125,8 +1115,8 @@ func (s *StreamingPayloadMethodServerStream) SendAndClose(v *streamingpayloadser // SendAndCloseWithContext streams instances of // "streamingpayloadservice.UserType" to the "StreamingPayloadMethod" endpoint // websocket connection with context and closes the connection. -func (s *StreamingPayloadMethodServerStream) SendAndCloseWithContext(ctx context.Context, v *streamingpayloadservice.UserType) (context.Context, error) { - return ctx, s.SendAndClose(v) +func (s *StreamingPayloadMethodServerStream) SendAndCloseWithContext(ctx context.Context, v *streamingpayloadservice.UserType) error { + return s.SendAndClose(v) } ` @@ -1166,9 +1156,8 @@ func (s *StreamingPayloadMethodServerStream) Recv() (*streamingpayloadservice.Re // RecvWithContext reads instances of "streamingpayloadservice.Request" from // the "StreamingPayloadMethod" endpoint websocket connection with context. -func (s *StreamingPayloadMethodServerStream) RecvWithContext(ctx context.Context) (*streamingpayloadservice.Request, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *StreamingPayloadMethodServerStream) RecvWithContext(ctx context.Context) (*streamingpayloadservice.Request, error) { + return s.Recv() } ` @@ -1213,8 +1202,8 @@ func (s *StreamingPayloadMethodClientStream) Send(v *streamingpayloadservice.Req // SendWithContext streams instances of "streamingpayloadservice.Request" to // the "StreamingPayloadMethod" endpoint websocket connection with context. -func (s *StreamingPayloadMethodClientStream) SendWithContext(ctx context.Context, v *streamingpayloadservice.Request) (context.Context, error) { - return ctx, s.Send(v) +func (s *StreamingPayloadMethodClientStream) SendWithContext(ctx context.Context, v *streamingpayloadservice.Request) error { + return s.Send(v) } ` @@ -1247,9 +1236,8 @@ func (s *StreamingPayloadMethodClientStream) CloseAndRecv() (*streamingpayloadse // CloseAndRecvWithContext stops sending messages to the // "StreamingPayloadMethod" endpoint websocket connection and reads instances // of "streamingpayloadservice.UserType" from the connection with context. -func (s *StreamingPayloadMethodClientStream) CloseAndRecvWithContext(ctx context.Context) (*streamingpayloadservice.UserType, context.Context, error) { - res, err := s.CloseAndRecv() - return res, ctx, err +func (s *StreamingPayloadMethodClientStream) CloseAndRecvWithContext(ctx context.Context) (*streamingpayloadservice.UserType, error) { + return s.CloseAndRecv() } ` @@ -1339,8 +1327,8 @@ func (s *StreamingPayloadNoPayloadMethodClientStream) Send(v *streamingpayloadno // SendWithContext streams instances of // "streamingpayloadnopayloadservice.Request" to the // "StreamingPayloadNoPayloadMethod" endpoint websocket connection with context. -func (s *StreamingPayloadNoPayloadMethodClientStream) SendWithContext(ctx context.Context, v *streamingpayloadnopayloadservice.Request) (context.Context, error) { - return ctx, s.Send(v) +func (s *StreamingPayloadNoPayloadMethodClientStream) SendWithContext(ctx context.Context, v *streamingpayloadnopayloadservice.Request) error { + return s.Send(v) } ` @@ -1374,9 +1362,8 @@ func (s *StreamingPayloadNoPayloadMethodClientStream) CloseAndRecv() (*streaming // "StreamingPayloadNoPayloadMethod" endpoint websocket connection and reads // instances of "streamingpayloadnopayloadservice.UserType" from the connection // with context. -func (s *StreamingPayloadNoPayloadMethodClientStream) CloseAndRecvWithContext(ctx context.Context) (*streamingpayloadnopayloadservice.UserType, context.Context, error) { - res, err := s.CloseAndRecv() - return res, ctx, err +func (s *StreamingPayloadNoPayloadMethodClientStream) CloseAndRecvWithContext(ctx context.Context) (*streamingpayloadnopayloadservice.UserType, error) { + return s.CloseAndRecv() } ` @@ -1416,9 +1403,8 @@ func (s *StreamingPayloadNoResultMethodServerStream) Recv() (string, error) { // RecvWithContext reads instances of "string" from the // "StreamingPayloadNoResultMethod" endpoint websocket connection with context. -func (s *StreamingPayloadNoResultMethodServerStream) RecvWithContext(ctx context.Context) (string, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *StreamingPayloadNoResultMethodServerStream) RecvWithContext(ctx context.Context) (string, error) { + return s.Recv() } ` @@ -1448,8 +1434,8 @@ func (s *StreamingPayloadNoResultMethodClientStream) Send(v string) error { // SendWithContext streams instances of "string" to the // "StreamingPayloadNoResultMethod" endpoint websocket connection with context. -func (s *StreamingPayloadNoResultMethodClientStream) SendWithContext(ctx context.Context, v string) (context.Context, error) { - return ctx, s.Send(v) +func (s *StreamingPayloadNoResultMethodClientStream) SendWithContext(ctx context.Context, v string) error { + return s.Send(v) } ` @@ -1488,8 +1474,8 @@ func (s *StreamingPayloadResultWithViewsMethodServerStream) SendAndClose(v *stre // "streamingpayloadresultwithviewsservice.Usertype" to the // "StreamingPayloadResultWithViewsMethod" endpoint websocket connection with // context and closes the connection. -func (s *StreamingPayloadResultWithViewsMethodServerStream) SendAndCloseWithContext(ctx context.Context, v *streamingpayloadresultwithviewsservice.Usertype) (context.Context, error) { - return ctx, s.SendAndClose(v) +func (s *StreamingPayloadResultWithViewsMethodServerStream) SendAndCloseWithContext(ctx context.Context, v *streamingpayloadresultwithviewsservice.Usertype) error { + return s.SendAndClose(v) } ` @@ -1530,9 +1516,8 @@ func (s *StreamingPayloadResultWithViewsMethodServerStream) Recv() (float32, err // RecvWithContext reads instances of "float32" from the // "StreamingPayloadResultWithViewsMethod" endpoint websocket connection with // context. -func (s *StreamingPayloadResultWithViewsMethodServerStream) RecvWithContext(ctx context.Context) (float32, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *StreamingPayloadResultWithViewsMethodServerStream) RecvWithContext(ctx context.Context) (float32, error) { + return s.Recv() } ` @@ -1553,8 +1538,8 @@ func (s *StreamingPayloadResultWithViewsMethodClientStream) Send(v float32) erro // SendWithContext streams instances of "float32" to the // "StreamingPayloadResultWithViewsMethod" endpoint websocket connection with // context. -func (s *StreamingPayloadResultWithViewsMethodClientStream) SendWithContext(ctx context.Context, v float32) (context.Context, error) { - return ctx, s.Send(v) +func (s *StreamingPayloadResultWithViewsMethodClientStream) SendWithContext(ctx context.Context, v float32) error { + return s.Send(v) } ` @@ -1593,9 +1578,8 @@ func (s *StreamingPayloadResultWithViewsMethodClientStream) CloseAndRecv() (*str // "StreamingPayloadResultWithViewsMethod" endpoint websocket connection and // reads instances of "streamingpayloadresultwithviewsservice.Usertype" from // the connection with context. -func (s *StreamingPayloadResultWithViewsMethodClientStream) CloseAndRecvWithContext(ctx context.Context) (*streamingpayloadresultwithviewsservice.Usertype, context.Context, error) { - res, err := s.CloseAndRecv() - return res, ctx, err +func (s *StreamingPayloadResultWithViewsMethodClientStream) CloseAndRecvWithContext(ctx context.Context) (*streamingpayloadresultwithviewsservice.Usertype, error) { + return s.CloseAndRecv() } ` @@ -1621,8 +1605,8 @@ func (s *StreamingPayloadResultWithExplicitViewMethodServerStream) SendAndClose( // "streamingpayloadresultwithexplicitviewservice.Usertype" to the // "StreamingPayloadResultWithExplicitViewMethod" endpoint websocket connection // with context and closes the connection. -func (s *StreamingPayloadResultWithExplicitViewMethodServerStream) SendAndCloseWithContext(ctx context.Context, v *streamingpayloadresultwithexplicitviewservice.Usertype) (context.Context, error) { - return ctx, s.SendAndClose(v) +func (s *StreamingPayloadResultWithExplicitViewMethodServerStream) SendAndCloseWithContext(ctx context.Context, v *streamingpayloadresultwithexplicitviewservice.Usertype) error { + return s.SendAndClose(v) } ` @@ -1663,9 +1647,8 @@ func (s *StreamingPayloadResultWithExplicitViewMethodServerStream) Recv() (float // RecvWithContext reads instances of "float32" from the // "StreamingPayloadResultWithExplicitViewMethod" endpoint websocket connection // with context. -func (s *StreamingPayloadResultWithExplicitViewMethodServerStream) RecvWithContext(ctx context.Context) (float32, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *StreamingPayloadResultWithExplicitViewMethodServerStream) RecvWithContext(ctx context.Context) (float32, error) { + return s.Recv() } ` @@ -1678,8 +1661,8 @@ func (s *StreamingPayloadResultWithExplicitViewMethodClientStream) Send(v float3 // SendWithContext streams instances of "float32" to the // "StreamingPayloadResultWithExplicitViewMethod" endpoint websocket connection // with context. -func (s *StreamingPayloadResultWithExplicitViewMethodClientStream) SendWithContext(ctx context.Context, v float32) (context.Context, error) { - return ctx, s.Send(v) +func (s *StreamingPayloadResultWithExplicitViewMethodClientStream) SendWithContext(ctx context.Context, v float32) error { + return s.Send(v) } ` @@ -1719,9 +1702,8 @@ func (s *StreamingPayloadResultWithExplicitViewMethodClientStream) CloseAndRecv( // and reads instances of // "streamingpayloadresultwithexplicitviewservice.Usertype" from the connection // with context. -func (s *StreamingPayloadResultWithExplicitViewMethodClientStream) CloseAndRecvWithContext(ctx context.Context) (*streamingpayloadresultwithexplicitviewservice.Usertype, context.Context, error) { - res, err := s.CloseAndRecv() - return res, ctx, err +func (s *StreamingPayloadResultWithExplicitViewMethodClientStream) CloseAndRecvWithContext(ctx context.Context) (*streamingpayloadresultwithexplicitviewservice.Usertype, error) { + return s.CloseAndRecv() } ` @@ -1748,8 +1730,8 @@ func (s *StreamingPayloadResultCollectionWithViewsMethodServerStream) SendAndClo // "streamingpayloadresultcollectionwithviewsservice.UsertypeCollection" to the // "StreamingPayloadResultCollectionWithViewsMethod" endpoint websocket // connection with context and closes the connection. -func (s *StreamingPayloadResultCollectionWithViewsMethodServerStream) SendAndCloseWithContext(ctx context.Context, v streamingpayloadresultcollectionwithviewsservice.UsertypeCollection) (context.Context, error) { - return ctx, s.SendAndClose(v) +func (s *StreamingPayloadResultCollectionWithViewsMethodServerStream) SendAndCloseWithContext(ctx context.Context, v streamingpayloadresultcollectionwithviewsservice.UsertypeCollection) error { + return s.SendAndClose(v) } ` @@ -1791,9 +1773,8 @@ func (s *StreamingPayloadResultCollectionWithViewsMethodServerStream) Recv() (an // RecvWithContext reads instances of "any" from the // "StreamingPayloadResultCollectionWithViewsMethod" endpoint websocket // connection with context. -func (s *StreamingPayloadResultCollectionWithViewsMethodServerStream) RecvWithContext(ctx context.Context) (any, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *StreamingPayloadResultCollectionWithViewsMethodServerStream) RecvWithContext(ctx context.Context) (any, error) { + return s.Recv() } ` @@ -1816,8 +1797,8 @@ func (s *StreamingPayloadResultCollectionWithViewsMethodClientStream) Send(v any // SendWithContext streams instances of "any" to the // "StreamingPayloadResultCollectionWithViewsMethod" endpoint websocket // connection with context. -func (s *StreamingPayloadResultCollectionWithViewsMethodClientStream) SendWithContext(ctx context.Context, v any) (context.Context, error) { - return ctx, s.Send(v) +func (s *StreamingPayloadResultCollectionWithViewsMethodClientStream) SendWithContext(ctx context.Context, v any) error { + return s.Send(v) } ` @@ -1858,9 +1839,8 @@ func (s *StreamingPayloadResultCollectionWithViewsMethodClientStream) CloseAndRe // connection and reads instances of // "streamingpayloadresultcollectionwithviewsservice.UsertypeCollection" from // the connection with context. -func (s *StreamingPayloadResultCollectionWithViewsMethodClientStream) CloseAndRecvWithContext(ctx context.Context) (streamingpayloadresultcollectionwithviewsservice.UsertypeCollection, context.Context, error) { - res, err := s.CloseAndRecv() - return res, ctx, err +func (s *StreamingPayloadResultCollectionWithViewsMethodClientStream) CloseAndRecvWithContext(ctx context.Context) (streamingpayloadresultcollectionwithviewsservice.UsertypeCollection, error) { + return s.CloseAndRecv() } ` @@ -1887,8 +1867,8 @@ func (s *StreamingPayloadResultCollectionWithExplicitViewMethodServerStream) Sen // "streamingpayloadresultcollectionwithexplicitviewservice.UsertypeCollection" // to the "StreamingPayloadResultCollectionWithExplicitViewMethod" endpoint // websocket connection with context and closes the connection. -func (s *StreamingPayloadResultCollectionWithExplicitViewMethodServerStream) SendAndCloseWithContext(ctx context.Context, v streamingpayloadresultcollectionwithexplicitviewservice.UsertypeCollection) (context.Context, error) { - return ctx, s.SendAndClose(v) +func (s *StreamingPayloadResultCollectionWithExplicitViewMethodServerStream) SendAndCloseWithContext(ctx context.Context, v streamingpayloadresultcollectionwithexplicitviewservice.UsertypeCollection) error { + return s.SendAndClose(v) } ` @@ -1930,9 +1910,8 @@ func (s *StreamingPayloadResultCollectionWithExplicitViewMethodServerStream) Rec // RecvWithContext reads instances of "any" from the // "StreamingPayloadResultCollectionWithExplicitViewMethod" endpoint websocket // connection with context. -func (s *StreamingPayloadResultCollectionWithExplicitViewMethodServerStream) RecvWithContext(ctx context.Context) (any, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *StreamingPayloadResultCollectionWithExplicitViewMethodServerStream) RecvWithContext(ctx context.Context) (any, error) { + return s.Recv() } ` @@ -1946,8 +1925,8 @@ func (s *StreamingPayloadResultCollectionWithExplicitViewMethodClientStream) Sen // SendWithContext streams instances of "any" to the // "StreamingPayloadResultCollectionWithExplicitViewMethod" endpoint websocket // connection with context. -func (s *StreamingPayloadResultCollectionWithExplicitViewMethodClientStream) SendWithContext(ctx context.Context, v any) (context.Context, error) { - return ctx, s.Send(v) +func (s *StreamingPayloadResultCollectionWithExplicitViewMethodClientStream) SendWithContext(ctx context.Context, v any) error { + return s.Send(v) } ` @@ -1988,9 +1967,8 @@ func (s *StreamingPayloadResultCollectionWithExplicitViewMethodClientStream) Clo // connection and reads instances of // "streamingpayloadresultcollectionwithexplicitviewservice.UsertypeCollection" // from the connection with context. -func (s *StreamingPayloadResultCollectionWithExplicitViewMethodClientStream) CloseAndRecvWithContext(ctx context.Context) (streamingpayloadresultcollectionwithexplicitviewservice.UsertypeCollection, context.Context, error) { - res, err := s.CloseAndRecv() - return res, ctx, err +func (s *StreamingPayloadResultCollectionWithExplicitViewMethodClientStream) CloseAndRecvWithContext(ctx context.Context) (streamingpayloadresultcollectionwithexplicitviewservice.UsertypeCollection, error) { + return s.CloseAndRecv() } ` @@ -2006,8 +1984,8 @@ func (s *StreamingPayloadPrimitiveMethodServerStream) SendAndClose(v string) err // SendAndCloseWithContext streams instances of "string" to the // "StreamingPayloadPrimitiveMethod" endpoint websocket connection with context // and closes the connection. -func (s *StreamingPayloadPrimitiveMethodServerStream) SendAndCloseWithContext(ctx context.Context, v string) (context.Context, error) { - return ctx, s.SendAndClose(v) +func (s *StreamingPayloadPrimitiveMethodServerStream) SendAndCloseWithContext(ctx context.Context, v string) error { + return s.SendAndClose(v) } ` @@ -2047,9 +2025,8 @@ func (s *StreamingPayloadPrimitiveMethodServerStream) Recv() (string, error) { // RecvWithContext reads instances of "string" from the // "StreamingPayloadPrimitiveMethod" endpoint websocket connection with context. -func (s *StreamingPayloadPrimitiveMethodServerStream) RecvWithContext(ctx context.Context) (string, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *StreamingPayloadPrimitiveMethodServerStream) RecvWithContext(ctx context.Context) (string, error) { + return s.Recv() } ` @@ -2061,8 +2038,8 @@ func (s *StreamingPayloadPrimitiveMethodClientStream) Send(v string) error { // SendWithContext streams instances of "string" to the // "StreamingPayloadPrimitiveMethod" endpoint websocket connection with context. -func (s *StreamingPayloadPrimitiveMethodClientStream) SendWithContext(ctx context.Context, v string) (context.Context, error) { - return ctx, s.Send(v) +func (s *StreamingPayloadPrimitiveMethodClientStream) SendWithContext(ctx context.Context, v string) error { + return s.Send(v) } ` @@ -2094,9 +2071,8 @@ func (s *StreamingPayloadPrimitiveMethodClientStream) CloseAndRecv() (string, er // CloseAndRecvWithContext stops sending messages to the // "StreamingPayloadPrimitiveMethod" endpoint websocket connection and reads // instances of "string" from the connection with context. -func (s *StreamingPayloadPrimitiveMethodClientStream) CloseAndRecvWithContext(ctx context.Context) (string, context.Context, error) { - res, err := s.CloseAndRecv() - return res, ctx, err +func (s *StreamingPayloadPrimitiveMethodClientStream) CloseAndRecvWithContext(ctx context.Context) (string, error) { + return s.CloseAndRecv() } ` @@ -2112,8 +2088,8 @@ func (s *StreamingPayloadPrimitiveArrayMethodServerStream) SendAndClose(v []stri // SendAndCloseWithContext streams instances of "[]string" to the // "StreamingPayloadPrimitiveArrayMethod" endpoint websocket connection with // context and closes the connection. -func (s *StreamingPayloadPrimitiveArrayMethodServerStream) SendAndCloseWithContext(ctx context.Context, v []string) (context.Context, error) { - return ctx, s.SendAndClose(v) +func (s *StreamingPayloadPrimitiveArrayMethodServerStream) SendAndCloseWithContext(ctx context.Context, v []string) error { + return s.SendAndClose(v) } ` @@ -2154,9 +2130,8 @@ func (s *StreamingPayloadPrimitiveArrayMethodServerStream) Recv() ([]int32, erro // RecvWithContext reads instances of "[]int32" from the // "StreamingPayloadPrimitiveArrayMethod" endpoint websocket connection with // context. -func (s *StreamingPayloadPrimitiveArrayMethodServerStream) RecvWithContext(ctx context.Context) ([]int32, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *StreamingPayloadPrimitiveArrayMethodServerStream) RecvWithContext(ctx context.Context) ([]int32, error) { + return s.Recv() } ` @@ -2169,8 +2144,8 @@ func (s *StreamingPayloadPrimitiveArrayMethodClientStream) Send(v []int32) error // SendWithContext streams instances of "[]int32" to the // "StreamingPayloadPrimitiveArrayMethod" endpoint websocket connection with // context. -func (s *StreamingPayloadPrimitiveArrayMethodClientStream) SendWithContext(ctx context.Context, v []int32) (context.Context, error) { - return ctx, s.Send(v) +func (s *StreamingPayloadPrimitiveArrayMethodClientStream) SendWithContext(ctx context.Context, v []int32) error { + return s.Send(v) } ` @@ -2202,9 +2177,8 @@ func (s *StreamingPayloadPrimitiveArrayMethodClientStream) CloseAndRecv() ([]str // CloseAndRecvWithContext stops sending messages to the // "StreamingPayloadPrimitiveArrayMethod" endpoint websocket connection and // reads instances of "[]string" from the connection with context. -func (s *StreamingPayloadPrimitiveArrayMethodClientStream) CloseAndRecvWithContext(ctx context.Context) ([]string, context.Context, error) { - res, err := s.CloseAndRecv() - return res, ctx, err +func (s *StreamingPayloadPrimitiveArrayMethodClientStream) CloseAndRecvWithContext(ctx context.Context) ([]string, error) { + return s.CloseAndRecv() } ` @@ -2220,8 +2194,8 @@ func (s *StreamingPayloadPrimitiveMapMethodServerStream) SendAndClose(v map[int] // SendAndCloseWithContext streams instances of "map[int]int" to the // "StreamingPayloadPrimitiveMapMethod" endpoint websocket connection with // context and closes the connection. -func (s *StreamingPayloadPrimitiveMapMethodServerStream) SendAndCloseWithContext(ctx context.Context, v map[int]int) (context.Context, error) { - return ctx, s.SendAndClose(v) +func (s *StreamingPayloadPrimitiveMapMethodServerStream) SendAndCloseWithContext(ctx context.Context, v map[int]int) error { + return s.SendAndClose(v) } ` @@ -2262,9 +2236,8 @@ func (s *StreamingPayloadPrimitiveMapMethodServerStream) Recv() (map[string]int3 // RecvWithContext reads instances of "map[string]int32" from the // "StreamingPayloadPrimitiveMapMethod" endpoint websocket connection with // context. -func (s *StreamingPayloadPrimitiveMapMethodServerStream) RecvWithContext(ctx context.Context) (map[string]int32, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *StreamingPayloadPrimitiveMapMethodServerStream) RecvWithContext(ctx context.Context) (map[string]int32, error) { + return s.Recv() } ` @@ -2277,8 +2250,8 @@ func (s *StreamingPayloadPrimitiveMapMethodClientStream) Send(v map[string]int32 // SendWithContext streams instances of "map[string]int32" to the // "StreamingPayloadPrimitiveMapMethod" endpoint websocket connection with // context. -func (s *StreamingPayloadPrimitiveMapMethodClientStream) SendWithContext(ctx context.Context, v map[string]int32) (context.Context, error) { - return ctx, s.Send(v) +func (s *StreamingPayloadPrimitiveMapMethodClientStream) SendWithContext(ctx context.Context, v map[string]int32) error { + return s.Send(v) } ` @@ -2310,9 +2283,8 @@ func (s *StreamingPayloadPrimitiveMapMethodClientStream) CloseAndRecv() (map[int // CloseAndRecvWithContext stops sending messages to the // "StreamingPayloadPrimitiveMapMethod" endpoint websocket connection and reads // instances of "map[int]int" from the connection with context. -func (s *StreamingPayloadPrimitiveMapMethodClientStream) CloseAndRecvWithContext(ctx context.Context) (map[int]int, context.Context, error) { - res, err := s.CloseAndRecv() - return res, ctx, err +func (s *StreamingPayloadPrimitiveMapMethodClientStream) CloseAndRecvWithContext(ctx context.Context) (map[int]int, error) { + return s.CloseAndRecv() } ` @@ -2328,8 +2300,8 @@ func (s *StreamingPayloadUserTypeArrayMethodServerStream) SendAndClose(v string) // SendAndCloseWithContext streams instances of "string" to the // "StreamingPayloadUserTypeArrayMethod" endpoint websocket connection with // context and closes the connection. -func (s *StreamingPayloadUserTypeArrayMethodServerStream) SendAndCloseWithContext(ctx context.Context, v string) (context.Context, error) { - return ctx, s.SendAndClose(v) +func (s *StreamingPayloadUserTypeArrayMethodServerStream) SendAndCloseWithContext(ctx context.Context, v string) error { + return s.SendAndClose(v) } ` @@ -2372,9 +2344,8 @@ func (s *StreamingPayloadUserTypeArrayMethodServerStream) Recv() ([]*streamingpa // "[]*streamingpayloadusertypearrayservice.RequestType" from the // "StreamingPayloadUserTypeArrayMethod" endpoint websocket connection with // context. -func (s *StreamingPayloadUserTypeArrayMethodServerStream) RecvWithContext(ctx context.Context) ([]*streamingpayloadusertypearrayservice.RequestType, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *StreamingPayloadUserTypeArrayMethodServerStream) RecvWithContext(ctx context.Context) ([]*streamingpayloadusertypearrayservice.RequestType, error) { + return s.Recv() } ` @@ -2390,8 +2361,8 @@ func (s *StreamingPayloadUserTypeArrayMethodClientStream) Send(v []*streamingpay // "[]*streamingpayloadusertypearrayservice.RequestType" to the // "StreamingPayloadUserTypeArrayMethod" endpoint websocket connection with // context. -func (s *StreamingPayloadUserTypeArrayMethodClientStream) SendWithContext(ctx context.Context, v []*streamingpayloadusertypearrayservice.RequestType) (context.Context, error) { - return ctx, s.Send(v) +func (s *StreamingPayloadUserTypeArrayMethodClientStream) SendWithContext(ctx context.Context, v []*streamingpayloadusertypearrayservice.RequestType) error { + return s.Send(v) } ` @@ -2423,9 +2394,8 @@ func (s *StreamingPayloadUserTypeArrayMethodClientStream) CloseAndRecv() (string // CloseAndRecvWithContext stops sending messages to the // "StreamingPayloadUserTypeArrayMethod" endpoint websocket connection and // reads instances of "string" from the connection with context. -func (s *StreamingPayloadUserTypeArrayMethodClientStream) CloseAndRecvWithContext(ctx context.Context) (string, context.Context, error) { - res, err := s.CloseAndRecv() - return res, ctx, err +func (s *StreamingPayloadUserTypeArrayMethodClientStream) CloseAndRecvWithContext(ctx context.Context) (string, error) { + return s.CloseAndRecv() } ` @@ -2441,8 +2411,8 @@ func (s *StreamingPayloadUserTypeMapMethodServerStream) SendAndClose(v []string) // SendAndCloseWithContext streams instances of "[]string" to the // "StreamingPayloadUserTypeMapMethod" endpoint websocket connection with // context and closes the connection. -func (s *StreamingPayloadUserTypeMapMethodServerStream) SendAndCloseWithContext(ctx context.Context, v []string) (context.Context, error) { - return ctx, s.SendAndClose(v) +func (s *StreamingPayloadUserTypeMapMethodServerStream) SendAndCloseWithContext(ctx context.Context, v []string) error { + return s.SendAndClose(v) } ` @@ -2485,9 +2455,8 @@ func (s *StreamingPayloadUserTypeMapMethodServerStream) Recv() (map[string]*stre // "map[string]*streamingpayloadusertypemapservice.RequestType" from the // "StreamingPayloadUserTypeMapMethod" endpoint websocket connection with // context. -func (s *StreamingPayloadUserTypeMapMethodServerStream) RecvWithContext(ctx context.Context) (map[string]*streamingpayloadusertypemapservice.RequestType, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *StreamingPayloadUserTypeMapMethodServerStream) RecvWithContext(ctx context.Context) (map[string]*streamingpayloadusertypemapservice.RequestType, error) { + return s.Recv() } ` @@ -2503,8 +2472,8 @@ func (s *StreamingPayloadUserTypeMapMethodClientStream) Send(v map[string]*strea // "map[string]*streamingpayloadusertypemapservice.RequestType" to the // "StreamingPayloadUserTypeMapMethod" endpoint websocket connection with // context. -func (s *StreamingPayloadUserTypeMapMethodClientStream) SendWithContext(ctx context.Context, v map[string]*streamingpayloadusertypemapservice.RequestType) (context.Context, error) { - return ctx, s.Send(v) +func (s *StreamingPayloadUserTypeMapMethodClientStream) SendWithContext(ctx context.Context, v map[string]*streamingpayloadusertypemapservice.RequestType) error { + return s.Send(v) } ` @@ -2536,9 +2505,8 @@ func (s *StreamingPayloadUserTypeMapMethodClientStream) CloseAndRecv() ([]string // CloseAndRecvWithContext stops sending messages to the // "StreamingPayloadUserTypeMapMethod" endpoint websocket connection and reads // instances of "[]string" from the connection with context. -func (s *StreamingPayloadUserTypeMapMethodClientStream) CloseAndRecvWithContext(ctx context.Context) ([]string, context.Context, error) { - res, err := s.CloseAndRecv() - return res, ctx, err +func (s *StreamingPayloadUserTypeMapMethodClientStream) CloseAndRecvWithContext(ctx context.Context) ([]string, error) { + return s.CloseAndRecv() } ` @@ -2627,8 +2595,8 @@ func (s *BidirectionalStreamingMethodServerStream) Send(v *bidirectionalstreamin // SendWithContext streams instances of // "bidirectionalstreamingservice.UserType" to the // "BidirectionalStreamingMethod" endpoint websocket connection with context. -func (s *BidirectionalStreamingMethodServerStream) SendWithContext(ctx context.Context, v *bidirectionalstreamingservice.UserType) (context.Context, error) { - return ctx, s.Send(v) +func (s *BidirectionalStreamingMethodServerStream) SendWithContext(ctx context.Context, v *bidirectionalstreamingservice.UserType) error { + return s.Send(v) } ` @@ -2669,9 +2637,8 @@ func (s *BidirectionalStreamingMethodServerStream) Recv() (*bidirectionalstreami // RecvWithContext reads instances of "bidirectionalstreamingservice.Request" // from the "BidirectionalStreamingMethod" endpoint websocket connection with // context. -func (s *BidirectionalStreamingMethodServerStream) RecvWithContext(ctx context.Context) (*bidirectionalstreamingservice.Request, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *BidirectionalStreamingMethodServerStream) RecvWithContext(ctx context.Context) (*bidirectionalstreamingservice.Request, error) { + return s.Recv() } ` @@ -2736,8 +2703,8 @@ func (s *BidirectionalStreamingMethodClientStream) Send(v *bidirectionalstreamin // SendWithContext streams instances of "bidirectionalstreamingservice.Request" // to the "BidirectionalStreamingMethod" endpoint websocket connection with // context. -func (s *BidirectionalStreamingMethodClientStream) SendWithContext(ctx context.Context, v *bidirectionalstreamingservice.Request) (context.Context, error) { - return ctx, s.Send(v) +func (s *BidirectionalStreamingMethodClientStream) SendWithContext(ctx context.Context, v *bidirectionalstreamingservice.Request) error { + return s.Send(v) } ` @@ -2763,9 +2730,8 @@ func (s *BidirectionalStreamingMethodClientStream) Recv() (*bidirectionalstreami // RecvWithContext reads instances of "bidirectionalstreamingservice.UserType" // from the "BidirectionalStreamingMethod" endpoint websocket connection with // context. -func (s *BidirectionalStreamingMethodClientStream) RecvWithContext(ctx context.Context) (*bidirectionalstreamingservice.UserType, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *BidirectionalStreamingMethodClientStream) RecvWithContext(ctx context.Context) (*bidirectionalstreamingservice.UserType, error) { + return s.Recv() } ` @@ -2887,8 +2853,8 @@ func (s *BidirectionalStreamingNoPayloadMethodClientStream) Send(v *bidirectiona // "bidirectionalstreamingnopayloadservice.Request" to the // "BidirectionalStreamingNoPayloadMethod" endpoint websocket connection with // context. -func (s *BidirectionalStreamingNoPayloadMethodClientStream) SendWithContext(ctx context.Context, v *bidirectionalstreamingnopayloadservice.Request) (context.Context, error) { - return ctx, s.Send(v) +func (s *BidirectionalStreamingNoPayloadMethodClientStream) SendWithContext(ctx context.Context, v *bidirectionalstreamingnopayloadservice.Request) error { + return s.Send(v) } ` @@ -2916,9 +2882,8 @@ func (s *BidirectionalStreamingNoPayloadMethodClientStream) Recv() (*bidirection // "bidirectionalstreamingnopayloadservice.UserType" from the // "BidirectionalStreamingNoPayloadMethod" endpoint websocket connection with // context. -func (s *BidirectionalStreamingNoPayloadMethodClientStream) RecvWithContext(ctx context.Context) (*bidirectionalstreamingnopayloadservice.UserType, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *BidirectionalStreamingNoPayloadMethodClientStream) RecvWithContext(ctx context.Context) (*bidirectionalstreamingnopayloadservice.UserType, error) { + return s.Recv() } ` @@ -2975,8 +2940,8 @@ func (s *BidirectionalStreamingResultWithViewsMethodServerStream) Send(v *bidire // "bidirectionalstreamingresultwithviewsservice.Usertype" to the // "BidirectionalStreamingResultWithViewsMethod" endpoint websocket connection // with context. -func (s *BidirectionalStreamingResultWithViewsMethodServerStream) SendWithContext(ctx context.Context, v *bidirectionalstreamingresultwithviewsservice.Usertype) (context.Context, error) { - return ctx, s.Send(v) +func (s *BidirectionalStreamingResultWithViewsMethodServerStream) SendWithContext(ctx context.Context, v *bidirectionalstreamingresultwithviewsservice.Usertype) error { + return s.Send(v) } ` @@ -3017,9 +2982,8 @@ func (s *BidirectionalStreamingResultWithViewsMethodServerStream) Recv() (float3 // RecvWithContext reads instances of "float32" from the // "BidirectionalStreamingResultWithViewsMethod" endpoint websocket connection // with context. -func (s *BidirectionalStreamingResultWithViewsMethodServerStream) RecvWithContext(ctx context.Context) (float32, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *BidirectionalStreamingResultWithViewsMethodServerStream) RecvWithContext(ctx context.Context) (float32, error) { + return s.Recv() } ` @@ -3059,8 +3023,8 @@ func (s *BidirectionalStreamingResultWithViewsMethodClientStream) Send(v float32 // SendWithContext streams instances of "float32" to the // "BidirectionalStreamingResultWithViewsMethod" endpoint websocket connection // with context. -func (s *BidirectionalStreamingResultWithViewsMethodClientStream) SendWithContext(ctx context.Context, v float32) (context.Context, error) { - return ctx, s.Send(v) +func (s *BidirectionalStreamingResultWithViewsMethodClientStream) SendWithContext(ctx context.Context, v float32) error { + return s.Send(v) } ` @@ -3092,9 +3056,8 @@ func (s *BidirectionalStreamingResultWithViewsMethodClientStream) Recv() (*bidir // "bidirectionalstreamingresultwithviewsservice.Usertype" from the // "BidirectionalStreamingResultWithViewsMethod" endpoint websocket connection // with context. -func (s *BidirectionalStreamingResultWithViewsMethodClientStream) RecvWithContext(ctx context.Context) (*bidirectionalstreamingresultwithviewsservice.Usertype, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *BidirectionalStreamingResultWithViewsMethodClientStream) RecvWithContext(ctx context.Context) (*bidirectionalstreamingresultwithviewsservice.Usertype, error) { + return s.Recv() } ` @@ -3149,8 +3112,8 @@ func (s *BidirectionalStreamingResultWithExplicitViewMethodServerStream) Send(v // "bidirectionalstreamingresultwithexplicitviewservice.Usertype" to the // "BidirectionalStreamingResultWithExplicitViewMethod" endpoint websocket // connection with context. -func (s *BidirectionalStreamingResultWithExplicitViewMethodServerStream) SendWithContext(ctx context.Context, v *bidirectionalstreamingresultwithexplicitviewservice.Usertype) (context.Context, error) { - return ctx, s.Send(v) +func (s *BidirectionalStreamingResultWithExplicitViewMethodServerStream) SendWithContext(ctx context.Context, v *bidirectionalstreamingresultwithexplicitviewservice.Usertype) error { + return s.Send(v) } ` @@ -3192,9 +3155,8 @@ func (s *BidirectionalStreamingResultWithExplicitViewMethodServerStream) Recv() // RecvWithContext reads instances of "float32" from the // "BidirectionalStreamingResultWithExplicitViewMethod" endpoint websocket // connection with context. -func (s *BidirectionalStreamingResultWithExplicitViewMethodServerStream) RecvWithContext(ctx context.Context) (float32, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *BidirectionalStreamingResultWithExplicitViewMethodServerStream) RecvWithContext(ctx context.Context) (float32, error) { + return s.Recv() } ` @@ -3208,8 +3170,8 @@ func (s *BidirectionalStreamingResultWithExplicitViewMethodClientStream) Send(v // SendWithContext streams instances of "float32" to the // "BidirectionalStreamingResultWithExplicitViewMethod" endpoint websocket // connection with context. -func (s *BidirectionalStreamingResultWithExplicitViewMethodClientStream) SendWithContext(ctx context.Context, v float32) (context.Context, error) { - return ctx, s.Send(v) +func (s *BidirectionalStreamingResultWithExplicitViewMethodClientStream) SendWithContext(ctx context.Context, v float32) error { + return s.Send(v) } ` @@ -3242,9 +3204,8 @@ func (s *BidirectionalStreamingResultWithExplicitViewMethodClientStream) Recv() // "bidirectionalstreamingresultwithexplicitviewservice.Usertype" from the // "BidirectionalStreamingResultWithExplicitViewMethod" endpoint websocket // connection with context. -func (s *BidirectionalStreamingResultWithExplicitViewMethodClientStream) RecvWithContext(ctx context.Context) (*bidirectionalstreamingresultwithexplicitviewservice.Usertype, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *BidirectionalStreamingResultWithExplicitViewMethodClientStream) RecvWithContext(ctx context.Context) (*bidirectionalstreamingresultwithexplicitviewservice.Usertype, error) { + return s.Recv() } ` @@ -3290,8 +3251,8 @@ func (s *BidirectionalStreamingResultCollectionWithViewsMethodServerStream) Send // "bidirectionalstreamingresultcollectionwithviewsservice.UsertypeCollection" // to the "BidirectionalStreamingResultCollectionWithViewsMethod" endpoint // websocket connection with context. -func (s *BidirectionalStreamingResultCollectionWithViewsMethodServerStream) SendWithContext(ctx context.Context, v bidirectionalstreamingresultcollectionwithviewsservice.UsertypeCollection) (context.Context, error) { - return ctx, s.Send(v) +func (s *BidirectionalStreamingResultCollectionWithViewsMethodServerStream) SendWithContext(ctx context.Context, v bidirectionalstreamingresultcollectionwithviewsservice.UsertypeCollection) error { + return s.Send(v) } ` @@ -3333,9 +3294,8 @@ func (s *BidirectionalStreamingResultCollectionWithViewsMethodServerStream) Recv // RecvWithContext reads instances of "any" from the // "BidirectionalStreamingResultCollectionWithViewsMethod" endpoint websocket // connection with context. -func (s *BidirectionalStreamingResultCollectionWithViewsMethodServerStream) RecvWithContext(ctx context.Context) (any, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *BidirectionalStreamingResultCollectionWithViewsMethodServerStream) RecvWithContext(ctx context.Context) (any, error) { + return s.Recv() } ` @@ -3359,8 +3319,8 @@ func (s *BidirectionalStreamingResultCollectionWithViewsMethodClientStream) Send // SendWithContext streams instances of "any" to the // "BidirectionalStreamingResultCollectionWithViewsMethod" endpoint websocket // connection with context. -func (s *BidirectionalStreamingResultCollectionWithViewsMethodClientStream) SendWithContext(ctx context.Context, v any) (context.Context, error) { - return ctx, s.Send(v) +func (s *BidirectionalStreamingResultCollectionWithViewsMethodClientStream) SendWithContext(ctx context.Context, v any) error { + return s.Send(v) } ` @@ -3393,9 +3353,8 @@ func (s *BidirectionalStreamingResultCollectionWithViewsMethodClientStream) Recv // "bidirectionalstreamingresultcollectionwithviewsservice.UsertypeCollection" // from the "BidirectionalStreamingResultCollectionWithViewsMethod" endpoint // websocket connection with context. -func (s *BidirectionalStreamingResultCollectionWithViewsMethodClientStream) RecvWithContext(ctx context.Context) (bidirectionalstreamingresultcollectionwithviewsservice.UsertypeCollection, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *BidirectionalStreamingResultCollectionWithViewsMethodClientStream) RecvWithContext(ctx context.Context) (bidirectionalstreamingresultcollectionwithviewsservice.UsertypeCollection, error) { + return s.Recv() } ` @@ -3439,8 +3398,8 @@ func (s *BidirectionalStreamingResultCollectionWithExplicitViewMethodServerStrea // "bidirectionalstreamingresultcollectionwithexplicitviewservice.UsertypeCollection" // to the "BidirectionalStreamingResultCollectionWithExplicitViewMethod" // endpoint websocket connection with context. -func (s *BidirectionalStreamingResultCollectionWithExplicitViewMethodServerStream) SendWithContext(ctx context.Context, v bidirectionalstreamingresultcollectionwithexplicitviewservice.UsertypeCollection) (context.Context, error) { - return ctx, s.Send(v) +func (s *BidirectionalStreamingResultCollectionWithExplicitViewMethodServerStream) SendWithContext(ctx context.Context, v bidirectionalstreamingresultcollectionwithexplicitviewservice.UsertypeCollection) error { + return s.Send(v) } ` @@ -3482,9 +3441,8 @@ func (s *BidirectionalStreamingResultCollectionWithExplicitViewMethodServerStrea // RecvWithContext reads instances of "any" from the // "BidirectionalStreamingResultCollectionWithExplicitViewMethod" endpoint // websocket connection with context. -func (s *BidirectionalStreamingResultCollectionWithExplicitViewMethodServerStream) RecvWithContext(ctx context.Context) (any, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *BidirectionalStreamingResultCollectionWithExplicitViewMethodServerStream) RecvWithContext(ctx context.Context) (any, error) { + return s.Recv() } ` @@ -3498,8 +3456,8 @@ func (s *BidirectionalStreamingResultCollectionWithExplicitViewMethodClientStrea // SendWithContext streams instances of "any" to the // "BidirectionalStreamingResultCollectionWithExplicitViewMethod" endpoint // websocket connection with context. -func (s *BidirectionalStreamingResultCollectionWithExplicitViewMethodClientStream) SendWithContext(ctx context.Context, v any) (context.Context, error) { - return ctx, s.Send(v) +func (s *BidirectionalStreamingResultCollectionWithExplicitViewMethodClientStream) SendWithContext(ctx context.Context, v any) error { + return s.Send(v) } ` @@ -3532,9 +3490,8 @@ func (s *BidirectionalStreamingResultCollectionWithExplicitViewMethodClientStrea // "bidirectionalstreamingresultcollectionwithexplicitviewservice.UsertypeCollection" // from the "BidirectionalStreamingResultCollectionWithExplicitViewMethod" // endpoint websocket connection with context. -func (s *BidirectionalStreamingResultCollectionWithExplicitViewMethodClientStream) RecvWithContext(ctx context.Context) (bidirectionalstreamingresultcollectionwithexplicitviewservice.UsertypeCollection, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *BidirectionalStreamingResultCollectionWithExplicitViewMethodClientStream) RecvWithContext(ctx context.Context) (bidirectionalstreamingresultcollectionwithexplicitviewservice.UsertypeCollection, error) { + return s.Recv() } ` @@ -3566,8 +3523,8 @@ func (s *BidirectionalStreamingPrimitiveMethodServerStream) Send(v string) error // SendWithContext streams instances of "string" to the // "BidirectionalStreamingPrimitiveMethod" endpoint websocket connection with // context. -func (s *BidirectionalStreamingPrimitiveMethodServerStream) SendWithContext(ctx context.Context, v string) (context.Context, error) { - return ctx, s.Send(v) +func (s *BidirectionalStreamingPrimitiveMethodServerStream) SendWithContext(ctx context.Context, v string) error { + return s.Send(v) } ` @@ -3608,9 +3565,8 @@ func (s *BidirectionalStreamingPrimitiveMethodServerStream) Recv() (string, erro // RecvWithContext reads instances of "string" from the // "BidirectionalStreamingPrimitiveMethod" endpoint websocket connection with // context. -func (s *BidirectionalStreamingPrimitiveMethodServerStream) RecvWithContext(ctx context.Context) (string, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *BidirectionalStreamingPrimitiveMethodServerStream) RecvWithContext(ctx context.Context) (string, error) { + return s.Recv() } ` @@ -3623,8 +3579,8 @@ func (s *BidirectionalStreamingPrimitiveMethodClientStream) Send(v string) error // SendWithContext streams instances of "string" to the // "BidirectionalStreamingPrimitiveMethod" endpoint websocket connection with // context. -func (s *BidirectionalStreamingPrimitiveMethodClientStream) SendWithContext(ctx context.Context, v string) (context.Context, error) { - return ctx, s.Send(v) +func (s *BidirectionalStreamingPrimitiveMethodClientStream) SendWithContext(ctx context.Context, v string) error { + return s.Send(v) } ` @@ -3649,9 +3605,8 @@ func (s *BidirectionalStreamingPrimitiveMethodClientStream) Recv() (string, erro // RecvWithContext reads instances of "string" from the // "BidirectionalStreamingPrimitiveMethod" endpoint websocket connection with // context. -func (s *BidirectionalStreamingPrimitiveMethodClientStream) RecvWithContext(ctx context.Context) (string, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *BidirectionalStreamingPrimitiveMethodClientStream) RecvWithContext(ctx context.Context) (string, error) { + return s.Recv() } ` @@ -3683,8 +3638,8 @@ func (s *BidirectionalStreamingPrimitiveArrayMethodServerStream) Send(v []string // SendWithContext streams instances of "[]string" to the // "BidirectionalStreamingPrimitiveArrayMethod" endpoint websocket connection // with context. -func (s *BidirectionalStreamingPrimitiveArrayMethodServerStream) SendWithContext(ctx context.Context, v []string) (context.Context, error) { - return ctx, s.Send(v) +func (s *BidirectionalStreamingPrimitiveArrayMethodServerStream) SendWithContext(ctx context.Context, v []string) error { + return s.Send(v) } ` @@ -3725,9 +3680,8 @@ func (s *BidirectionalStreamingPrimitiveArrayMethodServerStream) Recv() ([]int32 // RecvWithContext reads instances of "[]int32" from the // "BidirectionalStreamingPrimitiveArrayMethod" endpoint websocket connection // with context. -func (s *BidirectionalStreamingPrimitiveArrayMethodServerStream) RecvWithContext(ctx context.Context) ([]int32, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *BidirectionalStreamingPrimitiveArrayMethodServerStream) RecvWithContext(ctx context.Context) ([]int32, error) { + return s.Recv() } ` @@ -3740,8 +3694,8 @@ func (s *BidirectionalStreamingPrimitiveArrayMethodClientStream) Send(v []int32) // SendWithContext streams instances of "[]int32" to the // "BidirectionalStreamingPrimitiveArrayMethod" endpoint websocket connection // with context. -func (s *BidirectionalStreamingPrimitiveArrayMethodClientStream) SendWithContext(ctx context.Context, v []int32) (context.Context, error) { - return ctx, s.Send(v) +func (s *BidirectionalStreamingPrimitiveArrayMethodClientStream) SendWithContext(ctx context.Context, v []int32) error { + return s.Send(v) } ` @@ -3766,9 +3720,8 @@ func (s *BidirectionalStreamingPrimitiveArrayMethodClientStream) Recv() ([]strin // RecvWithContext reads instances of "[]string" from the // "BidirectionalStreamingPrimitiveArrayMethod" endpoint websocket connection // with context. -func (s *BidirectionalStreamingPrimitiveArrayMethodClientStream) RecvWithContext(ctx context.Context) ([]string, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *BidirectionalStreamingPrimitiveArrayMethodClientStream) RecvWithContext(ctx context.Context) ([]string, error) { + return s.Recv() } ` @@ -3800,8 +3753,8 @@ func (s *BidirectionalStreamingPrimitiveMapMethodServerStream) Send(v map[int]in // SendWithContext streams instances of "map[int]int" to the // "BidirectionalStreamingPrimitiveMapMethod" endpoint websocket connection // with context. -func (s *BidirectionalStreamingPrimitiveMapMethodServerStream) SendWithContext(ctx context.Context, v map[int]int) (context.Context, error) { - return ctx, s.Send(v) +func (s *BidirectionalStreamingPrimitiveMapMethodServerStream) SendWithContext(ctx context.Context, v map[int]int) error { + return s.Send(v) } ` @@ -3842,9 +3795,8 @@ func (s *BidirectionalStreamingPrimitiveMapMethodServerStream) Recv() (map[strin // RecvWithContext reads instances of "map[string]int32" from the // "BidirectionalStreamingPrimitiveMapMethod" endpoint websocket connection // with context. -func (s *BidirectionalStreamingPrimitiveMapMethodServerStream) RecvWithContext(ctx context.Context) (map[string]int32, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *BidirectionalStreamingPrimitiveMapMethodServerStream) RecvWithContext(ctx context.Context) (map[string]int32, error) { + return s.Recv() } ` @@ -3857,8 +3809,8 @@ func (s *BidirectionalStreamingPrimitiveMapMethodClientStream) Send(v map[string // SendWithContext streams instances of "map[string]int32" to the // "BidirectionalStreamingPrimitiveMapMethod" endpoint websocket connection // with context. -func (s *BidirectionalStreamingPrimitiveMapMethodClientStream) SendWithContext(ctx context.Context, v map[string]int32) (context.Context, error) { - return ctx, s.Send(v) +func (s *BidirectionalStreamingPrimitiveMapMethodClientStream) SendWithContext(ctx context.Context, v map[string]int32) error { + return s.Send(v) } ` @@ -3883,9 +3835,8 @@ func (s *BidirectionalStreamingPrimitiveMapMethodClientStream) Recv() (map[int]i // RecvWithContext reads instances of "map[int]int" from the // "BidirectionalStreamingPrimitiveMapMethod" endpoint websocket connection // with context. -func (s *BidirectionalStreamingPrimitiveMapMethodClientStream) RecvWithContext(ctx context.Context) (map[int]int, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *BidirectionalStreamingPrimitiveMapMethodClientStream) RecvWithContext(ctx context.Context) (map[int]int, error) { + return s.Recv() } ` @@ -3920,8 +3871,8 @@ func (s *BidirectionalStreamingUserTypeArrayMethodServerStream) Send(v []*bidire // "[]*bidirectionalstreamingusertypearrayservice.ResultType" to the // "BidirectionalStreamingUserTypeArrayMethod" endpoint websocket connection // with context. -func (s *BidirectionalStreamingUserTypeArrayMethodServerStream) SendWithContext(ctx context.Context, v []*bidirectionalstreamingusertypearrayservice.ResultType) (context.Context, error) { - return ctx, s.Send(v) +func (s *BidirectionalStreamingUserTypeArrayMethodServerStream) SendWithContext(ctx context.Context, v []*bidirectionalstreamingusertypearrayservice.ResultType) error { + return s.Send(v) } ` @@ -3964,9 +3915,8 @@ func (s *BidirectionalStreamingUserTypeArrayMethodServerStream) Recv() ([]*bidir // "[]*bidirectionalstreamingusertypearrayservice.RequestType" from the // "BidirectionalStreamingUserTypeArrayMethod" endpoint websocket connection // with context. -func (s *BidirectionalStreamingUserTypeArrayMethodServerStream) RecvWithContext(ctx context.Context) ([]*bidirectionalstreamingusertypearrayservice.RequestType, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *BidirectionalStreamingUserTypeArrayMethodServerStream) RecvWithContext(ctx context.Context) ([]*bidirectionalstreamingusertypearrayservice.RequestType, error) { + return s.Recv() } ` @@ -3982,8 +3932,8 @@ func (s *BidirectionalStreamingUserTypeArrayMethodClientStream) Send(v []*bidire // "[]*bidirectionalstreamingusertypearrayservice.RequestType" to the // "BidirectionalStreamingUserTypeArrayMethod" endpoint websocket connection // with context. -func (s *BidirectionalStreamingUserTypeArrayMethodClientStream) SendWithContext(ctx context.Context, v []*bidirectionalstreamingusertypearrayservice.RequestType) (context.Context, error) { - return ctx, s.Send(v) +func (s *BidirectionalStreamingUserTypeArrayMethodClientStream) SendWithContext(ctx context.Context, v []*bidirectionalstreamingusertypearrayservice.RequestType) error { + return s.Send(v) } ` @@ -4011,9 +3961,8 @@ func (s *BidirectionalStreamingUserTypeArrayMethodClientStream) Recv() ([]*bidir // "[]*bidirectionalstreamingusertypearrayservice.ResultType" from the // "BidirectionalStreamingUserTypeArrayMethod" endpoint websocket connection // with context. -func (s *BidirectionalStreamingUserTypeArrayMethodClientStream) RecvWithContext(ctx context.Context) ([]*bidirectionalstreamingusertypearrayservice.ResultType, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *BidirectionalStreamingUserTypeArrayMethodClientStream) RecvWithContext(ctx context.Context) ([]*bidirectionalstreamingusertypearrayservice.ResultType, error) { + return s.Recv() } ` @@ -4048,8 +3997,8 @@ func (s *BidirectionalStreamingUserTypeMapMethodServerStream) Send(v map[string] // "map[string]*bidirectionalstreamingusertypemapservice.ResultType" to the // "BidirectionalStreamingUserTypeMapMethod" endpoint websocket connection with // context. -func (s *BidirectionalStreamingUserTypeMapMethodServerStream) SendWithContext(ctx context.Context, v map[string]*bidirectionalstreamingusertypemapservice.ResultType) (context.Context, error) { - return ctx, s.Send(v) +func (s *BidirectionalStreamingUserTypeMapMethodServerStream) SendWithContext(ctx context.Context, v map[string]*bidirectionalstreamingusertypemapservice.ResultType) error { + return s.Send(v) } ` @@ -4092,9 +4041,8 @@ func (s *BidirectionalStreamingUserTypeMapMethodServerStream) Recv() (map[string // "map[string]*bidirectionalstreamingusertypemapservice.RequestType" from the // "BidirectionalStreamingUserTypeMapMethod" endpoint websocket connection with // context. -func (s *BidirectionalStreamingUserTypeMapMethodServerStream) RecvWithContext(ctx context.Context) (map[string]*bidirectionalstreamingusertypemapservice.RequestType, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *BidirectionalStreamingUserTypeMapMethodServerStream) RecvWithContext(ctx context.Context) (map[string]*bidirectionalstreamingusertypemapservice.RequestType, error) { + return s.Recv() } ` @@ -4110,8 +4058,8 @@ func (s *BidirectionalStreamingUserTypeMapMethodClientStream) Send(v map[string] // "map[string]*bidirectionalstreamingusertypemapservice.RequestType" to the // "BidirectionalStreamingUserTypeMapMethod" endpoint websocket connection with // context. -func (s *BidirectionalStreamingUserTypeMapMethodClientStream) SendWithContext(ctx context.Context, v map[string]*bidirectionalstreamingusertypemapservice.RequestType) (context.Context, error) { - return ctx, s.Send(v) +func (s *BidirectionalStreamingUserTypeMapMethodClientStream) SendWithContext(ctx context.Context, v map[string]*bidirectionalstreamingusertypemapservice.RequestType) error { + return s.Send(v) } ` @@ -4139,8 +4087,7 @@ func (s *BidirectionalStreamingUserTypeMapMethodClientStream) Recv() (map[string // "map[string]*bidirectionalstreamingusertypemapservice.ResultType" from the // "BidirectionalStreamingUserTypeMapMethod" endpoint websocket connection with // context. -func (s *BidirectionalStreamingUserTypeMapMethodClientStream) RecvWithContext(ctx context.Context) (map[string]*bidirectionalstreamingusertypemapservice.ResultType, context.Context, error) { - res, err := s.Recv() - return res, ctx, err +func (s *BidirectionalStreamingUserTypeMapMethodClientStream) RecvWithContext(ctx context.Context) (map[string]*bidirectionalstreamingusertypemapservice.ResultType, error) { + return s.Recv() } ` diff --git a/pkg/interceptor.go b/pkg/interceptor.go index ff9d9948e8..1c3abd1313 100644 --- a/pkg/interceptor.go +++ b/pkg/interceptor.go @@ -1,12 +1,10 @@ package goa -import "context" - type ( // InterceptorInfo contains information about the request shared between // all interceptors in the service chain. It provides access to the service name, // method name, the type of call the interceptor is handling (unary, streaming send, - // or streaming recv), and the request payload. + // or streaming receive), and the request payload. InterceptorInfo interface { // Service returns the name of the service handling the request. Service() string @@ -18,11 +16,6 @@ type ( RawPayload() any } - // InterceptorEndpoint is the endpoint function interface that interceptors call. It differs from the - // Endpoint function interface in that it also returns a context that allows streaming interceptors to - // return a context to the SendWithContext or RecvWithContext methods. - InterceptorEndpoint func(ctx context.Context, request any) (response any, returnCtx context.Context, err error) - // InterceptorCallType is the type of call the interceptor is handling InterceptorCallType int ) From edbbca88ff37de3b052a3e40098703bb07514ac2 Mon Sep 17 00:00:00 2001 From: Raphael Simon Date: Sat, 8 Feb 2025 13:30:58 -0800 Subject: [PATCH 22/23] Address lint issues --- codegen/cli/cli.go | 190 ++++----- codegen/service/service_data.go | 717 ++++++++++++++------------------ dsl/interceptor_test.go | 18 +- grpc/codegen/client_cli.go | 40 +- grpc/codegen/service_data.go | 681 +++++++++++++----------------- http/codegen/websocket.go | 193 ++++----- 6 files changed, 813 insertions(+), 1026 deletions(-) diff --git a/codegen/cli/cli.go b/codegen/cli/cli.go index 7e3c461acf..affdbfccd4 100644 --- a/codegen/cli/cli.go +++ b/codegen/cli/cli.go @@ -184,58 +184,50 @@ func BuildCommandData(data *service.Data) *CommandData { // BuildSubcommandData builds the data needed by CLI code generators to render // the CLI parsing of the service sub-command. func BuildSubcommandData(data *service.Data, m *service.MethodData, buildFunction *BuildFunctionData, flags []*FlagData) *SubcommandData { - var ( - name string - fullName string - description string - - conversion string - interceptors *InterceptorData - ) - { - en := m.Name - name = codegen.KebabCase(en) - fullName = goifyTerms(data.Name, en) - description = m.Description - if description == "" { - description = fmt.Sprintf("Make request to the %q endpoint", m.Name) + en := m.Name + name := codegen.KebabCase(en) + fullName := goifyTerms(data.Name, en) + description := m.Description + if description == "" { + description = fmt.Sprintf("Make request to the %q endpoint", m.Name) + } + + var conversion string + if m.Payload != "" && buildFunction == nil && len(flags) > 0 { + // No build function, just convert the arg to the body type + var convPre, convSuff string + target := "data" + if flagType(m.Payload) == "JSON" { + target = "val" + convPre = fmt.Sprintf("var val %s\n", m.Payload) + convSuff = "\ndata = val" } - - if m.Payload != "" && buildFunction == nil && len(flags) > 0 { - // No build function, just convert the arg to the body type - var convPre, convSuff string - target := "data" + conv, _, check := conversionCode( + "*"+flags[0].FullName+"Flag", + target, + m.Payload, + false, + ) + conversion = convPre + conv + convSuff + if check { + conversion = "var err error\n" + conversion + conversion += "\nif err != nil {\n" if flagType(m.Payload) == "JSON" { - target = "val" - convPre = fmt.Sprintf("var val %s\n", m.Payload) - convSuff = "\ndata = val" - } - conv, _, check := conversionCode( - "*"+flags[0].FullName+"Flag", - target, - m.Payload, - false, - ) - conversion = convPre + conv + convSuff - if check { - conversion = "var err error\n" + conversion - conversion += "\nif err != nil {\n" - if flagType(m.Payload) == "JSON" { - conversion += fmt.Sprintf(`return nil, nil, fmt.Errorf("invalid JSON for %s, \nerror: %%s, \nexample of valid JSON:\n%%s", err, %q)`, - flags[0].FullName+"Flag", flags[0].Example) - } else { - conversion += fmt.Sprintf(`return nil, nil, fmt.Errorf("invalid value for %s, must be %s")`, - flags[0].FullName+"Flag", flags[0].Type) - } - conversion += "\n}" + conversion += fmt.Sprintf(`return nil, nil, fmt.Errorf("invalid JSON for %s, \nerror: %%s, \nexample of valid JSON:\n%%s", err, %q)`, + flags[0].FullName+"Flag", flags[0].Example) + } else { + conversion += fmt.Sprintf(`return nil, nil, fmt.Errorf("invalid value for %s, must be %s")`, + flags[0].FullName+"Flag", flags[0].Type) } + conversion += "\n}" } + } - if len(m.ClientInterceptors) > 0 { - interceptors = &InterceptorData{ - VarName: "inter", - PkgName: data.PkgName, - } + var interceptors *InterceptorData + if len(m.ClientInterceptors) > 0 { + interceptors = &InterceptorData{ + VarName: "inter", + PkgName: data.PkgName, } } sub := &SubcommandData{ @@ -364,66 +356,64 @@ func FieldLoadCode(f *FlagData, argName, argTypeName, validate string, defaultVa startIf string endIf string ) - { - if !f.Required { - startIf = fmt.Sprintf("if %s != \"\" {\n", f.FullName) - endIf = "\n}" + if !f.Required { + startIf = fmt.Sprintf("if %s != \"\" {\n", f.FullName) + endIf = "\n}" + } + if argTypeName == codegen.GoNativeTypeName(expr.String) { + ref := "&" + if f.Required || defaultValue != nil { + ref = "" } - if argTypeName == codegen.GoNativeTypeName(expr.String) { - ref := "&" - if f.Required || defaultValue != nil { - ref = "" - } - code = argName + " = " + ref + f.FullName - declErr = validate != "" - } else { - var checkErr bool - code, declErr, checkErr = conversionCode(f.FullName, argName, argTypeName, !f.Required && defaultValue == nil) - if checkErr { - code += "\nif err != nil {\n" - nilVal := "nil" - if expr.IsPrimitive(payload) { - code += fmt.Sprintf("var zero %s\n", payloadRef) - nilVal = "zero" - } - if flagType(argTypeName) == "JSON" { - code += fmt.Sprintf(`return %s, fmt.Errorf("invalid JSON for %s, \nerror: %%s, \nexample of valid JSON:\n%%s", err, %q)`, - nilVal, argName, f.Example) - } else { - code += fmt.Sprintf(`return %s, fmt.Errorf("invalid value for %s, must be %s")`, - nilVal, argName, f.Type) - } - code += "\n}" - } - } - if validate != "" { - nilCheck := "if " + argName + " != nil {" - if strings.HasPrefix(validate, nilCheck) { - // hackety hack... the validation code is generated for the client and needs to - // account for the fact that the field could be nil in this case. We are reusing - // that code to validate a CLI flag which can never be nil. Lint tools complain - // about that so remove the if statements. Ideally we'd have a better way to do - // this but that requires a lot of changes and the added complexity might not be - // worth it. - var lines []string - ls := strings.Split(validate, "\n") - for i := 1; i < len(ls)-1; i++ { - if ls[i+1] == nilCheck { - i++ // skip both closing brace on previous line and check - continue - } - lines = append(lines, ls[i]) - } - validate = strings.Join(lines, "\n") - } - code += "\n" + validate + "\n" + code = argName + " = " + ref + f.FullName + declErr = validate != "" + } else { + var checkErr bool + code, declErr, checkErr = conversionCode(f.FullName, argName, argTypeName, !f.Required && defaultValue == nil) + if checkErr { + code += "\nif err != nil {\n" nilVal := "nil" if expr.IsPrimitive(payload) { code += fmt.Sprintf("var zero %s\n", payloadRef) nilVal = "zero" } - code += fmt.Sprintf("if err != nil {\n\treturn %s, err\n}", nilVal) + if flagType(argTypeName) == "JSON" { + code += fmt.Sprintf(`return %s, fmt.Errorf("invalid JSON for %s, \nerror: %%s, \nexample of valid JSON:\n%%s", err, %q)`, + nilVal, argName, f.Example) + } else { + code += fmt.Sprintf(`return %s, fmt.Errorf("invalid value for %s, must be %s")`, + nilVal, argName, f.Type) + } + code += "\n}" + } + } + if validate != "" { + nilCheck := "if " + argName + " != nil {" + if strings.HasPrefix(validate, nilCheck) { + // hackety hack... the validation code is generated for the client and needs to + // account for the fact that the field could be nil in this case. We are reusing + // that code to validate a CLI flag which can never be nil. Lint tools complain + // about that so remove the if statements. Ideally we'd have a better way to do + // this but that requires a lot of changes and the added complexity might not be + // worth it. + var lines []string + ls := strings.Split(validate, "\n") + for i := 1; i < len(ls)-1; i++ { + if ls[i+1] == nilCheck { + i++ // skip both closing brace on previous line and check + continue + } + lines = append(lines, ls[i]) + } + validate = strings.Join(lines, "\n") + } + code += "\n" + validate + "\n" + nilVal := "nil" + if expr.IsPrimitive(payload) { + code += fmt.Sprintf("var zero %s\n", payloadRef) + nilVal = "zero" } + code += fmt.Sprintf("if err != nil {\n\treturn %s, err\n}", nilVal) } return fmt.Sprintf("%s%s%s", startIf, code, endIf), declErr } diff --git a/codegen/service/service_data.go b/codegen/service/service_data.go index 195722f7bd..c552d30235 100644 --- a/codegen/service/service_data.go +++ b/codegen/service/service_data.go @@ -681,94 +681,83 @@ func (s SchemesData) Append(d *SchemeData) SchemesData { // It records the user types needed by the service definition in userTypes. func (d ServicesData) analyze(service *expr.ServiceExpr) *Data { var ( - scope *codegen.NameScope - viewScope *codegen.NameScope - pkgName string - viewspkg string types []*UserTypeData errTypes []*UserTypeData errorInits []*ErrorInitData projTypes []*ProjectedTypeData viewedUnionMeths []*UnionValueMethodData viewedRTs []*ViewedResultTypeData - seenErrors map[string]struct{} - seen map[string]struct{} - seenProj map[string]*ProjectedTypeData - seenViewed map[string]*ViewedResultTypeData ) - { - scope = codegen.NewNameScope() - scope.Unique("Use") // Reserve "Use" for Endpoints struct Use method. - viewScope = codegen.NewNameScope() - pkgName = scope.HashedUnique(service, strings.ToLower(codegen.Goify(service.Name, false)), "svc") - viewspkg = pkgName + "views" - seen = make(map[string]struct{}) - seenErrors = make(map[string]struct{}) - seenProj = make(map[string]*ProjectedTypeData) - seenViewed = make(map[string]*ViewedResultTypeData) - - // A function to collect user types from an error expression - recordError := func(er *expr.ErrorExpr) { - errTypes = append(errTypes, collectTypes(er.AttributeExpr, scope, seen)...) - if er.Type == expr.ErrorResult { - if _, ok := seenErrors[er.Name]; ok { - return - } - seenErrors[er.Name] = struct{}{} - errorInits = append(errorInits, buildErrorInitData(er, scope)) + scope := codegen.NewNameScope() + scope.Unique("Use") // Reserve "Use" for Endpoints struct Use method. + viewScope := codegen.NewNameScope() + pkgName := scope.HashedUnique(service, strings.ToLower(codegen.Goify(service.Name, false)), "svc") + viewspkg := pkgName + "views" + seen := make(map[string]struct{}) + seenErrors := make(map[string]struct{}) + seenProj := make(map[string]*ProjectedTypeData) + seenViewed := make(map[string]*ViewedResultTypeData) + + // A function to collect user types from an error expression + recordError := func(er *expr.ErrorExpr) { + errTypes = append(errTypes, collectTypes(er.AttributeExpr, scope, seen)...) + if er.Type == expr.ErrorResult { + if _, ok := seenErrors[er.Name]; ok { + return } + seenErrors[er.Name] = struct{}{} + errorInits = append(errorInits, buildErrorInitData(er, scope)) } - for _, er := range service.Errors { - recordError(er) - } + } + for _, er := range service.Errors { + recordError(er) + } - // A function to collect inner user types from an attribute expression - collectUserTypes := func(att *expr.AttributeExpr) { - if ut, ok := att.Type.(expr.UserType); ok { - att = ut.Attribute() - } - types = append(types, collectTypes(att, scope, seen)...) - } - for _, m := range service.Methods { - // collect inner user types - collectUserTypes(m.Payload) - collectUserTypes(m.StreamingPayload) - collectUserTypes(m.Result) - // Collect projected types - if hasResultType(m.Result) { - types, umeths := collectProjectedTypes(expr.DupAtt(m.Result), m.Result, viewspkg, scope, viewScope, seenProj) - projTypes = append(projTypes, types...) - viewedUnionMeths = append(viewedUnionMeths, umeths...) - } - for _, er := range m.Errors { - recordError(er) - } + // A function to collect inner user types from an attribute expression + collectUserTypes := func(att *expr.AttributeExpr) { + if ut, ok := att.Type.(expr.UserType); ok { + att = ut.Attribute() } + types = append(types, collectTypes(att, scope, seen)...) + } + for _, m := range service.Methods { + // collect inner user types + collectUserTypes(m.Payload) + collectUserTypes(m.StreamingPayload) + collectUserTypes(m.Result) + // Collect projected types + if hasResultType(m.Result) { + types, umeths := collectProjectedTypes(expr.DupAtt(m.Result), m.Result, viewspkg, scope, viewScope, seenProj) + projTypes = append(projTypes, types...) + viewedUnionMeths = append(viewedUnionMeths, umeths...) + } + for _, er := range m.Errors { + recordError(er) + } + } - // A function to convert raw object type to user type. - wrapObject := func(att *expr.AttributeExpr, name, id string) { - if _, ok := att.Type.(*expr.Object); ok { - att.Type = &expr.UserTypeExpr{ - AttributeExpr: expr.DupAtt(att), - TypeName: scope.Name(name), - UID: id, - } - } - if ut, ok := att.Type.(expr.UserType); ok { - seen[ut.ID()] = struct{}{} + // A function to convert raw object type to user type. + wrapObject := func(att *expr.AttributeExpr, name, id string) { + if _, ok := att.Type.(*expr.Object); ok { + att.Type = &expr.UserTypeExpr{ + AttributeExpr: expr.DupAtt(att), + TypeName: scope.Name(name), + UID: id, } } - - for _, m := range service.Methods { - name := codegen.Goify(m.Name, true) - // Create user type for raw object payloads - wrapObject(m.Payload, name+"Payload", service.Name+"#"+name+"Payload") - // Create user type for raw object streaming payloads - wrapObject(m.StreamingPayload, name+"StreamingPayload", service.Name+"#"+name+"StreamingPayload") - // Create user type for raw object results - wrapObject(m.Result, name+"Result", service.Name+"#"+name+"Result") + if ut, ok := att.Type.(expr.UserType); ok { + seen[ut.ID()] = struct{}{} } + } + for _, m := range service.Methods { + name := codegen.Goify(m.Name, true) + // Create user type for raw object payloads + wrapObject(m.Payload, name+"Payload", service.Name+"#"+name+"Payload") + // Create user type for raw object streaming payloads + wrapObject(m.StreamingPayload, name+"StreamingPayload", service.Name+"#"+name+"StreamingPayload") + // Create user type for raw object results + wrapObject(m.Result, name+"Result", service.Name+"#"+name+"Result") } // Add forced types @@ -796,86 +785,75 @@ func (d ServicesData) analyze(service *expr.ServiceExpr) *Data { methods []*MethodData schemes SchemesData ) - { - methods = make([]*MethodData, len(service.Methods)) - for i, e := range service.Methods { - m := buildMethodData(e, scope) - methods[i] = m - for _, s := range m.Schemes { - schemes = schemes.Append(s) - } - rt, ok := e.Result.Type.(*expr.ResultTypeExpr) - if !ok { - continue - } - var view string - if v, ok := e.Result.Meta.Last(expr.ViewMetaKey); ok { - view = v - } - if vrt, ok := seenViewed[m.Result+"::"+view]; ok { - m.ViewedResult = vrt - continue - } - projected := seenProj[rt.ID()] - projAtt := &expr.AttributeExpr{Type: projected.Type} - vrt := buildViewedResultType(e.Result, projAtt, viewspkg, scope, viewScope) - found := false - for _, rt := range viewedRTs { - if rt.Type.ID() == vrt.Type.ID() { - found = true - break - } - } - if !found { - viewedRTs = append(viewedRTs, vrt) - } + methods = make([]*MethodData, len(service.Methods)) + for i, e := range service.Methods { + m := buildMethodData(e, scope) + methods[i] = m + for _, s := range m.Schemes { + schemes = schemes.Append(s) + } + rt, ok := e.Result.Type.(*expr.ResultTypeExpr) + if !ok { + continue + } + var view string + if v, ok := e.Result.Meta.Last(expr.ViewMetaKey); ok { + view = v + } + if vrt, ok := seenViewed[m.Result+"::"+view]; ok { m.ViewedResult = vrt - seenViewed[vrt.Name+"::"+view] = vrt + continue } - } - - var ( - unionMethods []*UnionValueMethodData - ) - { - var ms []*UnionValueMethodData - seen := make(map[string]struct{}) - for _, t := range types { - ms = append(ms, collectUnionMethods(&expr.AttributeExpr{Type: t.Type}, scope, t.Loc, seen)...) - } - for _, t := range errTypes { - ms = append(ms, collectUnionMethods(&expr.AttributeExpr{Type: t.Type}, scope, t.Loc, seen)...) - } - for _, m := range service.Methods { - ms = append(ms, collectUnionMethods(m.Payload, scope, codegen.UserTypeLocation(m.Payload.Type), seen)...) - ms = append(ms, collectUnionMethods(m.StreamingPayload, scope, codegen.UserTypeLocation(m.StreamingPayload.Type), seen)...) - ms = append(ms, collectUnionMethods(m.Result, scope, codegen.UserTypeLocation(m.Result.Type), seen)...) - for _, e := range m.Errors { - ms = append(ms, collectUnionMethods(e.AttributeExpr, scope, codegen.UserTypeLocation(e.Type), seen)...) + projected := seenProj[rt.ID()] + projAtt := &expr.AttributeExpr{Type: projected.Type} + vrt := buildViewedResultType(e.Result, projAtt, viewspkg, scope, viewScope) + found := false + for _, rt := range viewedRTs { + if rt.Type.ID() == vrt.Type.ID() { + found = true + break } } - sort.Slice(ms, func(i, j int) bool { - return ms[i].Name < ms[j].Name - }) - pkgs := make(map[string]struct{}) - for _, m := range ms { - key := m.TypeRef + "::" + m.Name + "::" + m.Loc.PackageName() - if _, ok := pkgs[key]; ok { - continue - } - pkgs[key] = struct{}{} - unionMethods = append(unionMethods, m) + if !found { + viewedRTs = append(viewedRTs, vrt) } + m.ViewedResult = vrt + seenViewed[vrt.Name+"::"+view] = vrt } - var ( - desc string - ) - { - desc = service.Description - if desc == "" { - desc = fmt.Sprintf("Service is the %s service interface.", service.Name) + var unionMethods []*UnionValueMethodData + var ms []*UnionValueMethodData + seen = make(map[string]struct{}) + for _, t := range types { + ms = append(ms, collectUnionMethods(&expr.AttributeExpr{Type: t.Type}, scope, t.Loc, seen)...) + } + for _, t := range errTypes { + ms = append(ms, collectUnionMethods(&expr.AttributeExpr{Type: t.Type}, scope, t.Loc, seen)...) + } + for _, m := range service.Methods { + ms = append(ms, collectUnionMethods(m.Payload, scope, codegen.UserTypeLocation(m.Payload.Type), seen)...) + ms = append(ms, collectUnionMethods(m.StreamingPayload, scope, codegen.UserTypeLocation(m.StreamingPayload.Type), seen)...) + ms = append(ms, collectUnionMethods(m.Result, scope, codegen.UserTypeLocation(m.Result.Type), seen)...) + for _, e := range m.Errors { + ms = append(ms, collectUnionMethods(e.AttributeExpr, scope, codegen.UserTypeLocation(e.Type), seen)...) + } + } + sort.Slice(ms, func(i, j int) bool { + return ms[i].Name < ms[j].Name + }) + pkgs := make(map[string]struct{}) + for _, m := range ms { + key := m.TypeRef + "::" + m.Name + "::" + m.Loc.PackageName() + if _, ok := pkgs[key]; ok { + continue } + pkgs[key] = struct{}{} + unionMethods = append(unionMethods, m) + } + + desc := service.Description + if desc == "" { + desc = fmt.Sprintf("Service is the %s service interface.", service.Name) } varName := codegen.Goify(service.Name, false) @@ -1620,20 +1598,17 @@ func buildProjectedType(projected, att *expr.AttributeExpr, viewspkg string, sco var ( projections []*InitData typeInits []*InitData - validations []*ValidateData views []*ViewData varname = viewScope.GoTypeName(projected) pt = projected.Type.(expr.UserType) ) - { - if _, isrt := pt.(*expr.ResultTypeExpr); isrt { - typeInits = buildTypeInits(projected, att, viewspkg, scope, viewScope) - projections = buildProjections(projected, att, viewspkg, scope, viewScope) - views = buildViews(att.Type.(*expr.ResultTypeExpr), viewScope) - } - validations = buildValidations(projected, viewScope) + if _, isrt := pt.(*expr.ResultTypeExpr); isrt { + typeInits = buildTypeInits(projected, att, viewspkg, scope, viewScope) + projections = buildProjections(projected, att, viewspkg, scope, viewScope) + views = buildViews(att.Type.(*expr.ResultTypeExpr), viewScope) } + validations := buildValidations(projected, viewScope) removeMeta(projected) return &ProjectedTypeData{ UserTypeData: &UserTypeData{ @@ -1675,115 +1650,94 @@ func buildViews(rt *expr.ResultTypeExpr, viewScope *codegen.NameScope) []*ViewDa // and projected type. func buildViewedResultType(att, projected *expr.AttributeExpr, viewspkg string, scope, viewScope *codegen.NameScope) *ViewedResultTypeData { // collect result type views - var ( - viewName string - views []*ViewData - - rt = att.Type.(*expr.ResultTypeExpr) - isarr = expr.IsArray(att.Type) - ) - { - if !rt.HasMultipleViews() { - viewName = expr.DefaultView - } - if v, ok := att.Meta.Last(expr.ViewMetaKey); ok { - viewName = v - } - views = buildViews(rt, viewScope) + rt := att.Type.(*expr.ResultTypeExpr) + isarr := expr.IsArray(att.Type) + var viewName string + if !rt.HasMultipleViews() { + viewName = expr.DefaultView + } + if v, ok := att.Meta.Last(expr.ViewMetaKey); ok { + viewName = v } + views := buildViews(rt, viewScope) // build validation data - var ( - validate *ValidateData - - resvar = scope.GoTypeName(att) - resref = scope.GoTypeRef(att) - ) - { - data := map[string]any{ - "Projected": scope.GoTypeName(projected), - "ArgVar": "result", - "Source": "result", - "Views": views, - "IsViewed": true, - } - buf := &bytes.Buffer{} - if err := validateTypeCodeTmpl.Execute(buf, data); err != nil { - panic(err) // bug - } - name := "Validate" + resvar - validate = &ValidateData{ - Name: name, - Description: fmt.Sprintf("%s runs the validations defined on the viewed result type %s.", name, resvar), - Ref: resref, - Validate: buf.String(), - } + resvar := scope.GoTypeName(att) + resref := scope.GoTypeRef(att) + data := map[string]any{ + "Projected": scope.GoTypeName(projected), + "ArgVar": "result", + "Source": "result", + "Views": views, + "IsViewed": true, + } + buf := &bytes.Buffer{} + if err := validateTypeCodeTmpl.Execute(buf, data); err != nil { + panic(err) // bug + } + name := "Validate" + resvar + validate := &ValidateData{ + Name: name, + Description: fmt.Sprintf("%s runs the validations defined on the viewed result type %s.", name, resvar), + Ref: resref, + Validate: buf.String(), } // build constructor to initialize viewed result type from result type - var ( - init *InitData - - vresref = viewScope.GoFullTypeRef(att, viewspkg) - ) - { - data := map[string]any{ - "ToViewed": true, - "ArgVar": "res", - "ReturnVar": "vres", - "Views": views, - "ReturnTypeRef": vresref, - "IsCollection": isarr, - "TargetType": scope.GoFullTypeName(att, viewspkg), - "InitName": "new" + viewScope.GoTypeName(projected), - } - buf := &bytes.Buffer{} - if err := initTypeCodeTmpl.Execute(buf, data); err != nil { - panic(err) // bug - } - pkg := "" - if loc := codegen.UserTypeLocation(att.Type); loc != nil { - pkg = loc.PackageName() - } - name := "NewViewed" + resvar - init = &InitData{ - Name: name, - Description: fmt.Sprintf("%s initializes viewed result type %s from result type %s using the given view.", name, resvar, resvar), - Args: []*InitArgData{ - {Name: "res", Ref: scope.GoFullTypeRef(att, pkg)}, - {Name: "view", Ref: "string"}, - }, - ReturnTypeRef: vresref, - Code: buf.String(), - } + vresref := viewScope.GoFullTypeRef(att, viewspkg) + data = map[string]any{ + "ToViewed": true, + "ArgVar": "res", + "ReturnVar": "vres", + "Views": views, + "ReturnTypeRef": vresref, + "IsCollection": isarr, + "TargetType": scope.GoFullTypeName(att, viewspkg), + "InitName": "new" + viewScope.GoTypeName(projected), + } + buf = &bytes.Buffer{} + if err := initTypeCodeTmpl.Execute(buf, data); err != nil { + panic(err) // bug + } + pkg := "" + if loc := codegen.UserTypeLocation(att.Type); loc != nil { + pkg = loc.PackageName() + } + name = "NewViewed" + resvar + init := &InitData{ + Name: name, + Description: fmt.Sprintf("%s initializes viewed result type %s from result type %s using the given view.", name, resvar, resvar), + Args: []*InitArgData{ + {Name: "res", Ref: scope.GoFullTypeRef(att, pkg)}, + {Name: "view", Ref: "string"}, + }, + ReturnTypeRef: vresref, + Code: buf.String(), } // build constructor to initialize result type from viewed result type - var resinit *InitData - { - if loc := codegen.UserTypeLocation(att.Type); loc != nil { - resref = scope.GoFullTypeRef(att, loc.PackageName()) - } - data := map[string]any{ - "ToResult": true, - "ArgVar": "vres", - "ReturnVar": "res", - "Views": views, - "ReturnTypeRef": resref, - "InitName": "new" + scope.GoTypeName(att), - } - buf := &bytes.Buffer{} - if err := initTypeCodeTmpl.Execute(buf, data); err != nil { - panic(err) // bug - } - name := "New" + resvar - resinit = &InitData{ - Name: name, - Description: fmt.Sprintf("%s initializes result type %s from viewed result type %s.", name, resvar, resvar), - Args: []*InitArgData{{Name: "vres", Ref: scope.GoFullTypeRef(att, viewspkg)}}, - ReturnTypeRef: resref, - Code: buf.String(), - } + if loc := codegen.UserTypeLocation(att.Type); loc != nil { + resref = scope.GoFullTypeRef(att, loc.PackageName()) + } + data = map[string]any{ + "ToResult": true, + "ArgVar": "vres", + "ReturnVar": "res", + "Views": views, + "ReturnTypeRef": resref, + "InitName": "new" + scope.GoTypeName(att), + } + buf = &bytes.Buffer{} + if err := initTypeCodeTmpl.Execute(buf, data); err != nil { + panic(err) // bug + } + name = "New" + resvar + resinit := &InitData{ + Name: name, + Description: fmt.Sprintf("%s initializes result type %s from viewed result type %s.", name, resvar, resvar), + Args: []*InitArgData{{Name: "vres", Ref: scope.GoFullTypeRef(att, viewspkg)}}, + ReturnTypeRef: resref, + Code: buf.String(), } projT := wrapProjected(projected.Type.(expr.UserType)) @@ -1846,72 +1800,56 @@ func buildTypeInits(projected, att *expr.AttributeExpr, viewspkg string, scope, // For every view defined in the result type, build a constructor function // to create the result type from a projected type based on the view. - var init []*InitData - { - init = make([]*InitData, 0, len(prt.Views)) - for _, view := range prt.Views { - var ( - typ expr.DataType - - obj = &expr.Object{} - ) - { - walkViewAttrs(pobj, view, func(name string, att, _ *expr.AttributeExpr) { - obj.Set(name, att) - }) - typ = obj - if parr != nil { - typ = &expr.Array{ElemType: &expr.AttributeExpr{ - Type: &expr.ResultTypeExpr{ - UserTypeExpr: &expr.UserTypeExpr{ - AttributeExpr: &expr.AttributeExpr{Type: obj}, - TypeName: scope.GoTypeName(parr.ElemType), - }, - }, - }} - } - } - src := &expr.AttributeExpr{ + init := make([]*InitData, 0, len(prt.Views)) + for _, view := range prt.Views { + var typ expr.DataType + obj := &expr.Object{} + walkViewAttrs(pobj, view, func(name string, att, _ *expr.AttributeExpr) { + obj.Set(name, att) + }) + typ = obj + if parr != nil { + typ = &expr.Array{ElemType: &expr.AttributeExpr{ Type: &expr.ResultTypeExpr{ UserTypeExpr: &expr.UserTypeExpr{ - AttributeExpr: &expr.AttributeExpr{Type: typ}, - TypeName: scope.GoTypeName(projected), + AttributeExpr: &expr.AttributeExpr{Type: obj}, + TypeName: scope.GoTypeName(parr.ElemType), }, - Views: prt.Views, - Identifier: prt.Identifier, }, - } + }} + } + src := &expr.AttributeExpr{ + Type: &expr.ResultTypeExpr{ + UserTypeExpr: &expr.UserTypeExpr{ + AttributeExpr: &expr.AttributeExpr{Type: typ}, + TypeName: scope.GoTypeName(projected), + }, + Views: prt.Views, + Identifier: prt.Identifier, + }, + } - var ( - name string - code string - helpers []*codegen.TransformFunctionData - - srcCtx = projectedTypeContext(viewspkg, true, viewScope) - tgtCtx = typeContext("", scope) - resvar = scope.GoTypeName(att) - ) - { - name = "new" + resvar - if view.Name != expr.DefaultView { - name += codegen.Goify(view.Name, true) - } - code, helpers = buildConstructorCode(src, att, "vres", "res", srcCtx, tgtCtx, view.Name) - } + srcCtx := projectedTypeContext(viewspkg, true, viewScope) + tgtCtx := typeContext("", scope) + resvar := scope.GoTypeName(att) + name := "new" + resvar + if view.Name != expr.DefaultView { + name += codegen.Goify(view.Name, true) + } + code, helpers := buildConstructorCode(src, att, "vres", "res", srcCtx, tgtCtx, view.Name) - pkg := "" - if loc := codegen.UserTypeLocation(att.Type); loc != nil { - pkg = loc.PackageName() - } - init = append(init, &InitData{ - Name: name, - Description: fmt.Sprintf("%s converts projected type %s to service type %s.", name, resvar, resvar), - Args: []*InitArgData{{Name: "vres", Ref: viewScope.GoFullTypeRef(projected, viewspkg)}}, - ReturnTypeRef: scope.GoFullTypeRef(att, pkg), - Code: code, - Helpers: helpers, - }) + pkg := "" + if loc := codegen.UserTypeLocation(att.Type); loc != nil { + pkg = loc.PackageName() } + init = append(init, &InitData{ + Name: name, + Description: fmt.Sprintf("%s converts projected type %s to service type %s.", name, resvar, resvar), + Args: []*InitArgData{{Name: "vres", Ref: viewScope.GoFullTypeRef(projected, viewspkg)}}, + ReturnTypeRef: scope.GoFullTypeRef(att, pkg), + Code: code, + Helpers: helpers, + }) } return init } @@ -1919,40 +1857,30 @@ func buildTypeInits(projected, att *expr.AttributeExpr, viewspkg string, scope, // buildProjections builds the data to generate the constructor code to // project a result type to a projected type based on a view. func buildProjections(projected, att *expr.AttributeExpr, viewspkg string, scope, viewScope *codegen.NameScope) []*InitData { - var ( - projections []*InitData - - rt = att.Type.(*expr.ResultTypeExpr) - ) - - projections = make([]*InitData, 0, len(rt.Views)) + rt := att.Type.(*expr.ResultTypeExpr) + projections := make([]*InitData, 0, len(rt.Views)) for _, view := range rt.Views { - var ( - typ expr.DataType - - obj = &expr.Object{} - ) - { - pobj := expr.AsObject(projected.Type) - parr := expr.AsArray(projected.Type) - if parr != nil { - // result type collection - pobj = expr.AsObject(parr.ElemType.Type) - } - walkViewAttrs(pobj, view, func(name string, att, _ *expr.AttributeExpr) { - obj.Set(name, att) - }) - typ = obj - if parr != nil { - typ = &expr.Array{ElemType: &expr.AttributeExpr{ - Type: &expr.ResultTypeExpr{ - UserTypeExpr: &expr.UserTypeExpr{ - AttributeExpr: &expr.AttributeExpr{Type: obj}, - TypeName: parr.ElemType.Type.Name(), - }, + var typ expr.DataType + obj := &expr.Object{} + pobj := expr.AsObject(projected.Type) + parr := expr.AsArray(projected.Type) + if parr != nil { + // result type collection + pobj = expr.AsObject(parr.ElemType.Type) + } + walkViewAttrs(pobj, view, func(name string, att, _ *expr.AttributeExpr) { + obj.Set(name, att) + }) + typ = obj + if parr != nil { + typ = &expr.Array{ElemType: &expr.AttributeExpr{ + Type: &expr.ResultTypeExpr{ + UserTypeExpr: &expr.UserTypeExpr{ + AttributeExpr: &expr.AttributeExpr{Type: obj}, + TypeName: parr.ElemType.Type.Name(), }, - }} - } + }, + }} } tgt := &expr.AttributeExpr{ Type: &expr.ResultTypeExpr{ @@ -1965,22 +1893,14 @@ func buildProjections(projected, att *expr.AttributeExpr, viewspkg string, scope }, } - var ( - name string - code string - helpers []*codegen.TransformFunctionData - - srcCtx = typeContext("", scope) - tgtCtx = projectedTypeContext(viewspkg, true, viewScope) - tname = scope.GoTypeName(projected) - ) - { - name = "new" + tname - if view.Name != expr.DefaultView { - name += codegen.Goify(view.Name, true) - } - code, helpers = buildConstructorCode(att, tgt, "res", "vres", srcCtx, tgtCtx, view.Name) + srcCtx := typeContext("", scope) + tgtCtx := projectedTypeContext(viewspkg, true, viewScope) + tname := scope.GoTypeName(projected) + name := "new" + tname + if view.Name != expr.DefaultView { + name += codegen.Goify(view.Name, true) } + code, helpers := buildConstructorCode(att, tgt, "res", "vres", srcCtx, tgtCtx, view.Name) pkg := "" if loc := codegen.UserTypeLocation(att.Type); loc != nil { @@ -2001,12 +1921,9 @@ func buildProjections(projected, att *expr.AttributeExpr, viewspkg string, scope // buildValidations builds the data required to generate validations for the // projected types. func buildValidations(projected *expr.AttributeExpr, scope *codegen.NameScope) []*ValidateData { - var ( - validations []*ValidateData - - ut = projected.Type.(expr.UserType) - tname = scope.GoTypeName(projected) - ) + ut := projected.Type.(expr.UserType) + tname := scope.GoTypeName(projected) + var validations []*ValidateData if rt, isrt := ut.(*expr.ResultTypeExpr); isrt { // for result types we create a validation function containing view // specific validation logic for each view @@ -2018,16 +1935,11 @@ func buildValidations(projected *expr.AttributeExpr, scope *codegen.NameScope) [ "Source": "result", "IsCollection": arr != nil, } - var ( - name string - vn string - ) - { - name = "Validate" + tname - if view.Name != expr.DefaultView { - vn = codegen.Goify(view.Name, true) - name += vn - } + var vn string + name := "Validate" + tname + if view.Name != expr.DefaultView { + vn = codegen.Goify(view.Name, true) + name += vn } if arr != nil { @@ -2035,32 +1947,26 @@ func buildValidations(projected *expr.AttributeExpr, scope *codegen.NameScope) [ data["Source"] = "item" data["ValidateVar"] = "Validate" + scope.GoTypeName(arr.ElemType) + vn } else { - var ( - ctx *codegen.AttributeContext - fields []map[string]any - - o = &expr.Object{} - ) - { - walkViewAttrs(expr.AsObject(projected.Type), view, func(name string, attr, vatt *expr.AttributeExpr) { - if rt, ok := attr.Type.(*expr.ResultTypeExpr); ok { - // use explicitly specified view (if any) for the attribute, - // otherwise use default - vw := "" - if v, ok := vatt.Meta.Last(expr.ViewMetaKey); ok && v != expr.DefaultView { - vw = v - } - fields = append(fields, map[string]any{ - "Name": name, - "ValidateVar": "Validate" + scope.GoTypeName(attr) + codegen.Goify(vw, true), - "IsRequired": rt.Attribute().IsRequired(name), - }) - } else { - o.Set(name, attr) + var fields []map[string]any + o := &expr.Object{} + walkViewAttrs(expr.AsObject(projected.Type), view, func(name string, attr, vatt *expr.AttributeExpr) { + if rt, ok := attr.Type.(*expr.ResultTypeExpr); ok { + // use explicitly specified view (if any) for the attribute, + // otherwise use default + vw := "" + if v, ok := vatt.Meta.Last(expr.ViewMetaKey); ok && v != expr.DefaultView { + vw = v } - }) - ctx = projectedTypeContext("", !expr.IsPrimitive(projected.Type), scope) - } + fields = append(fields, map[string]any{ + "Name": name, + "ValidateVar": "Validate" + scope.GoTypeName(attr) + codegen.Goify(vw, true), + "IsRequired": rt.Attribute().IsRequired(name), + }) + } else { + o.Set(name, attr) + } + }) + ctx := projectedTypeContext("", !expr.IsPrimitive(projected.Type), scope) data["Validate"] = codegen.ValidationCode(&expr.AttributeExpr{Type: o, Validation: rt.Validation}, rt, ctx, true, false, true, "result") data["Fields"] = fields } @@ -2142,15 +2048,10 @@ func buildConstructorCode(src, tgt *expr.AttributeExpr, sourceVar, targetVar str data["Source"] = sourceVar data["Target"] = targetVar - var ( - code string - err error - ) - { - // build code for target with no result types - if code, helpers, err = codegen.GoTransform(src, tatt, sourceVar, targetVar, sourceCtx, targetCtx, "transform", true); err != nil { - panic(err) // bug - } + // build code for target with no result types + code, helpers, err := codegen.GoTransform(src, tatt, sourceVar, targetVar, sourceCtx, targetCtx, "transform", true) + if err != nil { + panic(err) // bug } data["Code"] = code diff --git a/dsl/interceptor_test.go b/dsl/interceptor_test.go index 719b600709..7b94d86011 100644 --- a/dsl/interceptor_test.go +++ b/dsl/interceptor_test.go @@ -15,7 +15,7 @@ import ( func TestInterceptor(t *testing.T) { cases := map[string]struct { DSL func() - Assert func(t *testing.T, intr *expr.InterceptorExpr) + Assert func(*testing.T, *expr.InterceptorExpr) }{ "valid-minimal": { func() { @@ -132,7 +132,7 @@ func TestInterceptor(t *testing.T) { func() { Interceptor("", func() {}) }, - func(t *testing.T, intr *expr.InterceptorExpr) { + func(t *testing.T, _ *expr.InterceptorExpr) { assert.NotNil(t, eval.Context.Errors, "expected a validation error") }, }, @@ -141,7 +141,7 @@ func TestInterceptor(t *testing.T) { Interceptor("duplicate", func() {}) Interceptor("duplicate", func() {}) }, - func(t *testing.T, intr *expr.InterceptorExpr) { + func(t *testing.T, _ *expr.InterceptorExpr) { if eval.Context.Errors == nil { t.Error("expected a validation error, got none") } @@ -164,7 +164,7 @@ func TestInterceptor(t *testing.T) { func TestServerInterceptor(t *testing.T) { cases := map[string]struct { DSL func() - Assert func(t *testing.T, svc *expr.ServiceExpr, err error) + Assert func(*testing.T, *expr.ServiceExpr, error) }{ "valid-reference": { func() { @@ -200,7 +200,7 @@ func TestServerInterceptor(t *testing.T) { ServerInterceptor(42) // Invalid type }) }, - func(t *testing.T, svc *expr.ServiceExpr, err error) { + func(t *testing.T, _ *expr.ServiceExpr, err error) { require.Error(t, err) }, }, @@ -210,7 +210,7 @@ func TestServerInterceptor(t *testing.T) { ServerInterceptor("invalid") }) }, - func(t *testing.T, svc *expr.ServiceExpr, err error) { + func(t *testing.T, _ *expr.ServiceExpr, err error) { require.Error(t, err) }, }, @@ -230,7 +230,7 @@ func TestServerInterceptor(t *testing.T) { func TestClientInterceptor(t *testing.T) { cases := map[string]struct { DSL func() - Assert func(t *testing.T, svc *expr.ServiceExpr, err error) + Assert func(*testing.T, *expr.ServiceExpr, error) }{ "valid-reference": { func() { @@ -264,7 +264,7 @@ func TestClientInterceptor(t *testing.T) { ClientInterceptor(42) // Invalid type }) }, - func(t *testing.T, svc *expr.ServiceExpr, err error) { + func(t *testing.T, _ *expr.ServiceExpr, err error) { require.Error(t, err) }, }, @@ -274,7 +274,7 @@ func TestClientInterceptor(t *testing.T) { ClientInterceptor("invalid") }) }, - func(t *testing.T, svc *expr.ServiceExpr, err error) { + func(t *testing.T, _ *expr.ServiceExpr, err error) { require.Error(t, err) }, }, diff --git a/grpc/codegen/client_cli.go b/grpc/codegen/client_cli.go index 9f7f9d8f92..9360c5057e 100644 --- a/grpc/codegen/client_cli.go +++ b/grpc/codegen/client_cli.go @@ -19,31 +19,27 @@ func ClientCLIFiles(genpkg string, root *expr.RootExpr) []*codegen.File { data []*cli.CommandData svcs []*expr.GRPCServiceExpr ) - { - for _, svc := range root.API.GRPC.Services { - if len(svc.GRPCEndpoints) == 0 { - continue - } - sd := GRPCServices.Get(svc.Name()) - command := cli.BuildCommandData(sd.Service) - for _, e := range sd.Endpoints { - flags, buildFunction := buildFlags(e) - subcmd := cli.BuildSubcommandData(sd.Service, e.Method, buildFunction, flags) - command.Subcommands = append(command.Subcommands, subcmd) - } - command.Example = command.Subcommands[0].Example - data = append(data, command) - svcs = append(svcs, svc) + for _, svc := range root.API.GRPC.Services { + if len(svc.GRPCEndpoints) == 0 { + continue + } + sd := GRPCServices.Get(svc.Name()) + command := cli.BuildCommandData(sd.Service) + for _, e := range sd.Endpoints { + flags, buildFunction := buildFlags(e) + subcmd := cli.BuildSubcommandData(sd.Service, e.Method, buildFunction, flags) + command.Subcommands = append(command.Subcommands, subcmd) } + command.Example = command.Subcommands[0].Example + data = append(data, command) + svcs = append(svcs, svc) } var files []*codegen.File - { - for _, svr := range root.API.Servers { - files = append(files, endpointParser(genpkg, root, svr, data)) - } - for i, svc := range svcs { - files = append(files, payloadBuilders(genpkg, svc, data[i])) - } + for _, svr := range root.API.Servers { + files = append(files, endpointParser(genpkg, root, svr, data)) + } + for i, svc := range svcs { + files = append(files, payloadBuilders(genpkg, svc, data[i])) } return files } diff --git a/grpc/codegen/service_data.go b/grpc/codegen/service_data.go index e375aa9c3f..f75e9a9d85 100644 --- a/grpc/codegen/service_data.go +++ b/grpc/codegen/service_data.go @@ -435,33 +435,26 @@ func (sd *ServiceData) HasStreamingEndpoint() bool { // analyze creates the data necessary to render the code of the given service. func (ServicesData) analyze(gs *expr.GRPCServiceExpr) *ServiceData { - var ( - sd *ServiceData - seen, imported map[string]struct{} - svcVarN string - - svc = service.Services.Get(gs.Name()) - scope = codegen.NewNameScope() - pkg = codegen.SnakeCase(codegen.Goify(svc.Name, false)) + pbPkgName - ) - { - svcVarN = scope.HashedUnique(gs.ServiceExpr, codegen.Goify(svc.Name, true)) - sd = &ServiceData{ - Service: svc, - Name: svcVarN, - Description: svc.Description, - PkgName: pkg, - ServerStruct: "Server", - ClientStruct: "Client", - ServerInit: "New", - ClientInit: "NewClient", - ServerInterface: svcVarN + "Server", - ClientInterface: svcVarN + "Client", - ClientInterfaceInit: fmt.Sprintf("%s.New%sClient", pkg, svcVarN), - Scope: scope, - } - seen, imported = make(map[string]struct{}), make(map[string]struct{}) + svc := service.Services.Get(gs.Name()) + scope := codegen.NewNameScope() + pkg := codegen.SnakeCase(codegen.Goify(svc.Name, false)) + pbPkgName + svcVarN := scope.HashedUnique(gs.ServiceExpr, codegen.Goify(svc.Name, true)) + sd := &ServiceData{ + Service: svc, + Name: svcVarN, + Description: svc.Description, + PkgName: pkg, + ServerStruct: "Server", + ClientStruct: "Client", + ServerInit: "New", + ClientInit: "NewClient", + ServerInterface: svcVarN + "Server", + ClientInterface: svcVarN + "Client", + ClientInterfaceInit: fmt.Sprintf("%s.New%sClient", pkg, svcVarN), + Scope: scope, } + seen, imported := make(map[string]struct{}), make(map[string]struct{}) + for _, e := range gs.GRPCEndpoints { // convert request and response types to protocol buffer message types e.Request = makeProtoBufMessage(e.Request, protoBufify(e.Name()+"_request", true, true), sd) @@ -512,102 +505,84 @@ func (ServicesData) analyze(gs *expr.GRPCServiceExpr) *ServiceData { payloadRef string resultRef string viewedResultRef string - errors []*ErrorData - - md = svc.Method(e.Name()) ) - { - if e.MethodExpr.Payload.Type != expr.Empty { - payloadRef = svc.Scope.GoFullTypeRef(e.MethodExpr.Payload, - pkgWithDefault(md.PayloadLoc, svc.PkgName)) - } - if e.MethodExpr.Result.Type != expr.Empty { - resultRef = svc.Scope.GoFullTypeRef(e.MethodExpr.Result, - pkgWithDefault(md.ResultLoc, svc.PkgName)) - } - if md.ViewedResult != nil { - viewedResultRef = md.ViewedResult.FullRef - } - errors = buildErrorsData(e, sd) - for _, er := range e.GRPCErrors { - if er.ErrorExpr.Type == expr.ErrorResult || !expr.IsObject(er.ErrorExpr.Type) { - continue - } - collect(er.Response.Message) + md := svc.Method(e.Name()) + if e.MethodExpr.Payload.Type != expr.Empty { + payloadRef = svc.Scope.GoFullTypeRef(e.MethodExpr.Payload, + pkgWithDefault(md.PayloadLoc, svc.PkgName)) + } + if e.MethodExpr.Result.Type != expr.Empty { + resultRef = svc.Scope.GoFullTypeRef(e.MethodExpr.Result, + pkgWithDefault(md.ResultLoc, svc.PkgName)) + } + if md.ViewedResult != nil { + viewedResultRef = md.ViewedResult.FullRef + } + errors := buildErrorsData(e, sd) + for _, er := range e.GRPCErrors { + if er.ErrorExpr.Type == expr.ErrorResult || !expr.IsObject(er.ErrorExpr.Type) { + continue } + collect(er.Response.Message) } // build request data - var ( - request *RequestData - reqMD []*MetadataData - ) - { - reqMD = extractMetadata(e.Metadata, e.MethodExpr.Payload, svc.Scope) - request = &RequestData{ - Description: e.Request.Description, - Metadata: reqMD, - ServerConvert: buildRequestConvertData(e.Request, e.MethodExpr.Payload, reqMD, e, sd, true), - ClientConvert: buildRequestConvertData(e.Request, e.MethodExpr.Payload, reqMD, e, sd, false), - } - if obj := expr.AsObject(e.Request.Type); (obj != nil && len(*obj) > 0) || expr.IsUnion(e.Request.Type) { - // add the request message as the first argument to the CLI - request.CLIArgs = append(request.CLIArgs, &InitArgData{ - Name: "message", - Ref: "message", - TypeName: protoBufGoFullTypeName(e.Request, sd.PkgName, sd.Scope), - TypeRef: protoBufGoFullTypeRef(e.Request, sd.PkgName, sd.Scope), - Example: e.Request.Example(expr.Root.API.ExampleGenerator), - }) - } - // pass the metadata as arguments to client CLI args - for _, m := range reqMD { - request.CLIArgs = append(request.CLIArgs, &InitArgData{ - Name: m.VarName, - Ref: m.VarName, - FieldName: m.FieldName, - FieldType: m.FieldType, - TypeName: m.TypeName, - TypeRef: m.TypeRef, - Type: m.Type, - Pointer: m.Pointer, - Required: m.Required, - Validate: m.Validate, - Example: m.Example, - DefaultValue: m.DefaultValue, - }) - } - if e.StreamingRequest.Type != expr.Empty { - request.Message = collect(e.StreamingRequest) - } else { - request.Message = collect(e.Request) - } + reqMD := extractMetadata(e.Metadata, e.MethodExpr.Payload, svc.Scope) + request := &RequestData{ + Description: e.Request.Description, + Metadata: reqMD, + ServerConvert: buildRequestConvertData(e.Request, e.MethodExpr.Payload, reqMD, e, sd, true), + ClientConvert: buildRequestConvertData(e.Request, e.MethodExpr.Payload, reqMD, e, sd, false), + } + if obj := expr.AsObject(e.Request.Type); (obj != nil && len(*obj) > 0) || expr.IsUnion(e.Request.Type) { + // add the request message as the first argument to the CLI + request.CLIArgs = append(request.CLIArgs, &InitArgData{ + Name: "message", + Ref: "message", + TypeName: protoBufGoFullTypeName(e.Request, sd.PkgName, sd.Scope), + TypeRef: protoBufGoFullTypeRef(e.Request, sd.PkgName, sd.Scope), + Example: e.Request.Example(expr.Root.API.ExampleGenerator), + }) + } + // pass the metadata as arguments to client CLI args + for _, m := range reqMD { + request.CLIArgs = append(request.CLIArgs, &InitArgData{ + Name: m.VarName, + Ref: m.VarName, + FieldName: m.FieldName, + FieldType: m.FieldType, + TypeName: m.TypeName, + TypeRef: m.TypeRef, + Type: m.Type, + Pointer: m.Pointer, + Required: m.Required, + Validate: m.Validate, + Example: m.Example, + DefaultValue: m.DefaultValue, + }) + } + if e.StreamingRequest.Type != expr.Empty { + request.Message = collect(e.StreamingRequest) + } else { + request.Message = collect(e.Request) } // build response data - var ( - response *ResponseData - hdrs []*MetadataData - trlrs []*MetadataData - - result, svcCtx = resultContext(e, sd) - ) - { - hdrs = extractMetadata(e.Response.Headers, result, svc.Scope) - trlrs = extractMetadata(e.Response.Trailers, result, svc.Scope) - response = &ResponseData{ - StatusCode: statusCodeToGRPCConst(e.Response.StatusCode), - Description: e.Response.Description, - Headers: hdrs, - Trailers: trlrs, - ServerConvert: buildResponseConvertData(e.Response.Message, result, svcCtx, hdrs, trlrs, e, sd, true), - ClientConvert: buildResponseConvertData(e.Response.Message, result, svcCtx, hdrs, trlrs, e, sd, false), - } - // If the endpoint is a streaming endpoint, no message is returned - // by gRPC. Hence, no need to set response message. - if e.Response.Message.Type != expr.Empty || !e.MethodExpr.IsStreaming() { - response.Message = collect(e.Response.Message) - } + result, svcCtx := resultContext(e, sd) + hdrs := extractMetadata(e.Response.Headers, result, svc.Scope) + trlrs := extractMetadata(e.Response.Trailers, result, svc.Scope) + response := &ResponseData{ + StatusCode: statusCodeToGRPCConst(e.Response.StatusCode), + Description: e.Response.Description, + Headers: hdrs, + Trailers: trlrs, + ServerConvert: buildResponseConvertData(e.Response.Message, result, svcCtx, hdrs, trlrs, e, sd, true), + ClientConvert: buildResponseConvertData(e.Response.Message, result, svcCtx, hdrs, trlrs, e, sd, false), + } + // If the endpoint is a streaming endpoint, no message is returned + // by gRPC. Hence, no need to set response message. + if e.Response.Message.Type != expr.Empty || !e.MethodExpr.IsStreaming() { + response.Message = collect(e.Response.Message) } // gather security requirements @@ -615,17 +590,15 @@ func (ServicesData) analyze(gs *expr.GRPCServiceExpr) *ServiceData { msgSch service.SchemesData metSch service.SchemesData ) - { - for _, req := range e.Requirements { - for _, sch := range req.Schemes { - s := md.Requirements.Scheme(sch.SchemeName).Dup() - s.In = sch.In - switch s.In { - case "message": - msgSch = msgSch.Append(s) - default: - metSch = metSch.Append(s) - } + for _, req := range e.Requirements { + for _, sch := range req.Schemes { + s := md.Requirements.Scheme(sch.SchemeName).Dup() + s.In = sch.In + switch s.In { + case "message": + msgSch = msgSch.Append(s) + default: + metSch = metSch.Append(s) } } } @@ -866,35 +839,29 @@ func buildRequestConvertData(request, payload *expr.AttributeExpr, md []*Metadat return nil } - var ( - svc = sd.Service - pkg = pkgWithDefault(svc.Method(e.MethodExpr.Name).PayloadLoc, svc.PkgName) - svcCtx = serviceTypeContext(pkg, svc.Scope) - ) - + svc := sd.Service + pkg := pkgWithDefault(svc.Method(e.MethodExpr.Name).PayloadLoc, svc.PkgName) + svcCtx := serviceTypeContext(pkg, svc.Scope) if svr { // server side - var data *InitData - { - data = buildInitData(request, payload, "message", "v", svcCtx, false, svr, false, sd) - data.Name = fmt.Sprintf("New%sPayload", codegen.Goify(e.Name(), true)) - data.Description = fmt.Sprintf("%s builds the payload of the %q endpoint of the %q service from the gRPC request type.", data.Name, e.Name(), svc.Name) - for _, m := range md { - // pass the metadata as arguments to payload constructor in server - data.Args = append(data.Args, &InitArgData{ - Name: m.VarName, - Ref: m.VarName, - FieldName: m.FieldName, - FieldType: m.FieldType, - TypeName: m.TypeName, - TypeRef: m.TypeRef, - Type: m.Type, - Pointer: m.Pointer, - Required: m.Required, - Validate: m.Validate, - Example: m.Example, - }) - } + data := buildInitData(request, payload, "message", "v", svcCtx, false, svr, false, sd) + data.Name = fmt.Sprintf("New%sPayload", codegen.Goify(e.Name(), true)) + data.Description = fmt.Sprintf("%s builds the payload of the %q endpoint of the %q service from the gRPC request type.", data.Name, e.Name(), svc.Name) + for _, m := range md { + // pass the metadata as arguments to payload constructor in server + data.Args = append(data.Args, &InitArgData{ + Name: m.VarName, + Ref: m.VarName, + FieldName: m.FieldName, + FieldType: m.FieldType, + TypeName: m.TypeName, + TypeRef: m.TypeRef, + Type: m.Type, + Pointer: m.Pointer, + Required: m.Required, + Validate: m.Validate, + Example: m.Example, + }) } return &ConvertData{ SrcName: protoBufGoFullTypeName(request, sd.PkgName, sd.Scope), @@ -907,14 +874,8 @@ func buildRequestConvertData(request, payload *expr.AttributeExpr, md []*Metadat } // client side - - var ( - data *InitData - ) - { - data = buildInitData(payload, request, "payload", "message", svcCtx, true, svr, false, sd) - data.Description = fmt.Sprintf("%s builds the gRPC request type from the payload of the %q endpoint of the %q service.", data.Name, e.Name(), svc.Name) - } + data := buildInitData(payload, request, "payload", "message", svcCtx, true, svr, false, sd) + data.Description = fmt.Sprintf("%s builds the gRPC request type from the payload of the %q endpoint of the %q service.", data.Name, e.Name(), svc.Name) return &ConvertData{ SrcName: svc.Scope.GoFullTypeName(payload, pkg), SrcRef: svc.Scope.GoFullTypeRef(payload, pkg), @@ -937,18 +898,12 @@ func buildResponseConvertData(response, result *expr.AttributeExpr, svcCtx *code return nil } - var ( - svc = sd.Service - ) - + svc := sd.Service if svr { // server side - var data *InitData - { - data = buildInitData(result, response, "result", "message", svcCtx, true, svr, false, sd) - data.Description = fmt.Sprintf("%s builds the gRPC response type from the result of the %q endpoint of the %q service.", data.Name, e.Name(), svc.Name) - } + data := buildInitData(result, response, "result", "message", svcCtx, true, svr, false, sd) + data.Description = fmt.Sprintf("%s builds the gRPC response type from the result of the %q endpoint of the %q service.", data.Name, e.Name(), svc.Name) return &ConvertData{ SrcName: svcCtx.Scope.Name(result, svcCtx.Pkg(result), svcCtx.Pointer, svcCtx.UseDefault), SrcRef: svcCtx.Scope.Ref(result, svcCtx.Pkg(result)), @@ -959,44 +914,40 @@ func buildResponseConvertData(response, result *expr.AttributeExpr, svcCtx *code } // client side - - var data *InitData - { - data = buildInitData(response, result, "message", "result", svcCtx, false, svr, false, sd) - data.Name = fmt.Sprintf("New%sResult", codegen.Goify(e.Name(), true)) - data.Description = fmt.Sprintf("%s builds the result type of the %q endpoint of the %q service from the gRPC response type.", data.Name, e.Name(), svc.Name) - for _, m := range hdrs { - // pass the headers as arguments to result constructor in client - data.Args = append(data.Args, &InitArgData{ - Name: m.VarName, - Ref: m.VarName, - FieldName: m.FieldName, - FieldType: m.FieldType, - TypeName: m.TypeName, - TypeRef: m.TypeRef, - Type: m.Type, - Pointer: m.Pointer, - Required: m.Required, - Validate: m.Validate, - Example: m.Example, - }) - } - for _, m := range trlrs { - // pass the trailers as arguments to result constructor in client - data.Args = append(data.Args, &InitArgData{ - Name: m.VarName, - Ref: m.VarName, - FieldName: m.FieldName, - FieldType: m.FieldType, - TypeName: m.TypeName, - TypeRef: m.TypeRef, - Type: m.Type, - Pointer: m.Pointer, - Required: m.Required, - Validate: m.Validate, - Example: m.Example, - }) - } + data := buildInitData(response, result, "message", "result", svcCtx, false, svr, false, sd) + data.Name = fmt.Sprintf("New%sResult", codegen.Goify(e.Name(), true)) + data.Description = fmt.Sprintf("%s builds the result type of the %q endpoint of the %q service from the gRPC response type.", data.Name, e.Name(), svc.Name) + for _, m := range hdrs { + // pass the headers as arguments to result constructor in client + data.Args = append(data.Args, &InitArgData{ + Name: m.VarName, + Ref: m.VarName, + FieldName: m.FieldName, + FieldType: m.FieldType, + TypeName: m.TypeName, + TypeRef: m.TypeRef, + Type: m.Type, + Pointer: m.Pointer, + Required: m.Required, + Validate: m.Validate, + Example: m.Example, + }) + } + for _, m := range trlrs { + // pass the trailers as arguments to result constructor in client + data.Args = append(data.Args, &InitArgData{ + Name: m.VarName, + Ref: m.VarName, + FieldName: m.FieldName, + FieldType: m.FieldType, + TypeName: m.TypeName, + TypeRef: m.TypeRef, + Type: m.Type, + Pointer: m.Pointer, + Required: m.Required, + Validate: m.Validate, + Example: m.Example, + }) } return &ConvertData{ SrcName: protoBufGoFullTypeName(response, sd.PkgName, sd.Scope), @@ -1018,53 +969,40 @@ func buildResponseConvertData(response, result *expr.AttributeExpr, svcCtx *code // proto if true indicates the target type is a protocol buffer type // svr if true indicates the code is generated for conversion server side func buildInitData(source, target *expr.AttributeExpr, sourceVar, targetVar string, svcCtx *codegen.AttributeContext, proto, _, usesrc bool, sd *ServiceData) *InitData { - var ( - name string - isStruct bool - code string - helpers []*codegen.TransformFunctionData - args []*InitArgData - err error - srcCtx *codegen.AttributeContext - tgtCtx *codegen.AttributeContext - - // pbCtx = protoBufTypeContext(sd.PkgName, sd.Scope, proto && svr || !proto && !svr) - pbCtx = protoBufTypeContext(sd.PkgName, sd.Scope, false) - ) - { - name = "New" - srcCtx = pbCtx - tgtCtx = svcCtx - if proto { - srcCtx = svcCtx - tgtCtx = pbCtx - name += "Proto" - } - isStruct = expr.IsObject(target.Type) || expr.IsUnion(target.Type) - if _, ok := source.Type.(expr.UserType); ok && usesrc { - name += protoBufGoTypeName(source, sd.Scope) - } - n := protoBufGoTypeName(target, sd.Scope) - if !isStruct { - // If target is array, map, or primitive the name will be suffixed with - // the definition (e.g int, []string, map[int]string) which is incorrect. - n = protoBufGoTypeName(source, sd.Scope) - } - name += n - code, helpers, err = protoBufTransform(source, target, sourceVar, targetVar, srcCtx, tgtCtx, proto, true) - if err != nil { - panic(err) // bug - } - sd.transformHelpers = codegen.AppendHelpers(sd.transformHelpers, helpers) - if (!proto && !isEmpty(source.Type)) || (proto && !isEmpty(target.Type)) { - args = []*InitArgData{{ - Name: sourceVar, - Ref: sourceVar, - TypeName: srcCtx.Scope.Name(source, srcCtx.Pkg(source), srcCtx.Pointer, srcCtx.UseDefault), - TypeRef: srcCtx.Scope.Ref(source, srcCtx.Pkg(source)), - Example: source.Example(expr.Root.API.ExampleGenerator), - }} - } + pbCtx := protoBufTypeContext(sd.PkgName, sd.Scope, false) + name := "New" + srcCtx := pbCtx + tgtCtx := svcCtx + if proto { + srcCtx = svcCtx + tgtCtx = pbCtx + name += "Proto" + } + isStruct := expr.IsObject(target.Type) || expr.IsUnion(target.Type) + if _, ok := source.Type.(expr.UserType); ok && usesrc { + name += protoBufGoTypeName(source, sd.Scope) + } + n := protoBufGoTypeName(target, sd.Scope) + if !isStruct { + // If target is array, map, or primitive the name will be suffixed with + // the definition (e.g int, []string, map[int]string) which is incorrect. + n = protoBufGoTypeName(source, sd.Scope) + } + name += n + code, helpers, err := protoBufTransform(source, target, sourceVar, targetVar, srcCtx, tgtCtx, proto, true) + if err != nil { + panic(err) // bug + } + sd.transformHelpers = codegen.AppendHelpers(sd.transformHelpers, helpers) + var args []*InitArgData + if (!proto && !isEmpty(source.Type)) || (proto && !isEmpty(target.Type)) { + args = []*InitArgData{{ + Name: sourceVar, + Ref: sourceVar, + TypeName: srcCtx.Scope.Name(source, srcCtx.Pkg(source), srcCtx.Pointer, srcCtx.UseDefault), + TypeRef: srcCtx.Scope.Ref(source, srcCtx.Pkg(source)), + Example: source.Example(expr.Root.API.ExampleGenerator), + }} } return &InitData{ Name: name, @@ -1081,21 +1019,14 @@ func buildInitData(source, target *expr.AttributeExpr, sourceVar, targetVar stri // endpoint expression. The response message for each error response are // inferred from the method's error expression if not specified explicitly. func buildErrorsData(e *expr.GRPCEndpointExpr, sd *ServiceData) []*ErrorData { - var ( - errors []*ErrorData - - svc = sd.Service - ) - errors = make([]*ErrorData, 0, len(e.GRPCErrors)) + svc := sd.Service + errors := make([]*ErrorData, 0, len(e.GRPCErrors)) for _, v := range e.GRPCErrors { - var responseData *ResponseData - { - responseData = &ResponseData{ - StatusCode: statusCodeToGRPCConst(v.Response.StatusCode), - Description: v.Response.Description, - ServerConvert: buildErrorConvertData(v, e, sd, true), - ClientConvert: buildErrorConvertData(v, e, sd, false), - } + responseData := &ResponseData{ + StatusCode: statusCodeToGRPCConst(v.Response.StatusCode), + Description: v.Response.Description, + ServerConvert: buildErrorConvertData(v, e, sd, true), + ClientConvert: buildErrorConvertData(v, e, sd, false), } errorLoc := svc.Method(e.MethodExpr.Name).ErrorLocs[v.Name] errors = append(errors, &ErrorData{ @@ -1113,20 +1044,14 @@ func buildErrorConvertData(ge *expr.GRPCErrorExpr, e *expr.GRPCEndpointExpr, sd if ge.ErrorExpr.Type == expr.ErrorResult || !expr.IsObject(ge.ErrorExpr.Type) { return nil } - var ( - svc = sd.Service - svcCtx = serviceTypeContext(svc.PkgName, svc.Scope) - ) + svc := sd.Service + svcCtx := serviceTypeContext(svc.PkgName, svc.Scope) if svr { // server side - - var data *InitData - { - data = buildInitData(ge.ErrorExpr.AttributeExpr, ge.Response.Message, "er", "message", svcCtx, true, svr, false, sd) - data.Name = fmt.Sprintf("New%s%sError", codegen.Goify(e.Name(), true), codegen.Goify(ge.Name, true)) - data.Description = fmt.Sprintf("%s builds the gRPC error response type from the error of the %q endpoint of the %q service.", data.Name, e.Name(), svc.Name) - } + data := buildInitData(ge.ErrorExpr.AttributeExpr, ge.Response.Message, "er", "message", svcCtx, true, svr, false, sd) + data.Name = fmt.Sprintf("New%s%sError", codegen.Goify(e.Name(), true), codegen.Goify(ge.Name, true)) + data.Description = fmt.Sprintf("%s builds the gRPC error response type from the error of the %q endpoint of the %q service.", data.Name, e.Name(), svc.Name) return &ConvertData{ SrcName: svcCtx.Scope.Name(ge.ErrorExpr.AttributeExpr, svcCtx.Pkg(ge.ErrorExpr.AttributeExpr), svcCtx.Pointer, svcCtx.UseDefault), SrcRef: svcCtx.Scope.Ref(ge.ErrorExpr.AttributeExpr, svcCtx.Pkg(ge.ErrorExpr.AttributeExpr)), @@ -1137,13 +1062,9 @@ func buildErrorConvertData(ge *expr.GRPCErrorExpr, e *expr.GRPCEndpointExpr, sd } // client side - - var data *InitData - { - data = buildInitData(ge.Response.Message, ge.ErrorExpr.AttributeExpr, "message", "er", svcCtx, false, svr, false, sd) - data.Name = fmt.Sprintf("New%s%sError", codegen.Goify(e.Name(), true), codegen.Goify(ge.Name, true)) - data.Description = fmt.Sprintf("%s builds the error type of the %q endpoint of the %q service from the gRPC error response type.", data.Name, e.Name(), svc.Name) - } + data := buildInitData(ge.Response.Message, ge.ErrorExpr.AttributeExpr, "message", "er", svcCtx, false, svr, false, sd) + data.Name = fmt.Sprintf("New%s%sError", codegen.Goify(e.Name(), true), codegen.Goify(ge.Name, true)) + data.Description = fmt.Sprintf("%s builds the error type of the %q endpoint of the %q service from the gRPC error response type.", data.Name, e.Name(), svc.Name) return &ConvertData{ SrcName: protoBufGoFullTypeName(ge.Response.Message, sd.PkgName, sd.Scope), SrcRef: protoBufGoFullTypeRef(ge.Response.Message, sd.PkgName, sd.Scope), @@ -1176,89 +1097,86 @@ func buildStreamData(e *expr.GRPCEndpointExpr, sd *ServiceData, svr bool) *Strea recvConvert *ConvertData mustClose bool typ string - - svc = sd.Service - ed = sd.Endpoint(e.Name()) - md = ed.Method - svcCtx = serviceTypeContext(svc.PkgName, svc.Scope) - result, resCtx = resultContext(e, sd) ) - { - resVar := "result" - if md.ViewedResult != nil { - resVar = "vresult" - } - if svr { - typ = "server" - varn = md.ServerStream.VarName - intName = fmt.Sprintf("%s.%s_%sServer", sd.PkgName, svc.StructName, md.VarName) - svcInt = fmt.Sprintf("%s.%s", svc.PkgName, md.ServerStream.Interface) - if e.MethodExpr.Result.Type != expr.Empty { - sendName = md.ServerStream.SendName - sendRef = ed.ResultRef - sendWithContextName = md.ServerStream.SendWithContextName - sendConvert = &ConvertData{ - SrcName: resCtx.Scope.Name(result, resCtx.Pkg(result), resCtx.Pointer, resCtx.UseDefault), - SrcRef: resCtx.Scope.Ref(result, resCtx.Pkg(result)), - TgtName: protoBufGoFullTypeName(e.Response.Message, sd.PkgName, sd.Scope), - TgtRef: protoBufGoFullTypeRef(e.Response.Message, sd.PkgName, sd.Scope), - Init: buildInitData(result, e.Response.Message, resVar, "v", resCtx, true, svr, true, sd), - } - } - if e.MethodExpr.StreamingPayload.Type != expr.Empty { - recvName = md.ServerStream.RecvName - recvWithContextName = md.ServerStream.RecvWithContextName - recvRef = svcCtx.Scope.Ref(e.MethodExpr.StreamingPayload, svcCtx.Pkg(e.MethodExpr.StreamingPayload)) - recvConvert = &ConvertData{ - SrcName: protoBufGoFullTypeName(e.StreamingRequest, sd.PkgName, sd.Scope), - SrcRef: protoBufGoFullTypeRef(e.StreamingRequest, sd.PkgName, sd.Scope), - TgtName: svcCtx.Scope.Name(e.MethodExpr.StreamingPayload, svcCtx.Pkg(e.MethodExpr.StreamingPayload), svcCtx.Pointer, svcCtx.UseDefault), - TgtRef: recvRef, - Init: buildInitData(e.StreamingRequest, e.MethodExpr.StreamingPayload, "v", "spayload", svcCtx, false, svr, true, sd), - Validation: addValidation(e.StreamingRequest, "stream", sd, true), - } - } - mustClose = md.ServerStream.MustClose - } else { - typ = "client" - varn = md.ClientStream.VarName - intName = fmt.Sprintf("%s.%s_%sClient", sd.PkgName, svc.StructName, md.VarName) - svcInt = fmt.Sprintf("%s.%s", svc.PkgName, md.ClientStream.Interface) - if e.MethodExpr.StreamingPayload.Type != expr.Empty { - sendName = md.ClientStream.SendName - sendWithContextName = md.ClientStream.SendWithContextName - sendRef = svcCtx.Scope.Ref(e.MethodExpr.StreamingPayload, svcCtx.Pkg(e.MethodExpr.StreamingPayload)) - sendConvert = &ConvertData{ - SrcName: svcCtx.Scope.Name(e.MethodExpr.StreamingPayload, svcCtx.Pkg(e.MethodExpr.StreamingPayload), svcCtx.Pointer, svcCtx.UseDefault), - SrcRef: sendRef, - TgtName: protoBufGoFullTypeName(e.StreamingRequest, sd.PkgName, sd.Scope), - TgtRef: protoBufGoFullTypeRef(e.StreamingRequest, sd.PkgName, sd.Scope), - Init: buildInitData(e.MethodExpr.StreamingPayload, e.StreamingRequest, "spayload", "v", svcCtx, true, svr, true, sd), - } + svc := sd.Service + ed := sd.Endpoint(e.Name()) + md := ed.Method + svcCtx := serviceTypeContext(svc.PkgName, svc.Scope) + result, resCtx := resultContext(e, sd) + resVar := "result" + if md.ViewedResult != nil { + resVar = "vresult" + } + if svr { + typ = "server" + varn = md.ServerStream.VarName + intName = fmt.Sprintf("%s.%s_%sServer", sd.PkgName, svc.StructName, md.VarName) + svcInt = fmt.Sprintf("%s.%s", svc.PkgName, md.ServerStream.Interface) + if e.MethodExpr.Result.Type != expr.Empty { + sendName = md.ServerStream.SendName + sendRef = ed.ResultRef + sendWithContextName = md.ServerStream.SendWithContextName + sendConvert = &ConvertData{ + SrcName: resCtx.Scope.Name(result, resCtx.Pkg(result), resCtx.Pointer, resCtx.UseDefault), + SrcRef: resCtx.Scope.Ref(result, resCtx.Pkg(result)), + TgtName: protoBufGoFullTypeName(e.Response.Message, sd.PkgName, sd.Scope), + TgtRef: protoBufGoFullTypeRef(e.Response.Message, sd.PkgName, sd.Scope), + Init: buildInitData(result, e.Response.Message, resVar, "v", resCtx, true, svr, true, sd), } - if e.MethodExpr.Result.Type != expr.Empty { - recvName = md.ClientStream.RecvName - recvWithContextName = md.ClientStream.RecvWithContextName - recvRef = ed.ResultRef - recvConvert = &ConvertData{ - SrcName: protoBufGoFullTypeName(e.Response.Message, sd.PkgName, sd.Scope), - SrcRef: protoBufGoFullTypeRef(e.Response.Message, sd.PkgName, sd.Scope), - TgtName: resCtx.Scope.Name(result, resCtx.Pkg(result), resCtx.Pointer, resCtx.UseDefault), - TgtRef: resCtx.Scope.Ref(result, resCtx.Pkg(result)), - Init: buildInitData(e.Response.Message, result, "v", resVar, resCtx, false, svr, true, sd), - Validation: addValidation(e.Response.Message, "stream", sd, false), - } + } + if e.MethodExpr.StreamingPayload.Type != expr.Empty { + recvName = md.ServerStream.RecvName + recvWithContextName = md.ServerStream.RecvWithContextName + recvRef = svcCtx.Scope.Ref(e.MethodExpr.StreamingPayload, svcCtx.Pkg(e.MethodExpr.StreamingPayload)) + recvConvert = &ConvertData{ + SrcName: protoBufGoFullTypeName(e.StreamingRequest, sd.PkgName, sd.Scope), + SrcRef: protoBufGoFullTypeRef(e.StreamingRequest, sd.PkgName, sd.Scope), + TgtName: svcCtx.Scope.Name(e.MethodExpr.StreamingPayload, svcCtx.Pkg(e.MethodExpr.StreamingPayload), svcCtx.Pointer, svcCtx.UseDefault), + TgtRef: recvRef, + Init: buildInitData(e.StreamingRequest, e.MethodExpr.StreamingPayload, "v", "spayload", svcCtx, false, svr, true, sd), + Validation: addValidation(e.StreamingRequest, "stream", sd, true), } - mustClose = md.ClientStream.MustClose } - if sendConvert != nil { - sendDesc = fmt.Sprintf("%s streams instances of %q to the %q endpoint gRPC stream.", sendName, sendConvert.TgtName, md.Name) - sendWithContextDesc = fmt.Sprintf("%s streams instances of %q to the %q endpoint gRPC stream with context.", sendWithContextName, sendConvert.TgtName, md.Name) + mustClose = md.ServerStream.MustClose + } else { + typ = "client" + varn = md.ClientStream.VarName + intName = fmt.Sprintf("%s.%s_%sClient", sd.PkgName, svc.StructName, md.VarName) + svcInt = fmt.Sprintf("%s.%s", svc.PkgName, md.ClientStream.Interface) + if e.MethodExpr.StreamingPayload.Type != expr.Empty { + sendName = md.ClientStream.SendName + sendWithContextName = md.ClientStream.SendWithContextName + sendRef = svcCtx.Scope.Ref(e.MethodExpr.StreamingPayload, svcCtx.Pkg(e.MethodExpr.StreamingPayload)) + sendConvert = &ConvertData{ + SrcName: svcCtx.Scope.Name(e.MethodExpr.StreamingPayload, svcCtx.Pkg(e.MethodExpr.StreamingPayload), svcCtx.Pointer, svcCtx.UseDefault), + SrcRef: sendRef, + TgtName: protoBufGoFullTypeName(e.StreamingRequest, sd.PkgName, sd.Scope), + TgtRef: protoBufGoFullTypeRef(e.StreamingRequest, sd.PkgName, sd.Scope), + Init: buildInitData(e.MethodExpr.StreamingPayload, e.StreamingRequest, "spayload", "v", svcCtx, true, svr, true, sd), + } } - if recvConvert != nil { - recvDesc = fmt.Sprintf("%s reads instances of %q from the %q endpoint gRPC stream.", recvName, recvConvert.SrcName, md.Name) - recvWithContextDesc = fmt.Sprintf("%s reads instances of %q from the %q endpoint gRPC stream with context.", recvWithContextName, recvConvert.SrcName, md.Name) + if e.MethodExpr.Result.Type != expr.Empty { + recvName = md.ClientStream.RecvName + recvWithContextName = md.ClientStream.RecvWithContextName + recvRef = ed.ResultRef + recvConvert = &ConvertData{ + SrcName: protoBufGoFullTypeName(e.Response.Message, sd.PkgName, sd.Scope), + SrcRef: protoBufGoFullTypeRef(e.Response.Message, sd.PkgName, sd.Scope), + TgtName: resCtx.Scope.Name(result, resCtx.Pkg(result), resCtx.Pointer, resCtx.UseDefault), + TgtRef: resCtx.Scope.Ref(result, resCtx.Pkg(result)), + Init: buildInitData(e.Response.Message, result, "v", resVar, resCtx, false, svr, true, sd), + Validation: addValidation(e.Response.Message, "stream", sd, false), + } } + mustClose = md.ClientStream.MustClose + } + if sendConvert != nil { + sendDesc = fmt.Sprintf("%s streams instances of %q to the %q endpoint gRPC stream.", sendName, sendConvert.TgtName, md.Name) + sendWithContextDesc = fmt.Sprintf("%s streams instances of %q to the %q endpoint gRPC stream with context.", sendWithContextName, sendConvert.TgtName, md.Name) + } + if recvConvert != nil { + recvDesc = fmt.Sprintf("%s reads instances of %q from the %q endpoint gRPC stream.", recvName, recvConvert.SrcName, md.Name) + recvWithContextDesc = fmt.Sprintf("%s reads instances of %q from the %q endpoint gRPC stream with context.", recvWithContextName, recvConvert.SrcName, md.Name) } return &StreamData{ VarName: varn, @@ -1288,28 +1206,21 @@ func extractMetadata(a *expr.MappedAttributeExpr, service *expr.AttributeExpr, s var metadata []*MetadataData ctx := serviceTypeContext("", scope) codegen.WalkMappedAttr(a, func(name, elem string, required bool, c *expr.AttributeExpr) error { // nolint: errcheck - var ( - varn string - fieldName string - pointer bool - - arr = expr.AsArray(c.Type) - mp = expr.AsMap(c.Type) - typeRef = scope.GoTypeRef(unalias(c)) - ft = service.Type - ) - { - varn = scope.Name(codegen.Goify(name, false)) - fieldName = codegen.Goify(name, true) - if !expr.IsObject(service.Type) { - fieldName = "" - } else { - pointer = service.IsPrimitivePointer(name, true) - ft = service.Find(name).Type - } - if pointer { - typeRef = "*" + typeRef - } + arr := expr.AsArray(c.Type) + mp := expr.AsMap(c.Type) + typeRef := scope.GoTypeRef(unalias(c)) + ft := service.Type + varn := scope.Name(codegen.Goify(name, false)) + fieldName := codegen.Goify(name, true) + var pointer bool + if !expr.IsObject(service.Type) { + fieldName = "" + } else { + pointer = service.IsPrimitivePointer(name, true) + ft = service.Find(name).Type + } + if pointer { + typeRef = "*" + typeRef } metadata = append(metadata, &MetadataData{ Name: elem, diff --git a/http/codegen/websocket.go b/http/codegen/websocket.go index 0439b81622..de75f4c28f 100644 --- a/http/codegen/websocket.go +++ b/http/codegen/websocket.go @@ -75,129 +75,118 @@ type ( // initWebSocketData initializes the WebSocket related data in ed. func initWebSocketData(ed *EndpointData, e *expr.HTTPEndpointExpr, sd *ServiceData) { var ( - svrSendTypeName string - svrSendTypeRef string svrRecvTypeName string svrRecvTypeRef string - svrSendDesc string - svrSendWithContextDesc string svrRecvDesc string svrRecvWithContextDesc string svrPayload *TypeData cliSendDesc string cliSendWithContextDesc string - cliRecvDesc string - cliRecvWithContextDesc string cliPayload *TypeData - - md = ed.Method - svc = sd.Service - svcctx = serviceContext(sd.Service.PkgName, sd.Service.Scope) ) - { - svrSendTypeName = ed.Result.Name - svrSendTypeRef = ed.Result.Ref - svrSendDesc = fmt.Sprintf("%s streams instances of %q to the %q endpoint websocket connection.", md.ServerStream.SendName, svrSendTypeName, md.Name) - svrSendWithContextDesc = fmt.Sprintf("%s streams instances of %q to the %q endpoint websocket connection with context.", md.ServerStream.SendWithContextName, svrSendTypeName, md.Name) - cliRecvDesc = fmt.Sprintf("%s reads instances of %q from the %q endpoint websocket connection.", md.ClientStream.RecvName, svrSendTypeName, md.Name) - cliRecvWithContextDesc = fmt.Sprintf("%s reads instances of %q from the %q endpoint websocket connection with context.", md.ClientStream.RecvWithContextName, svrSendTypeName, md.Name) - if e.MethodExpr.Stream == expr.ClientStreamKind || e.MethodExpr.Stream == expr.BidirectionalStreamKind { - svrRecvTypeName = sd.Scope.GoFullTypeName(e.MethodExpr.StreamingPayload, svc.PkgName) - svrRecvTypeRef = sd.Scope.GoFullTypeRef(e.MethodExpr.StreamingPayload, svc.PkgName) - svrPayload = buildRequestBodyType(e.StreamingBody, e.MethodExpr.StreamingPayload, e, true, sd) - if needInit(e.MethodExpr.StreamingPayload.Type) { - makeHTTPType(e.StreamingBody) - body := e.StreamingBody.Type - // generate constructor function to transform request body, - // into the method streaming payload type + md := ed.Method + svc := sd.Service + svcctx := serviceContext(sd.Service.PkgName, sd.Service.Scope) + svrSendTypeName := ed.Result.Name + svrSendTypeRef := ed.Result.Ref + svrSendDesc := fmt.Sprintf("%s streams instances of %q to the %q endpoint websocket connection.", md.ServerStream.SendName, svrSendTypeName, md.Name) + svrSendWithContextDesc := fmt.Sprintf("%s streams instances of %q to the %q endpoint websocket connection with context.", md.ServerStream.SendWithContextName, svrSendTypeName, md.Name) + cliRecvDesc := fmt.Sprintf("%s reads instances of %q from the %q endpoint websocket connection.", md.ClientStream.RecvName, svrSendTypeName, md.Name) + cliRecvWithContextDesc := fmt.Sprintf("%s reads instances of %q from the %q endpoint websocket connection with context.", md.ClientStream.RecvWithContextName, svrSendTypeName, md.Name) + if e.MethodExpr.Stream == expr.ClientStreamKind || e.MethodExpr.Stream == expr.BidirectionalStreamKind { + svrRecvTypeName = sd.Scope.GoFullTypeName(e.MethodExpr.StreamingPayload, svc.PkgName) + svrRecvTypeRef = sd.Scope.GoFullTypeRef(e.MethodExpr.StreamingPayload, svc.PkgName) + svrPayload = buildRequestBodyType(e.StreamingBody, e.MethodExpr.StreamingPayload, e, true, sd) + if needInit(e.MethodExpr.StreamingPayload.Type) { + makeHTTPType(e.StreamingBody) + body := e.StreamingBody.Type + // generate constructor function to transform request body, + // into the method streaming payload type + var ( + name string + desc string + serverArgs []*InitArgData + serverCode string + err error + ) + n := codegen.Goify(e.MethodExpr.Name, true) + p := codegen.Goify(svrPayload.Name, true) + // Raw payload object has type name prefixed with endpoint name. No need to + // prefix the type name again. + if strings.HasPrefix(p, n) { + name = fmt.Sprintf("New%s", p) + } else { + name = fmt.Sprintf("New%s%s", n, p) + } + desc = fmt.Sprintf("%s builds a %s service %s endpoint payload.", name, svc.Name, e.MethodExpr.Name) + if body != expr.Empty { var ( - name string - desc string - serverArgs []*InitArgData - serverCode string - err error + ref string + svcode string ) { - n := codegen.Goify(e.MethodExpr.Name, true) - p := codegen.Goify(svrPayload.Name, true) - // Raw payload object has type name prefixed with endpoint name. No need to - // prefix the type name again. - if strings.HasPrefix(p, n) { - name = fmt.Sprintf("New%s", p) - } else { - name = fmt.Sprintf("New%s%s", n, p) + ref = "body" + if expr.IsObject(body) { + ref = "&body" } - desc = fmt.Sprintf("%s builds a %s service %s endpoint payload.", name, svc.Name, e.MethodExpr.Name) - if body != expr.Empty { - var ( - ref string - svcode string - ) - { - ref = "body" - if expr.IsObject(body) { - ref = "&body" - } - if ut, ok := body.(expr.UserType); ok { - if val := ut.Attribute().Validation; val != nil { - httpctx := httpContext("", sd.Scope, true, true) - svcode = codegen.ValidationCode(ut.Attribute(), ut, httpctx, true, expr.IsAlias(ut), false, "body") - } - } + if ut, ok := body.(expr.UserType); ok { + if val := ut.Attribute().Validation; val != nil { + httpctx := httpContext("", sd.Scope, true, true) + svcode = codegen.ValidationCode(ut.Attribute(), ut, httpctx, true, expr.IsAlias(ut), false, "body") } - serverArgs = []*InitArgData{{ - Ref: ref, - AttributeData: &AttributeData{ - Name: "payload", - VarName: "body", - TypeName: sd.Scope.GoTypeName(e.StreamingBody), - TypeRef: sd.Scope.GoTypeRef(e.StreamingBody), - Type: e.StreamingBody.Type, - Required: true, - Example: e.Body.Example(expr.Root.API.ExampleGenerator), - Validate: svcode, - }, - }} - } - if body != expr.Empty { - var helpers []*codegen.TransformFunctionData - httpctx := httpContext("", sd.Scope, true, true) - serverCode, helpers, err = marshal(e.StreamingBody, e.MethodExpr.StreamingPayload, "body", "v", httpctx, svcctx) - if err == nil { - sd.ServerTransformHelpers = codegen.AppendHelpers(sd.ServerTransformHelpers, helpers) - } - } - if err != nil { - fmt.Println(err.Error()) // TBD validate DSL so errors are not possible } } - svrPayload.Init = &InitData{ - Name: name, - Description: desc, - ServerArgs: serverArgs, - ReturnTypeName: svc.Scope.GoFullTypeName(e.MethodExpr.StreamingPayload, svc.PkgName), - ReturnTypeRef: svc.Scope.GoFullTypeRef(e.MethodExpr.StreamingPayload, svc.PkgName), - ReturnIsStruct: expr.IsObject(e.MethodExpr.StreamingPayload.Type), - ReturnTypePkg: svc.PkgName, - ServerCode: serverCode, + serverArgs = []*InitArgData{{ + Ref: ref, + AttributeData: &AttributeData{ + Name: "payload", + VarName: "body", + TypeName: sd.Scope.GoTypeName(e.StreamingBody), + TypeRef: sd.Scope.GoTypeRef(e.StreamingBody), + Type: e.StreamingBody.Type, + Required: true, + Example: e.Body.Example(expr.Root.API.ExampleGenerator), + Validate: svcode, + }, + }} + } + if body != expr.Empty { + var helpers []*codegen.TransformFunctionData + httpctx := httpContext("", sd.Scope, true, true) + serverCode, helpers, err = marshal(e.StreamingBody, e.MethodExpr.StreamingPayload, "body", "v", httpctx, svcctx) + if err == nil { + sd.ServerTransformHelpers = codegen.AppendHelpers(sd.ServerTransformHelpers, helpers) } } - cliPayload = buildRequestBodyType(e.StreamingBody, e.MethodExpr.StreamingPayload, e, false, sd) - if cliPayload != nil { - sd.ClientTypeNames[cliPayload.Name] = false - sd.ServerTypeNames[cliPayload.Name] = false + if err != nil { + fmt.Println(err.Error()) // TBD validate DSL so errors are not possible } - if e.MethodExpr.Stream == expr.ClientStreamKind { - svrSendDesc = fmt.Sprintf("%s streams instances of %q to the %q endpoint websocket connection and closes the connection.", md.ServerStream.SendName, svrSendTypeName, md.Name) - svrSendWithContextDesc = fmt.Sprintf("%s streams instances of %q to the %q endpoint websocket connection with context and closes the connection.", md.ServerStream.SendWithContextName, svrSendTypeName, md.Name) - cliRecvDesc = fmt.Sprintf("%s stops sending messages to the %q endpoint websocket connection and reads instances of %q from the connection.", md.ClientStream.RecvName, md.Name, svrSendTypeName) - cliRecvWithContextDesc = fmt.Sprintf("%s stops sending messages to the %q endpoint websocket connection and reads instances of %q from the connection with context.", md.ClientStream.RecvWithContextName, md.Name, svrSendTypeName) + svrPayload.Init = &InitData{ + Name: name, + Description: desc, + ServerArgs: serverArgs, + ReturnTypeName: svc.Scope.GoFullTypeName(e.MethodExpr.StreamingPayload, svc.PkgName), + ReturnTypeRef: svc.Scope.GoFullTypeRef(e.MethodExpr.StreamingPayload, svc.PkgName), + ReturnIsStruct: expr.IsObject(e.MethodExpr.StreamingPayload.Type), + ReturnTypePkg: svc.PkgName, + ServerCode: serverCode, } - svrRecvDesc = fmt.Sprintf("%s reads instances of %q from the %q endpoint websocket connection.", md.ServerStream.RecvName, svrRecvTypeName, md.Name) - svrRecvWithContextDesc = fmt.Sprintf("%s reads instances of %q from the %q endpoint websocket connection with context.", md.ServerStream.RecvWithContextName, svrRecvTypeName, md.Name) - cliSendDesc = fmt.Sprintf("%s streams instances of %q to the %q endpoint websocket connection.", md.ClientStream.SendName, svrRecvTypeName, md.Name) - cliSendWithContextDesc = fmt.Sprintf("%s streams instances of %q to the %q endpoint websocket connection with context.", md.ClientStream.SendWithContextName, svrRecvTypeName, md.Name) } + cliPayload = buildRequestBodyType(e.StreamingBody, e.MethodExpr.StreamingPayload, e, false, sd) + if cliPayload != nil { + sd.ClientTypeNames[cliPayload.Name] = false + sd.ServerTypeNames[cliPayload.Name] = false + } + if e.MethodExpr.Stream == expr.ClientStreamKind { + svrSendDesc = fmt.Sprintf("%s streams instances of %q to the %q endpoint websocket connection and closes the connection.", md.ServerStream.SendName, svrSendTypeName, md.Name) + svrSendWithContextDesc = fmt.Sprintf("%s streams instances of %q to the %q endpoint websocket connection with context and closes the connection.", md.ServerStream.SendWithContextName, svrSendTypeName, md.Name) + cliRecvDesc = fmt.Sprintf("%s stops sending messages to the %q endpoint websocket connection and reads instances of %q from the connection.", md.ClientStream.RecvName, md.Name, svrSendTypeName) + cliRecvWithContextDesc = fmt.Sprintf("%s stops sending messages to the %q endpoint websocket connection and reads instances of %q from the connection with context.", md.ClientStream.RecvWithContextName, md.Name, svrSendTypeName) + } + svrRecvDesc = fmt.Sprintf("%s reads instances of %q from the %q endpoint websocket connection.", md.ServerStream.RecvName, svrRecvTypeName, md.Name) + svrRecvWithContextDesc = fmt.Sprintf("%s reads instances of %q from the %q endpoint websocket connection with context.", md.ServerStream.RecvWithContextName, svrRecvTypeName, md.Name) + cliSendDesc = fmt.Sprintf("%s streams instances of %q to the %q endpoint websocket connection.", md.ClientStream.SendName, svrRecvTypeName, md.Name) + cliSendWithContextDesc = fmt.Sprintf("%s streams instances of %q to the %q endpoint websocket connection with context.", md.ClientStream.SendWithContextName, svrRecvTypeName, md.Name) } ed.ServerWebSocket = &WebSocketData{ VarName: md.ServerStream.VarName, From 77667dc36dd98e97a3d700529e96aa4b87bfe6db Mon Sep 17 00:00:00 2001 From: Raphael Simon Date: Sat, 8 Feb 2025 15:50:48 -0800 Subject: [PATCH 23/23] Fix lint issue --- http/codegen/websocket.go | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/http/codegen/websocket.go b/http/codegen/websocket.go index de75f4c28f..b0df17604a 100644 --- a/http/codegen/websocket.go +++ b/http/codegen/websocket.go @@ -120,20 +120,15 @@ func initWebSocketData(ed *EndpointData, e *expr.HTTPEndpointExpr, sd *ServiceDa } desc = fmt.Sprintf("%s builds a %s service %s endpoint payload.", name, svc.Name, e.MethodExpr.Name) if body != expr.Empty { - var ( - ref string - svcode string - ) - { - ref = "body" - if expr.IsObject(body) { - ref = "&body" - } - if ut, ok := body.(expr.UserType); ok { - if val := ut.Attribute().Validation; val != nil { - httpctx := httpContext("", sd.Scope, true, true) - svcode = codegen.ValidationCode(ut.Attribute(), ut, httpctx, true, expr.IsAlias(ut), false, "body") - } + ref := "body" + if expr.IsObject(body) { + ref = "&body" + } + var svcode string + if ut, ok := body.(expr.UserType); ok { + if val := ut.Attribute().Validation; val != nil { + httpctx := httpContext("", sd.Scope, true, true) + svcode = codegen.ValidationCode(ut.Attribute(), ut, httpctx, true, expr.IsAlias(ut), false, "body") } } serverArgs = []*InitArgData{{