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

Method handleQueue

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

Source from the content-addressed store, hash-verified

326}
327
328func (s *Server) handleQueue(w http.ResponseWriter, r *http.Request) {
329 switch {
330 case r.URL.Path == "/queue/":
331 handleRequest(w, r, func(ctx context.Context, req CreateQueueReq) (*CreateQueueResp, error) {
332 qh, err := s.Service.CreateQueue(ctx, req.Host, req.Spec)
333 if err != nil {
334 return nil, err
335 }
336 return &CreateQueueResp{Handle: *qh}, nil
337 })
338 return
339 }
340 var queueIDStr string
341 var method string
342 if _, err := fmt.Sscanf(r.URL.Path, "/queue/%34s.%s", &queueIDStr, &method); err != nil {
343 http.Error(w, "could not parse path "+r.URL.Path, http.StatusBadRequest)
344 return
345 }
346 var h blobcache.Handle
347 if err := h.OID.UnmarshalText([]byte(queueIDStr)); err != nil {
348 http.Error(w, "could not decode queue id", http.StatusBadRequest)
349 return
350 }
351 secretStr := r.Header.Get("X-Secret")
352 if _, err := hex.Decode(h.Secret[:], []byte(secretStr)); err != nil {
353 http.Error(w, "could not decode secret", http.StatusBadRequest)
354 return
355 }
356 switch method {
357 case "Inspect":
358 handleRequest(w, r, func(ctx context.Context, req InspectQueueReq) (*InspectQueueResp, error) {
359 info, err := s.Service.InspectQueue(ctx, h)
360 if err != nil {
361 return nil, err
362 }
363 return &InspectQueueResp{Info: info}, nil
364 })
365 case "Dequeue":
366 handleRequest(w, r, func(ctx context.Context, req NextReq) (*NextResp, error) {
367 if req.Max < 0 {
368 return nil, fmt.Errorf("max cannot be negative")
369 }
370 buf := make([]blobcache.Message, req.Max)
371 n, err := s.Service.Dequeue(ctx, h, buf, req.Opts)
372 if err != nil {
373 return nil, err
374 }
375 return &NextResp{Messages: buf[:n]}, nil
376 })
377 case "Enqueue":
378 handleRequest(w, r, func(ctx context.Context, req InsertReq) (*blobcache.InsertResp, error) {
379 resp, err := s.Service.Enqueue(ctx, h, req.Messages)
380 if err != nil {
381 return nil, err
382 }
383 return resp, nil
384 })
385 case "SubToVolume":

Callers 1

ServeHTTPMethod · 0.95

Calls 9

handleRequestFunction · 0.85
CreateQueueMethod · 0.65
GetMethod · 0.65
InspectQueueMethod · 0.65
DequeueMethod · 0.65
EnqueueMethod · 0.65
SubToVolumeMethod · 0.65
ErrorMethod · 0.45
UnmarshalTextMethod · 0.45

Tested by

no test coverage detected