MCPcopy Create free account
hub / github.com/GoMudEngine/GoMud / apiV1PatchColorPatterns

Function apiV1PatchColorPatterns

internal/web/api_v1_colorpatterns.go:54–73  ·  view source on GitHub ↗

PATCH /admin/api/v1/colorpatterns Body: {"patternName": [1,2,3], ...} - updates or creates each named pattern.

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

52// PATCH /admin/api/v1/colorpatterns
53// Body: {"patternName": [1,2,3], ...} - updates or creates each named pattern.
54func apiV1PatchColorPatterns(w http.ResponseWriter, r *http.Request) {
55 var patches map[string][]int
56 if err := json.NewDecoder(r.Body).Decode(&patches); err != nil {
57 writeAPIError(w, http.StatusBadRequest, "malformed request body: "+err.Error())
58 return
59 }
60 for name, colors := range patches {
61 for i, c := range colors {
62 if c < 0 || c > 255 {
63 writeAPIError(w, http.StatusBadRequest, fmt.Sprintf("color value at index %d of pattern %q out of range 0-255: %d", i, name, c))
64 return
65 }
66 }
67 if err := colorpatterns.SaveColorPattern(name, colors); err != nil {
68 writeAPIError(w, http.StatusInternalServerError, err.Error())
69 return
70 }
71 }
72 writeJSON(w, http.StatusOK, APIResponse[struct{}]{Success: true})
73}
74
75// DELETE /admin/api/v1/colorpatterns
76// Body: {"name": "patternName"}

Callers

nothing calls this directly

Calls 3

SaveColorPatternFunction · 0.92
writeAPIErrorFunction · 0.85
writeJSONFunction · 0.85

Tested by

no test coverage detected