MCPcopy Index your code
hub / github.com/mpolden/echoip / cacheResizeHandler

Method cacheResizeHandler

http/http.go:298–320  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

296}
297
298func (s *Server) cacheResizeHandler(w http.ResponseWriter, r *http.Request) *appError {
299 body, err := io.ReadAll(r.Body)
300 if err != nil {
301 return badRequest(err).WithMessage(err.Error()).AsJSON()
302 }
303 capacity, err := strconv.Atoi(string(body))
304 if err != nil {
305 return badRequest(err).WithMessage(err.Error()).AsJSON()
306 }
307 if err := s.cache.Resize(capacity); err != nil {
308 return badRequest(err).WithMessage(err.Error()).AsJSON()
309 }
310 data := struct {
311 Message string `json:"message"`
312 }{fmt.Sprintf("Changed cache capacity to %d.", capacity)}
313 b, err := json.MarshalIndent(data, "", " ")
314 if err != nil {
315 return internalServerError(err).AsJSON()
316 }
317 w.Header().Set("Content-Type", jsonMediaType)
318 w.Write(b)
319 return nil
320}
321
322func (s *Server) cacheHandler(w http.ResponseWriter, r *http.Request) *appError {
323 cacheStats := s.cache.Stats()

Callers

nothing calls this directly

Calls 7

badRequestFunction · 0.85
internalServerErrorFunction · 0.85
AsJSONMethod · 0.80
WithMessageMethod · 0.80
ResizeMethod · 0.80
HeaderMethod · 0.80
SetMethod · 0.45

Tested by

no test coverage detected