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

Function ExtractNotificationTemplateParam

coderd/httpmw/notificationtemplateparam.go:24–49  ·  view source on GitHub ↗

ExtractNotificationTemplateParam grabs a notification template from the "notification_template" URL parameter.

(db database.Store)

Source from the content-addressed store, hash-verified

22
23// ExtractNotificationTemplateParam grabs a notification template from the "notification_template" URL parameter.
24func ExtractNotificationTemplateParam(db database.Store) func(http.Handler) http.Handler {
25 return func(next http.Handler) http.Handler {
26 return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
27 ctx := r.Context()
28 notifTemplateID, parsed := ParseUUIDParam(rw, r, "notification_template")
29 if !parsed {
30 return
31 }
32 nt, err := db.GetNotificationTemplateByID(r.Context(), notifTemplateID)
33 if httpapi.Is404Error(err) {
34 httpapi.ResourceNotFound(rw)
35 return
36 }
37 if err != nil {
38 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
39 Message: "Internal error fetching notification template.",
40 Detail: err.Error(),
41 })
42 return
43 }
44
45 ctx = context.WithValue(ctx, notificationTemplateParamContextKey{}, nt)
46 next.ServeHTTP(rw, r.WithContext(ctx))
47 })
48 }
49}

Callers 1

NewFunction · 0.92

Calls 9

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

Tested by

no test coverage detected