MCPcopy Create free account
hub / github.com/cloud-native-go/examples / keyValueGetHandler

Function keyValueGetHandler

ch05/ch05_07/service.go:66–83  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

64}
65
66func keyValueGetHandler(w http.ResponseWriter, r *http.Request) {
67 vars := mux.Vars(r)
68 key := vars["key"]
69
70 value, err := Get(key)
71 if errors.Is(err, ErrorNoSuchKey) {
72 http.Error(w, err.Error(), http.StatusNotFound)
73 return
74 }
75 if err != nil {
76 http.Error(w, err.Error(), http.StatusInternalServerError)
77 return
78 }
79
80 w.Write([]byte(value))
81
82 log.Printf("GET key=%s\n", key)
83}
84
85func keyValueDeleteHandler(w http.ResponseWriter, r *http.Request) {
86 vars := mux.Vars(r)

Callers

nothing calls this directly

Calls 1

GetFunction · 0.70

Tested by

no test coverage detected