MCPcopy Create free account
hub / github.com/ByteStorage/FlyDB / PutHandler

Method PutHandler

protocol/http/http_server.go:19–48  ·  view source on GitHub ↗

PutHandler 支持http进行Put

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

17
18// PutHandler 支持http进行Put
19func (hs *HttpHandler) PutHandler(w http.ResponseWriter, r *http.Request) {
20 type PutRequest struct {
21 Key string `json:"key"`
22 Value string `json:"value"`
23 }
24
25 var putReq PutRequest
26 err := json.NewDecoder(r.Body).Decode(&putReq)
27 if err != nil {
28 http.Error(w, err.Error(), http.StatusBadRequest)
29 return
30 }
31 if putReq.Key == "" {
32 http.Error(w, "key is empty", http.StatusBadRequest)
33 return
34 }
35 if putReq.Value == "" {
36 http.Error(w, "value is empty", http.StatusBadRequest)
37 return
38 }
39 err = hs.Put([]byte(putReq.Key), []byte(putReq.Value))
40 if err != nil {
41 http.Error(w, err.Error(), http.StatusInternalServerError)
42 return
43 }
44 _, err = w.Write([]byte("ok"))
45 if err != nil {
46 return
47 }
48}
49
50// DelHandler 支持http进行Delete
51func (hs *HttpHandler) DelHandler(w http.ResponseWriter, r *http.Request) {

Callers

nothing calls this directly

Calls 3

PutMethod · 0.65
WriteMethod · 0.65
DecodeMethod · 0.45

Tested by

no test coverage detected