本文整理汇总了Golang中github.com/martini-contrib/render.Render.Status方法的典型用法代码示例。如果您正苦于以下问题:Golang Render.Status方法的具体用法?Golang Render.Status怎么用?Golang Render.Status使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/martini-contrib/render.Render
的用法示例。
在下文中一共展示了Render.Status方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: updateList
func updateList(db *bolt.DB, params martini.Params, req *http.Request, r render.Render) {
var l DistributionList
body, _ := ioutil.ReadAll(req.Body)
req.Body.Close()
err := json.Unmarshal(body, &l)
if err != nil {
r.Error(http.StatusBadRequest)
return
}
if params["id"] != l.Id {
r.Error(http.StatusBadRequest)
return
}
// marshal back out to json to normalize our data
j, err := json.Marshal(l)
db.Update(
func(tx *bolt.Tx) error {
b := tx.Bucket([]byte(bucketDistributionLists))
return b.Put([]byte(l.Id), j)
})
r.Status(http.StatusOK)
}
示例2: Delete
func Delete(rw http.ResponseWriter, req *http.Request, r render.Render, params martini.Params) {
ctx := appengine.NewContext(req)
b := banner.Banner{}
intID, err := strconv.Atoi(params["id"])
if err == nil {
b.ID = int64(intID)
}
if err := b.Get(ctx); err != nil {
http.Error(rw, "failed to delete banner", http.StatusInternalServerError)
return
}
segs := strings.Split(b.Image, "/")
blobstore.Delete(ctx, appengine.BlobKey(segs[len(segs)-1]))
if err := b.Delete(ctx); err != nil {
http.Error(rw, "failed to delete banner", http.StatusInternalServerError)
return
}
r.Status(200)
return
}
示例3: HandleDelete
// Delete a post
// DELETE /post/1
func HandleDelete(post Post, r render.Render) {
err := post.delete()
if err != nil {
r.Error(500)
return
}
r.Status(200)
}
示例4: HandlePut
// Update a post
// PUT /post/1
func HandlePut(post Post, r render.Render) {
err := post.update()
if err != nil {
r.Error(500)
return
}
r.Status(200)
}
示例5: PostValidate
// POST /validate
func PostValidate(r render.Render, req *http.Request) {
s := req.PostFormValue("session")
session := db.Session{}
if db.DB.Where("uuid = ?", s).First(&session).RecordNotFound() {
r.Error(404)
} else {
r.Status(200)
}
}
示例6: routePostAd
func routePostAd(r render.Render, req *http.Request, params martini.Params) {
slot := params["slot"]
advrId := advertiserId(req)
if advrId == "" {
r.Status(404)
return
}
req.ParseMultipartForm(100000)
asset := req.MultipartForm.File["asset"][0]
id := nextAdId()
key := adKey(slot, id)
content_type := ""
if len(req.Form["type"]) > 0 {
content_type = req.Form["type"][0]
}
if content_type == "" && len(asset.Header["Content-Type"]) > 0 {
content_type = asset.Header["Content-Type"][0]
}
if content_type == "" {
content_type = "video/mp4"
}
title := ""
if a := req.Form["title"]; a != nil {
title = a[0]
}
destination := ""
if a := req.Form["destination"]; a != nil {
destination = a[0]
}
rd.HMSet(key,
"slot", slot,
"id", id,
"title", title,
"type", content_type,
"advertiser", advrId,
"destination", destination,
"impressions", "0",
)
f, _ := asset.Open()
defer f.Close()
buf := bytes.NewBuffer(nil)
io.Copy(buf, f)
asset_data := string(buf.Bytes())
rd.Set(assetKey(slot, id), asset_data, 0)
rd.RPush(slotKey(slot), id)
rd.SAdd(advertiserKey(advrId), key)
r.JSON(200, getAd(req, slot, id))
}
示例7: GetUsersActivate
// GET /users/:uuid/activate
func GetUsersActivate(r render.Render, params martini.Params) {
user := db.User{}
if db.DB.Where("activation_token = ?", params["uuid"]).First(&user).RecordNotFound() {
r.Error(404)
} else {
if err := user.Activate(); err != nil {
r.Error(500)
}
r.Status(200)
}
}
示例8: SetHeading
func SetHeading(rw http.ResponseWriter, req *http.Request, r render.Render, params martini.Params) {
ctx := appengine.NewContext(req)
h := quote.Heading{}
h.Heading = req.FormValue("heading")
if err := h.Save(ctx); err != nil {
http.Error(rw, "failed to save heading", http.StatusInternalServerError)
return
}
r.Status(200)
return
}
示例9: routeGetAdCount
func routeGetAdCount(r render.Render, params martini.Params) {
slot := params["slot"]
id := params["id"]
key := adKey(slot, id)
exists, _ := rd.Exists(key).Result()
if !exists {
r.JSON(404, map[string]string{"error": "not_found"})
return
}
rd.HIncrBy(key, "impressions", 1).Result()
r.Status(204)
}
示例10: removeList
func removeList(db *bolt.DB, params martini.Params, req *http.Request, r render.Render) {
id := params["id"]
err := db.Update(
func(tx *bolt.Tx) error {
b := tx.Bucket([]byte(bucketDistributionLists))
return b.Delete([]byte(id))
})
if err != nil {
r.Error(http.StatusInternalServerError)
return
}
r.Status(http.StatusOK)
}
示例11: Register
// Register creates a new device
func Register(render render.Render, r doorbot.Repositories, vm DeviceViewModel) {
repo := r.DeviceRepository()
device, err := repo.FindByToken(r.DB(), vm.Device.Token)
if err != nil {
log.WithFields(log.Fields{
"error": err,
"account_id": r.AccountScope(),
"device_token": vm.Device.Token,
"step": "device-find",
}).Error("Api::Devices->Register database error")
render.Status(http.StatusInternalServerError)
return
}
if device == nil {
render.Status(http.StatusNotFound)
return
}
device.Make = vm.Device.Make
device.DeviceID = vm.Device.DeviceID
device.IsEnabled = true
_, err = repo.Update(r.DB(), device)
if err != nil {
log.WithFields(log.Fields{
"error": err,
"account_id": r.AccountScope(),
"device_id": device.ID,
"step": "device-update",
}).Error("Api::Devices->Register database error")
render.Status(http.StatusInternalServerError)
return
}
log.WithFields(log.Fields{
"account_id": r.AccountScope(),
"device_id": device.ID,
}).Info("Api::Devices->Put device registered")
render.JSON(http.StatusOK, device)
}
示例12: RegisterDropbox
func RegisterDropbox(req *http.Request, render render.Render, registerDropboxForm RegisterDropboxForm, account *models.Account, logger *middlewares.Logger, ds *appx.Datastore) {
logger.Infof("You are in register dropbox")
authorization := &models.ExternalServiceAuthorization{
AuthorizationType: models.DropBox,
AccessToken: registerDropboxForm.AccessToken,
UserId: models.DropBox.String() + "-" + registerDropboxForm.UserId,
}
authorization.SetParentKey(account.Key())
err := ds.Load(authorization)
if err != nil {
println("I failed you becasue: %v", err.Error())
}
exists := err == nil
if err := ds.Save(authorization); err != nil {
logger.Errorf("Unable to register for dropbox %v", err)
render.JSON(http.StatusInternalServerError, "Unable to register dropbox")
return
}
if exists {
DropboxDelta(req, ds, account, authorization)
} else {
DropboxInit(req, ds, account, authorization)
}
render.Status(http.StatusOK)
}
示例13: Delete
// Delete a door
func Delete(render render.Render, r doorbot.Repositories, params martini.Params) {
id, err := strconv.ParseUint(params["id"], 10, 32)
if err != nil {
render.JSON(http.StatusBadRequest, doorbot.NewBadRequestErrorResponse([]string{"The id must be an unsigned integer"}))
return
}
repo := r.DoorRepository()
door, err := repo.Find(r.DB(), uint(id))
if err != nil {
log.WithFields(log.Fields{
"error": err,
"account_id": r.AccountScope(),
"door_id": id,
"step": "door-find",
}).Error("Api::Doors->Delete database error")
render.JSON(http.StatusInternalServerError, doorbot.NewInternalServerErrorResponse([]string{}))
return
}
if door == nil {
render.JSON(http.StatusNotFound, doorbot.NewEntityNotFoundResponse([]string{"The specified door does not exists"}))
return
}
_, err = repo.Delete(r.DB(), door)
if err != nil {
log.WithFields(log.Fields{
"error": err,
"account_id": r.AccountScope(),
"door_id": id,
"step": "door-delete",
}).Error("Api::Doors->Delete database error")
render.Status(http.StatusInternalServerError)
return
}
log.WithFields(log.Fields{
"account_id": r.AccountScope(),
"door_id": door.ID,
}).Error("Api::Doors->Post door deleted")
render.Status(http.StatusNoContent)
}
示例14: AuthorizationAccountProvider
func AuthorizationAccountProvider(c appengine.Context, logger *Logger, request *http.Request, render render.Render, martiniContext martini.Context, appx *appx.Datastore) {
authToken := extractAuthToken(request)
if authToken == "" {
render.Status(http.StatusUnauthorized)
return
}
var currentAccount models.Account
if err := appx.Query(models.Accounts.ByAuthToken(authToken)).Result(¤tAccount); err != nil {
logger.Errorf("%v", err)
render.Status(http.StatusUnauthorized)
return
}
martiniContext.Map(¤tAccount)
}
示例15: Delete
func Delete(rw http.ResponseWriter, req *http.Request, r render.Render, params martini.Params) {
ctx := appengine.NewContext(req)
e := equipment.Equipment{}
intID, err := strconv.Atoi(params["id"])
if err == nil {
e.ID = int64(intID)
}
if err := e.Delete(ctx); err != nil {
http.Error(rw, "failed to delete equipment", http.StatusInternalServerError)
return
}
r.Status(200)
return
}