...
1 package server
2
3 import (
4 "fmt"
5 "golang.conradwood.net/go-easyops/cache"
6 "net/http"
7 "strings"
8 )
9
10 func clearCacheHandler(w http.ResponseWriter, req *http.Request) {
11 cacheName := strings.TrimPrefix(req.URL.Path, "/internal/clearcache")
12 cacheName = strings.TrimPrefix(cacheName, "/")
13 caches, err := cache.Clear(cacheName)
14 if err != nil {
15 s := fmt.Sprintf("Cache \"%s\" could not be cleared: %s\n", cacheName, err)
16 w.Write([]byte(s))
17 return
18 }
19 w.Write([]byte("<html><body>"))
20 for _, c := range caches {
21 s := fmt.Sprintf("Cleared Cache \"%s\"</br>\n", c.Name())
22 w.Write([]byte(s))
23 }
24 w.Write([]byte("</body></html>"))
25 }
26
View as plain text