ExtractUserParamOptional does not fail if no user is present.
(db database.Store)
| 55 | |
| 56 | // ExtractUserParamOptional does not fail if no user is present. |
| 57 | func ExtractUserParamOptional(db database.Store) func(http.Handler) http.Handler { |
| 58 | return func(next http.Handler) http.Handler { |
| 59 | return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { |
| 60 | ctx := r.Context() |
| 61 | |
| 62 | user, ok := ExtractUserContext(ctx, db, &httpapi.NoopResponseWriter{}, r) |
| 63 | if ok { |
| 64 | ctx = context.WithValue(ctx, userParamContextKey{}, user) |
| 65 | } |
| 66 | |
| 67 | next.ServeHTTP(rw, r.WithContext(ctx)) |
| 68 | }) |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | // ExtractUserContext queries the database for the parameterized `{user}` from the request URL. |
| 73 | func ExtractUserContext(ctx context.Context, db database.Store, rw http.ResponseWriter, r *http.Request) (user database.User, ok bool) { |
nothing calls this directly
no test coverage detected