(w http.ResponseWriter, r *http.Request)
| 296 | } |
| 297 | |
| 298 | func (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 | |
| 322 | func (s *Server) cacheHandler(w http.ResponseWriter, r *http.Request) *appError { |
| 323 | cacheStats := s.cache.Stats() |
nothing calls this directly
no test coverage detected