Skip to content

Commit d1db444

Browse files
committed
add some usage examples
1 parent 5420fb9 commit d1db444

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

lambda/handler.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,44 @@ type handlerOptions struct {
2828
type Option func(*handlerOptions)
2929

3030
// WithContext is a HandlerOption that sets the base context for all invocations of the handler.
31+
//
32+
// Usage:
33+
// lambda.StartWithOptions(
34+
// func (ctx context.Context) (string, error) {
35+
// return ctx.Value("foo"), nil
36+
// },
37+
// lambda.WithContext(context.WithValue(context.Background(), "foo", "bar"))
38+
// )
3139
func WithContext(ctx context.Context) Option {
3240
return Option(func(h *handlerOptions) {
3341
h.baseContext = ctx
3442
})
3543
}
3644

3745
// WithSetEscapeHTML sets the SetEscapeHTML argument on the underlying json encoder
46+
//
47+
// Usage:
48+
// lambda.StartWithOptions(
49+
// func () (string, error) {
50+
// return "<html><body>hello!></body></html>", nil
51+
// },
52+
// lambda.WithSetEscapeHTML(true),
53+
// )
3854
func WithSetEscapeHTML(escapeHTML bool) Option {
3955
return Option(func(h *handlerOptions) {
4056
h.jsonResponseEscapeHTML = escapeHTML
4157
})
4258
}
4359

4460
// WithSetIndent sets the SetIndent argument on the underling json encoder
61+
//
62+
// Usage:
63+
// lambda.StartWithOptions(
64+
// func (event any) (any, error) {
65+
// return event, nil
66+
// },
67+
// lambda.WithSetIndent(">"," "),
68+
// )
4569
func WithSetIndent(prefix, indent string) Option {
4670
return Option(func(h *handlerOptions) {
4771
h.jsonResponseIndentPrefix = prefix

0 commit comments

Comments
 (0)