Created
March 1, 2019 22:43
-
-
Save mlafeldt/0ba38a819030e18d053cedb144839aea to your computer and use it in GitHub Desktop.
Revisions
-
mlafeldt created this gist
Mar 1, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ func main() { lambda.StartHandler(middleware(handler)) } type handlerFunc func(ctx context.Context, payload []byte) ([]byte, error) func (h handlerFunc) Invoke(ctx context.Context, input []byte) ([]byte, error) { log.Printf("[DEBUG] input = %s", string(input)) output, err := h(ctx, input) log.Printf("[DEBUG] output = %s", string(output)) return output, err } func middleware(originalHandler interface{}) lambda.Handler { handler := lambda.NewHandler(originalHandler) return handlerFunc(func(ctx context.Context, payload []byte) ([]byte, error) { ctx = handlertrace.NewContext(ctx, handlertrace.HandlerTrace{ RequestEvent: func(c context.Context, e interface{}) { log.Printf("[DEBUG] input = %+v", e) }, ResponseEvent: func(c context.Context, e interface{}) { log.Printf("[DEBUG] output = %+v", e) }, }) return handler.Invoke(ctx, payload) }) } func handler(input Input) (*Output, error) { // ... }