MCPcopy Create free account
hub / github.com/goadesign/goa / Interceptor

Function Interceptor

dsl/interceptor.go:29–52  ·  view source on GitHub ↗

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 an API, Service or Method expression. Interceptor accepts two arguments: the name of the interceptor and the defining DSL. Example:

(name string, fn ...func())

Source from the content-addressed store, hash-verified

27// })
28// })
29func Interceptor(name string, fn ...func()) *expr.InterceptorExpr {
30 if len(fn) > 1 {
31 eval.ReportError("interceptor %q cannot have multiple definitions", name)
32 return nil
33 }
34 i := &expr.InterceptorExpr{Name: name}
35 if name == "" {
36 eval.ReportError("interceptor name cannot be empty")
37 return i
38 }
39 if len(fn) > 0 {
40 if !eval.Execute(fn[0], i) {
41 return i
42 }
43 }
44 for _, i := range expr.Root.Interceptors {
45 if i.Name == name {
46 eval.ReportError("interceptor %q already defined", name)
47 return i
48 }
49 }
50 expr.Root.Interceptors = append(expr.Root.Interceptors, i)
51 return i
52}
53
54// ReadPayload defines the payload attributes read by the interceptor.
55//

Callers 9

dsls.goFile · 0.85
TestInterceptorFunction · 0.85
TestServerInterceptorFunction · 0.85
TestClientInterceptorFunction · 0.85
service_dsls.goFile · 0.85
endpoint_dsls.goFile · 0.85

Calls 2

ReportErrorFunction · 0.92
ExecuteFunction · 0.92

Tested by 3

TestInterceptorFunction · 0.68
TestServerInterceptorFunction · 0.68
TestClientInterceptorFunction · 0.68