MCPcopy Create free account
hub / github.com/vercel/examples / handleGetItem

Method handleGetItem

go/api/internal/handler/handler.go:70–85  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

68}
69
70func (h *Handler) handleGetItem(w http.ResponseWriter, r *http.Request) {
71 id := strings.TrimPrefix(r.URL.Path, "/api/items/")
72 if id == "" {
73 http.NotFound(w, r)
74 return
75 }
76
77 writeJSON(w, http.StatusOK, model.ItemResponse{
78 Item: model.DataItem{
79 ID: 1,
80 Name: "Sample Item " + id,
81 Value: 100,
82 },
83 Timestamp: time.Now().UTC().Format(time.RFC3339),
84 })
85}
86
87func writeJSON(w http.ResponseWriter, status int, v any) {
88 w.Header().Set("Content-Type", "application/json")

Callers

nothing calls this directly

Calls 1

writeJSONFunction · 0.85

Tested by

no test coverage detected