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

Function ExtractChatParam

coderd/httpmw/chatparam.go:24–50  ·  view source on GitHub ↗

ExtractChatParam grabs a chat from the "chat" URL parameter.

(db database.Store)

Source from the content-addressed store, hash-verified

22
23// ExtractChatParam grabs a chat from the "chat" URL parameter.
24func ExtractChatParam(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 chatID, parsed := ParseUUIDParam(rw, r, "chat")
29 if !parsed {
30 return
31 }
32
33 chat, err := db.GetChatByID(ctx, chatID)
34 if httpapi.Is404Error(err) {
35 httpapi.ResourceNotFound(rw)
36 return
37 }
38 if err != nil {
39 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
40 Message: "Internal error fetching chat.",
41 Detail: err.Error(),
42 })
43 return
44 }
45
46 ctx = context.WithValue(ctx, chatParamContextKey{}, chat)
47 next.ServeHTTP(rw, r.WithContext(ctx))
48 })
49 }
50}

Callers 3

TestWatchChatGitFunction · 0.92
TestChatParamFunction · 0.92

Calls 9

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

Tested by 3

TestWatchChatGitFunction · 0.74
TestChatParamFunction · 0.74