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

Function ExtractGroupParam

coderd/httpmw/groupparam.go:62–90  ·  view source on GitHub ↗

ExtraGroupParam grabs a group from the "group" URL parameter.

(db database.Store)

Source from the content-addressed store, hash-verified

60
61// ExtraGroupParam grabs a group from the "group" URL parameter.
62func ExtractGroupParam(db database.Store) func(http.Handler) http.Handler {
63 return func(next http.Handler) http.Handler {
64 return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
65 ctx := r.Context()
66
67 groupID, parsed := ParseUUIDParam(rw, r, "group")
68 if !parsed {
69 return
70 }
71
72 group, err := db.GetGroupByID(r.Context(), groupID)
73 if httpapi.Is404Error(err) {
74 httpapi.ResourceNotFound(rw)
75 return
76 }
77 if err != nil {
78 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
79 Message: "Internal error fetching group.",
80 Detail: err.Error(),
81 })
82 return
83 }
84
85 ctx = context.WithValue(ctx, groupParamContextKey{}, group)
86 chi.RouteContext(ctx).URLParams.Add("organization", group.OrganizationID.String())
87 next.ServeHTTP(rw, r.WithContext(ctx))
88 })
89 }
90}

Callers 2

TestGroupParamFunction · 0.92
NewFunction · 0.92

Calls 11

Is404ErrorFunction · 0.92
ResourceNotFoundFunction · 0.92
WriteFunction · 0.92
ParseUUIDParamFunction · 0.85
WithContextMethod · 0.80
ContextMethod · 0.65
GetGroupByIDMethod · 0.65
AddMethod · 0.65
ErrorMethod · 0.45
StringMethod · 0.45
ServeHTTPMethod · 0.45

Tested by 1

TestGroupParamFunction · 0.74