MCPcopy Create free account
hub / github.com/driangle/taskmd / projectMiddleware

Function projectMiddleware

apps/cli/internal/web/project_resolver.go:83–105  ·  view source on GitHub ↗

projectMiddleware resolves ?project= and injects the DataProvider into request context.

(resolver *ProjectResolver, next http.Handler)

Source from the content-addressed store, hash-verified

81
82// projectMiddleware resolves ?project=<id> and injects the DataProvider into request context.
83func projectMiddleware(resolver *ProjectResolver, next http.Handler) http.Handler {
84 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
85 projectID := r.URL.Query().Get("project")
86 if projectID == "" || resolver == nil {
87 next.ServeHTTP(w, r)
88 return
89 }
90
91 pctx, err := resolver.get(projectID)
92 if err != nil {
93 status := http.StatusInternalServerError
94 if errors.Is(err, ErrProjectNotFound) {
95 status = http.StatusNotFound
96 }
97 writeError(w, status, fmt.Sprintf("project %q: %s", projectID, err.Error()), nil)
98 return
99 }
100
101 ctx := context.WithValue(r.Context(), projectDPKey, pctx.dp)
102 ctx = context.WithValue(ctx, projectPhasesKey, pctx.phases)
103 next.ServeHTTP(w, r.WithContext(ctx))
104 })
105}
106
107// effectiveDP returns the project-scoped DataProvider from request context,
108// falling back to the default.

Callers 2

StartMethod · 0.85
setupProjectMiddlewareFunction · 0.85

Calls 4

writeErrorFunction · 0.85
ServeHTTPMethod · 0.80
getMethod · 0.80
ErrorMethod · 0.80

Tested by 1

setupProjectMiddlewareFunction · 0.68