MCPcopy Index your code
hub / github.com/aws/aws-lambda-go / handlerTakesContext

Function handlerTakesContext

lambda/handler.go:95–124  ·  view source on GitHub ↗

handlerTakesContext returns whether the handler takes a context.Context as its first argument.

(handler reflect.Type)

Source from the content-addressed store, hash-verified

93
94// handlerTakesContext returns whether the handler takes a context.Context as its first argument.
95func handlerTakesContext(handler reflect.Type) (bool, error) {
96 switch handler.NumIn() {
97 case 0:
98 return false, nil
99 case 1:
100 contextType := reflect.TypeOf((*context.Context)(nil)).Elem()
101 argumentType := handler.In(0)
102 if argumentType.Kind() != reflect.Interface {
103 return false, nil
104 }
105
106 // handlers like func(event any) are valid.
107 if argumentType.NumMethod() == 0 {
108 return false, nil
109 }
110
111 if !contextType.Implements(argumentType) || !argumentType.Implements(contextType) {
112 return false, fmt.Errorf("handler takes an interface, but it is not context.Context: %q", argumentType.Name())
113 }
114 return true, nil
115 case 2:
116 contextType := reflect.TypeOf((*context.Context)(nil)).Elem()
117 argumentType := handler.In(0)
118 if argumentType.Kind() != reflect.Interface || !contextType.Implements(argumentType) || !argumentType.Implements(contextType) {
119 return false, fmt.Errorf("handler takes two arguments, but the first is not Context. got %s", argumentType.Kind())
120 }
121 return true, nil
122 }
123 return false, fmt.Errorf("handlers may not take more than two arguments, but handler takes %d", handler.NumIn())
124}
125
126func validateReturns(handler reflect.Type) error {
127 errorType := reflect.TypeOf((*error)(nil)).Elem()

Callers 2

TestStartHandlerFuncFunction · 0.85
reflectHandlerFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestStartHandlerFuncFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…