From 97941da9012f7c76d520c9582c77ba414e1fdfa5 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sun, 20 Jun 2021 02:16:24 +0200 Subject: [PATCH] docs: update README for context.Context and middlewares --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0cda3fc..c2182e6 100644 --- a/README.md +++ b/README.md @@ -107,12 +107,17 @@ func main() { log.Fatalf("invalid config: %s", err) } + // add http middlewares (logger) + builder.With(func(next http.Handler) http.Handler{ /* ... */ }) + + // add contextual middlewares (authentication) + builder.WithContext(func(next http.Handler) http.Handler{ /* ... */ }) + // bind handlers err = builder.Bind(http.MethodGet, "/user/{id}", getUserById) if err != nil { log.Fatalf("cannog bind GET /user/{id}: %s", err) } - // ... // build your services handler, err := builder.Build() @@ -261,7 +266,7 @@ type res struct{ Output2 bool } -func myHandler(ctx *api.Context, r req) (*res, api.Err) { +func myHandler(ctx context.Context, r req) (*res, api.Err) { err := doSomething() if err != nil { return nil, api.ErrFailure