forked from puppetlabs-toy-chest/wash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcache.go
40 lines (35 loc) · 919 Bytes
/
cache.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package api
import (
"encoding/json"
"fmt"
"net/http"
"github.com/puppetlabs/wash/activity"
"github.com/puppetlabs/wash/plugin"
)
// swagger:route DELETE /cache cache cacheDelete
//
// Remove items from the cache
//
// Removes the specified entry and its children from the cache.
//
// Produces:
// - application/json
//
// Schemes: http
//
// Responses:
// 200:
// 500: errorResp
var cacheHandler = handler{fn: func(w http.ResponseWriter, r *http.Request) *errorResponse {
path, errResp := getWashPathFromRequest(r)
if errResp != nil {
return errResp
}
deleted := plugin.ClearCacheFor(path, true)
activity.Record(r.Context(), "API: Cache DELETE %v %+v", path, deleted)
jsonEncoder := json.NewEncoder(w)
if err := jsonEncoder.Encode(deleted); err != nil {
return unknownErrorResponse(fmt.Errorf("Could not marshal deleted keys for %v: %v", path, err))
}
return nil
}}