當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Render.Status方法代碼示例

本文整理匯總了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)
}
開發者ID:KanwarGill,項目名稱:trifles,代碼行數:29,代碼來源:main.go

示例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
}
開發者ID:ninnemana,項目名稱:dynamicfab,代碼行數:26,代碼來源:banners.go

示例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)
}
開發者ID:jf,項目名稱:gwp,代碼行數:10,代碼來源:post.go

示例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)
}
開發者ID:jf,項目名稱:gwp,代碼行數:10,代碼來源:post.go

示例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)
	}
}
開發者ID:sausheong,項目名稱:goauthserv,代碼行數:10,代碼來源:routes.go

示例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))
}
開發者ID:n0bisuke,項目名稱:isucon4,代碼行數:56,代碼來源:app.go

示例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)
	}
}
開發者ID:sausheong,項目名稱:goauthserv,代碼行數:12,代碼來源:routes.go

示例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
}
開發者ID:ninnemana,項目名稱:dynamicfab,代碼行數:14,代碼來源:quote.go

示例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)
}
開發者ID:n0bisuke,項目名稱:isucon4,代碼行數:14,代碼來源:app.go

示例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)
}
開發者ID:KanwarGill,項目名稱:trifles,代碼行數:15,代碼來源:main.go

示例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)
}
開發者ID:masom,項目名稱:doorbot,代碼行數:49,代碼來源:devices.go

示例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)
}
開發者ID:BearchInc,項目名稱:trails-api,代碼行數:31,代碼來源:dropbox.go

示例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)
}
開發者ID:masom,項目名稱:doorbot,代碼行數:48,代碼來源:doors.go

示例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(&currentAccount); err != nil {
		logger.Errorf("%v", err)
		render.Status(http.StatusUnauthorized)
		return
	}

	martiniContext.Map(&currentAccount)
}
開發者ID:BearchInc,項目名稱:trails-api,代碼行數:17,代碼來源:account_provider.go

示例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
}
開發者ID:ninnemana,項目名稱:dynamicfab,代碼行數:18,代碼來源:equipment.go


注:本文中的github.com/martini-contrib/render.Render.Status方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。