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

Function ExtractGroupByNameParam

coderd/httpmw/groupparam.go:25–59  ·  view source on GitHub ↗
(db database.Store)

Source from the content-addressed store, hash-verified

23}
24
25func ExtractGroupByNameParam(db database.Store) func(http.Handler) http.Handler {
26 return func(next http.Handler) http.Handler {
27 return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
28 var (
29 ctx = r.Context()
30 org = OrganizationParam(r)
31 )
32
33 name := chi.URLParam(r, "groupName")
34 if name == "" {
35 httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
36 Message: "Missing group name in URL",
37 })
38 return
39 }
40
41 group, err := db.GetGroupByOrgAndName(ctx, database.GetGroupByOrgAndNameParams{
42 OrganizationID: org.ID,
43 Name: name,
44 })
45 if httpapi.Is404Error(err) {
46 httpapi.ResourceNotFound(rw)
47 return
48 }
49 if err != nil {
50 httpapi.InternalServerError(rw, err)
51 return
52 }
53
54 ctx = context.WithValue(ctx, groupParamContextKey{}, group)
55 chi.RouteContext(ctx).URLParams.Add("organization", group.OrganizationID.String())
56 next.ServeHTTP(rw, r.WithContext(ctx))
57 })
58 }
59}
60
61// ExtraGroupParam grabs a group from the "group" URL parameter.
62func ExtractGroupParam(db database.Store) func(http.Handler) http.Handler {

Callers 1

NewFunction · 0.92

Calls 11

WriteFunction · 0.92
Is404ErrorFunction · 0.92
ResourceNotFoundFunction · 0.92
InternalServerErrorFunction · 0.92
OrganizationParamFunction · 0.85
WithContextMethod · 0.80
ContextMethod · 0.65
GetGroupByOrgAndNameMethod · 0.65
AddMethod · 0.65
StringMethod · 0.45
ServeHTTPMethod · 0.45

Tested by

no test coverage detected