docs: update README for context.Context and middlewares
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
Adrien Marquès 2021-06-20 02:16:24 +02:00
parent af63c4514b
commit 97941da901
Signed by: xdrm-brackets
GPG Key ID: D75243CA236D825E
1 changed files with 7 additions and 2 deletions

View File

@ -107,12 +107,17 @@ func main() {
log.Fatalf("invalid config: %s", err) 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 // bind handlers
err = builder.Bind(http.MethodGet, "/user/{id}", getUserById) err = builder.Bind(http.MethodGet, "/user/{id}", getUserById)
if err != nil { if err != nil {
log.Fatalf("cannog bind GET /user/{id}: %s", err) log.Fatalf("cannog bind GET /user/{id}: %s", err)
} }
// ...
// build your services // build your services
handler, err := builder.Build() handler, err := builder.Build()
@ -261,7 +266,7 @@ type res struct{
Output2 bool Output2 bool
} }
func myHandler(ctx *api.Context, r req) (*res, api.Err) { func myHandler(ctx context.Context, r req) (*res, api.Err) {
err := doSomething() err := doSomething()
if err != nil { if err != nil {
return nil, api.ErrFailure return nil, api.ErrFailure