func (ph *Handler) ServeAdmin(req *http.Request) interface{} { if strings.HasSuffix(req.URL.Path, "/admin/headers") { serverTime, err := time.Parse(time.RFC3339Nano, req.Form.Get("receivedat")) if err != nil { // maybe a duration dur, err := time.ParseDuration(req.Form.Get("receivedat")) if err != nil { // neither duration or time return err } serverTime = time.Now().Add(dur) } receiver := req.Form.Get("receiver") var out [10]pandora.Message sz, err := ph.Server.FetchHeaders(out[:], receiver, serverTime) if err != nil { return err } if sz == 0 { return http.StatusNoContent } final := make([]url.Values, sz) for i, _ := range final { msg := &out[i] output := make(url.Values) msg.WriteTo(output) final[i] = output } return jsonOutput{final} } else if strings.HasSuffix(req.URL.Path, "/admin/fetchBlob") { var kp pandora.KeyPrinter var key pandora.SHA1Key err := kp.ReadString(&key, req.Form.Get("mid")) if err != nil { return err } data, err := ph.Server.BlobStore.GetData(nil, &key) if err != nil { return err } return data } else if strings.HasSuffix(req.URL.Path, "/admin/reenqueue") { err := ph.Server.MessageStore.Reenqueue(time.Now()) if err != nil { return err } return "OK" } return ErrNotFound }
func (ph *Handler) Ack(req *http.Request) interface{} { var kp pandora.KeyPrinter var midK pandora.SHA1Key var lidK pandora.SHA1Key err := kp.ReadString(&midK, req.Form.Get("mid")) if err != nil { return err } err = kp.ReadString(&lidK, req.Form.Get("lid")) if err != nil { return err } status, err := strconv.ParseInt(req.Form.Get("statusCode"), 32, 10) if err != nil { return err } err = ph.Server.Ack(&midK, &lidK, pandora.AckStatus(status)) if err != nil { return err } return http.StatusOK }