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

Function apiV1PutPetScript

internal/web/api_v1_pets.go:126–150  ·  view source on GitHub ↗

PUT /admin/api/v1/pets/{petname}/script

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

Source from the content-addressed store, hash-verified

124
125// PUT /admin/api/v1/pets/{petname}/script
126func apiV1PutPetScript(w http.ResponseWriter, r *http.Request) {
127 petName := strings.ToLower(strings.TrimSpace(r.PathValue("petname")))
128 if petName == "" {
129 writeAPIError(w, http.StatusBadRequest, "petname is required")
130 return
131 }
132
133 var body struct {
134 Script string `json:"script"`
135 }
136 if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
137 writeAPIError(w, http.StatusBadRequest, "malformed request body: "+err.Error())
138 return
139 }
140
141 if err := pets.SavePetScript(petName, body.Script); err != nil {
142 writeAPIError(w, http.StatusInternalServerError, err.Error())
143 return
144 }
145
146 // Invalidate the cached VM so the next invocation picks up the new script
147 scripting.InvalidatePetVM(petName)
148
149 writeJSON(w, http.StatusOK, APIResponse[struct{}]{Success: true})
150}

Callers

nothing calls this directly

Calls 4

SavePetScriptFunction · 0.92
InvalidatePetVMFunction · 0.92
writeAPIErrorFunction · 0.85
writeJSONFunction · 0.85

Tested by

no test coverage detected