MCPcopy Index your code
hub / github.com/coder/coder / ExtractUserParam

Function ExtractUserParam

coderd/httpmw/userparam.go:41–54  ·  view source on GitHub ↗

ExtractUserParam extracts a user from an ID/username in the {user} URL parameter.

(db database.Store)

Source from the content-addressed store, hash-verified

39// ExtractUserParam extracts a user from an ID/username in the {user} URL
40// parameter.
41func ExtractUserParam(db database.Store) func(http.Handler) http.Handler {
42 return func(next http.Handler) http.Handler {
43 return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
44 ctx := r.Context()
45 user, ok := ExtractUserContext(ctx, db, rw, r)
46 if !ok {
47 // response already handled
48 return
49 }
50 ctx = context.WithValue(ctx, userParamContextKey{}, user)
51 next.ServeHTTP(rw, r.WithContext(ctx))
52 })
53 }
54}
55
56// ExtractUserParamOptional does not fail if no user is present.
57func ExtractUserParamOptional(db database.Store) func(http.Handler) http.Handler {

Callers 3

TestOrganizationParamFunction · 0.92
TestUserParamFunction · 0.92
NewFunction · 0.92

Calls 4

ExtractUserContextFunction · 0.85
WithContextMethod · 0.80
ContextMethod · 0.65
ServeHTTPMethod · 0.45

Tested by 2

TestOrganizationParamFunction · 0.74
TestUserParamFunction · 0.74