MCPcopy Create free account
hub / github.com/blobcache/blobcache / handleVolume

Method handleVolume

src/bchttp/server.go:108–149  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

106}
107
108func (s *Server) handleVolume(w http.ResponseWriter, r *http.Request) {
109 switch {
110 case r.URL.Path == "/volume/":
111 handleRequest(w, r, func(ctx context.Context, req CreateVolumeReq) (*CreateVolumeResp, error) {
112 vol, err := s.Service.CreateVolume(ctx, req.Host, req.Spec)
113 if err != nil {
114 return nil, err
115 }
116 return &CreateVolumeResp{Handle: *vol}, nil
117 })
118 return
119 }
120 var volIDStr string
121 var method string
122 if _, err := fmt.Sscanf(r.URL.Path, "/volume/%34s.%s", &volIDStr, &method); err != nil {
123 http.Error(w, "could not parse path "+r.URL.Path, http.StatusBadRequest)
124 return
125 }
126 var h blobcache.Handle
127 if err := h.OID.UnmarshalText([]byte(volIDStr)); err != nil {
128 http.Error(w, "could not decode volume id", http.StatusBadRequest)
129 return
130 }
131 secretStr := r.Header.Get("X-Secret")
132 if _, err := hex.Decode(h.Secret[:], []byte(secretStr)); err != nil {
133 http.Error(w, "could not decode secret", http.StatusBadRequest)
134 return
135 }
136 switch method {
137 case "Inspect":
138 info, err := s.Service.InspectVolume(r.Context(), h)
139 if err != nil {
140 http.Error(w, err.Error(), http.StatusInternalServerError)
141 return
142 }
143 if err := json.NewEncoder(w).Encode(info); err != nil {
144 http.Error(w, err.Error(), http.StatusInternalServerError)
145 return
146 }
147 return
148 }
149}
150
151func (s *Server) handleTx(w http.ResponseWriter, r *http.Request) {
152 if r.URL.Path == "/tx/" {

Callers 1

ServeHTTPMethod · 0.95

Calls 6

handleRequestFunction · 0.85
CreateVolumeMethod · 0.65
GetMethod · 0.65
InspectVolumeMethod · 0.65
ErrorMethod · 0.45
UnmarshalTextMethod · 0.45

Tested by

no test coverage detected