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())
| 27 | // }) |
| 28 | // }) |
| 29 | func 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 | // |