func newDirCaptchas() dirCaptchas { r := dirCaptchas{} r.methods = map[string]func(he.Request) he.Response{ "POST": func(req he.Request) he.Response { db := req.Things["db"].(*periwinkle.Tx) return rfc7231.StatusCreated(r, backend.NewCaptcha(db).ID, req) }, } return r }
func (o *captcha) Methods() map[string]func(he.Request) he.Response { return map[string]func(he.Request) he.Response{ "GET": func(req he.Request) he.Response { return rfc7231.StatusOK(o) }, "POST": func(req he.Request) he.Response { db := req.Things["db"].(*periwinkle.Tx) type postfmt struct { Value string `json:"value"` Expiration time.Time `json:"password"` } var entity postfmt httperr := safeDecodeJSON(req.Entity, &entity) if httperr != nil { return *httperr } o := (*captcha)(backend.NewCaptcha(db)) if o == nil { return rfc7231.StatusForbidden(he.NetPrintf("Captcha generation failed")) } else { ret := rfc7231.StatusOK(o) return ret } }, "PUT": func(req he.Request) he.Response { db := req.Things["db"].(*periwinkle.Tx) var newCaptcha captcha httperr := safeDecodeJSON(req.Entity, &newCaptcha) if httperr != nil { return *httperr } *o = newCaptcha o.backend().Save(db) return rfc7231.StatusOK(o) }, /* "PATCH": func(req he.Request) he.Response { panic("TODO: API: (*captcha).Methods()[\"PATCH\"]") }, */ } }