• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang rest.NotFound函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/ant0ine/go-json-rest/rest.NotFound函数的典型用法代码示例。如果您正苦于以下问题:Golang NotFound函数的具体用法?Golang NotFound怎么用?Golang NotFound使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NotFound函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: GetPacker

func (api *Api) GetPacker(w rest.ResponseWriter, r *rest.Request) {
	id := r.PathParam("id")
	packer := PackerModule{}
	has, err := api.DB.Where("id=?", id).Get(&packer)
	if err != nil {
		rest.NotFound(w, r)
		return
	}
	if !has {
		rest.NotFound(w, r)
		return
	}
	w.WriteJson(&packer)
}
开发者ID:ohlinux,项目名称:golang-snippet-cn,代码行数:14,代码来源:rest_packer.go


示例2: getDevice

func getDevice(w rest.ResponseWriter, r *rest.Request) {
	devId := r.PathParam("devid")

	r.ParseForm()
	token := r.FormValue("token")
	if token == "" {
		rest.Error(w, "Missing \"token\"", http.StatusBadRequest)
		return
	}

	if !checkAuthz(token, devId) {
		log.Warnf("Auth failed. token: %s, device_id: %s", token, devId)
		rest.Error(w, "Authorization failed", http.StatusForbidden)
		return
	}

	stats.QueryDeviceInfo()

	if serverName, err := storage.Instance.CheckDevice(devId); err == nil && serverName != "" {
		resp := cloud.ApiResponse{}
		resp.ErrNo = cloud.ERR_NOERROR
		resp.Data = devInfo{
			Id: devId,
		}
		w.WriteJson(resp)
	} else {
		rest.NotFound(w, r)
		return
	}
}
开发者ID:houcy,项目名称:push,代码行数:30,代码来源:controlapi.go


示例3: PutDocument

// PutDocument Route
// @route Put /api/documents/:id
func PutDocument(w rest.ResponseWriter, r *rest.Request) {
	email := fmt.Sprintf("%v", r.Env["REMOTE_USER"])

	id := r.PathParam("id")
	document := Document{}
	if DB.Where("email = ?", email).First(&document, id).Error != nil {
		rest.NotFound(w, r)
		return
	}

	updated := Document{}
	if err := r.DecodeJsonPayload(&updated); err != nil {
		rest.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	document.Body = updated.Body
	document.Name, document.Description = splitBody(document.Body)

	if err := DB.Save(&document).Error; err != nil {
		rest.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	w.WriteJson(&document)
}
开发者ID:ds0nt,项目名称:markdown,代码行数:27,代码来源:documents.go


示例4: PutOverlay

func (i *Impl) PutOverlay(w rest.ResponseWriter, r *rest.Request) {

	id := r.PathParam("id")
	overlay := Overlay{}
	if i.DB.First(&overlay, id).Error != nil {
		rest.NotFound(w, r)
		return
	}

	updated := Overlay{}
	if err := r.DecodeJsonPayload(&updated); err != nil {
		rest.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	// TODO create the mapping for the PUT replacements
	// this is an example of the field mapping. I need a more complex mapping to
	// handle put... for field in fields: overlay.<field> = updated.<field>
	// overlay.Description = updated.Description

	if err := i.DB.Save(&overlay).Error; err != nil {
		rest.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	w.WriteJson(&overlay)
}
开发者ID:MarkMarine,项目名称:overlayAPI,代码行数:26,代码来源:main.go


示例5: controlDevice

func controlDevice(w rest.ResponseWriter, r *rest.Request) {
	type ControlParam struct {
		Token   string `json:"token"`
		Service string `json:"service"`
		Cmd     string `json:"cmd"`
	}

	devId := r.PathParam("devid")
	body := r.Env["body"]
	if body == nil {
		rest.Error(w, "Empty body", http.StatusBadRequest)
		return
	}
	b := body.([]byte)
	param := ControlParam{}
	if err := json.Unmarshal(b, &param); err != nil {
		log.Warnf("Error decode body: %s", err.Error())
		rest.Error(w, err.Error(), http.StatusBadRequest)
		return
	}

	if !checkAuthz(param.Token, devId) {
		log.Warnf("Auth failed. token: %s, device_id: %s", param.Token, devId)
		rest.Error(w, "Authorization failed", http.StatusForbidden)
		return
	}

	stats.Cmd(param.Service)
	resp := cloud.ApiResponse{}
	result, err := rpcClient.Control(devId, param.Service, param.Cmd)
	if err != nil {
		if _, ok := err.(*mq.NoDeviceError); ok {
			stats.CmdOffline(param.Service)
			rest.NotFound(w, r)
			return
		} else if _, ok := err.(*mq.TimeoutError); ok {
			stats.CmdTimeout(param.Service)
			resp.ErrNo = cloud.ERR_CMD_TIMEOUT
			resp.ErrMsg = fmt.Sprintf("recv response timeout [%s]", devId)
		} else if _, ok := err.(*mq.InvalidServiceError); ok {
			stats.CmdInvalidService(param.Service)
			resp.ErrNo = cloud.ERR_CMD_INVALID_SERVICE
			resp.ErrMsg = fmt.Sprintf("Device [%s] has no service [%s]", devId, param.Service)
		} else if _, ok := err.(*mq.SdkError); ok {
			stats.CmdOtherError(param.Service)
			resp.ErrNo = cloud.ERR_CMD_SDK_ERROR
			resp.ErrMsg = fmt.Sprintf("Error when calling service [%s] on [%s]", param.Service, devId)
		} else {
			stats.CmdOtherError(param.Service)
			resp.ErrNo = cloud.ERR_CMD_OTHER
			resp.ErrMsg = err.Error()
		}
	} else {
		stats.CmdSuccess(param.Service)
		resp.ErrNo = cloud.ERR_NOERROR
		resp.Data = result
	}

	w.WriteJson(resp)
}
开发者ID:houcy,项目名称:push,代码行数:60,代码来源:controlapi.go


示例6: GetEntry

func (api *Api) GetEntry(w rest.ResponseWriter, r *rest.Request) {
	idParam := r.PathParam("id")
	entries := &PlaylistEntry{}

	rows, err := api.DB.Query("SELECT ROWID, " + COLNAME1 + ", " + COLNAME2 + " FROM " + TABLENAME + " WHERE ROWID = " + idParam)
	if err != nil {
		log.Fatal(err)
	}

	if rows.Next() {
		var id int
		var url string
		var played int
		if err := rows.Scan(&id, &url, &played); err != nil {
			log.Fatal(err)
		}
		entries = &PlaylistEntry{Id: id, Url: url, Played: played}
	} else {
		rest.NotFound(w, r)
		return
	}
	if err := rows.Err(); err != nil {
		log.Fatal(err)
	}

	w.WriteJson(&entries)
}
开发者ID:sohamsankaran,项目名称:go-database-drivers,代码行数:27,代码来源:sqlite-json-rest.go


示例7: GetUser

func (api *Api) GetUser(w rest.ResponseWriter, r *rest.Request) {
	id := r.PathParam("id")
	user := &User{}

	rows, err := api.DB.Query("SELECT * FROM " + TABLENAME + " WHERE ID = " + id)
	if err != nil {
		log.Fatal(err)
	}

	if rows.Next() {
		var id int
		var name string
		if err := rows.Scan(&id, &name); err != nil {
			log.Fatal(err)
		}
		user = &User{Id: id, Name: name}
	} else {
		rest.NotFound(w, r)
		return
	}
	if err := rows.Err(); err != nil {
		log.Fatal(err)
	}

	w.WriteJson(&user)
}
开发者ID:sohamsankaran,项目名称:go-database-drivers,代码行数:26,代码来源:sqlserver-json-rest.go


示例8: GetOriginator

func (api *Api) GetOriginator(w rest.ResponseWriter, r *rest.Request) {
	_, err := api.validateAuthHeader(r.Request)

	if err != nil {
		rest.Error(w, "Authorization invalid", http.StatusUnauthorized)
		return
	}

	_id := r.PathParam("id")
	id, err := strconv.ParseInt(_id, 10, 64)

	onion := db.Onion{}
	if api.First(&onion, id).Error != nil {
		rest.NotFound(w, r)
		return
	}

	contactId, err := api.fetchContact(onion.Id)
	if err != nil {
	}

	w.WriteJson(
		&GetOriginatorWrapper{
			Onion: db.EmberOnion{
				Id:        onion.Id,
				Onion:     onion.Onion,
				ContactId: contactId,
			},
		},
	)
}
开发者ID:Zwiebelring,项目名称:zwiebelnetz,代码行数:31,代码来源:onion_controller.go


示例9: DeleteCircle

func (api *Api) DeleteCircle(w rest.ResponseWriter, r *rest.Request) {
	_, err := api.validateAuthHeader(r.Request)

	if err != nil {
		rest.Error(w, "Authorization invalid", http.StatusUnauthorized)
		return
	}

	_id := r.PathParam("id")
	id, err := strconv.ParseInt(_id, 10, 64)

	circle := db.Circle{Id: id}

	if err = api.Find(&circle, circle).Error; err != nil {
		if err == gorm.RecordNotFound {
			rest.NotFound(w, r)
			return
		} else {
			log.Println(gormLoadError("circle"), err)
			rest.Error(w, INTERNALERROR, http.StatusInternalServerError)
		}
	}

	api.Model(&circle).Association("Contacts").Clear()
	api.Model(&circle).Association("Posts").Clear()
	api.Delete(&circle)

	w.WriteHeader(http.StatusOK)
}
开发者ID:Zwiebelring,项目名称:zwiebelnetz,代码行数:29,代码来源:circle_controller.go


示例10: DeletePost

func (api *Api) DeletePost(w rest.ResponseWriter, r *rest.Request) {
	_, err := api.validateAuthHeader(r.Request)
	if err != nil {
		rest.Error(w, "Authorization invalid", http.StatusUnauthorized)
		return
	}

	_id := r.PathParam("id")
	id, err := strconv.ParseInt(_id, 10, 64)

	post := db.Post{}

	if err = api.First(&post, id).Error; err != nil {
		if err == gorm.RecordNotFound {
			rest.NotFound(w, r)
			return
		} else {
			log.Println(gormLoadError("post"), err)
			rest.Error(w, INTERNALERROR, http.StatusInternalServerError)
			return
		}
	}

	if err := api.Delete(&post).Error; err != nil {
		log.Println(gormDeleteError("post"), err)
		rest.Error(w, INTERNALERROR, http.StatusInternalServerError)
		return
	}

	w.WriteHeader(http.StatusOK)
}
开发者ID:Zwiebelring,项目名称:zwiebelnetz,代码行数:31,代码来源:post_controller.go


示例11: GetQueues

// GetQueues ...
func GetQueues(w rest.ResponseWriter, r *rest.Request) {
	accountID, applicationName, _, err := queueParams(r)
	if err != nil {
		rest.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	b := GetBase(r)
	lp := parseListQuery(r)
	var queues []*models.Queue
	lr := &models.ListResult{
		List: &queues,
	}

	if err := b.GetQueues(accountID, applicationName, lp, lr); err != nil {
		rest.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	if lr.Count == 0 {
		rest.NotFound(w, r)
		return
	}
	rt := make([]*Queue, len(queues))
	for idx, queue := range queues {
		rt[idx] = NewQueueFromModel(queue)
	}
	w.WriteJson(models.ListResult{
		List:    rt,
		HasMore: lr.HasMore,
		Total:   lr.Total,
		Count:   lr.Count,
		Page:    lr.Page,
		Pages:   lr.Pages,
	})
}
开发者ID:johnnoone,项目名称:hooky,代码行数:36,代码来源:queue.go


示例12: GetAccounts

// GetAccounts ...
func GetAccounts(w rest.ResponseWriter, r *rest.Request) {
	b := GetBase(r)
	lp := parseListQuery(r)
	var accounts []*models.Account
	lr := &models.ListResult{
		List: &accounts,
	}

	if err := b.GetAccounts(lp, lr); err != nil {
		rest.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	if lr.Count == 0 {
		rest.NotFound(w, r)
		return
	}
	rt := make([]*Account, len(accounts))
	for idx, account := range accounts {
		rt[idx] = NewAccountFromModel(account)
	}
	w.WriteJson(models.ListResult{
		List:    rt,
		HasMore: lr.HasMore,
		Total:   lr.Total,
		Count:   lr.Count,
		Page:    lr.Page,
		Pages:   lr.Pages,
	})
}
开发者ID:yonglehou,项目名称:hooky,代码行数:30,代码来源:account.go


示例13: UpdateTripPlaces

//UpdateTripPlaces update trip places
func (t *Trips) UpdateTripPlaces(w rest.ResponseWriter, r *rest.Request) {
	id := r.PathParam("id")
	res, err := rethink.Table(tableName).Get(id).Run(t.Conn)
	if err != nil {
		rest.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	if res.IsNil() {
		rest.NotFound(w, r)
		return
	}
	var trip *Trip
	res.One(&trip)

	tripPlaces := []TripPlace{}
	err = r.DecodeJsonPayload(&tripPlaces)
	if err != nil {
		rest.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	trip.Updated = time.Now()
	trip.Places = tripPlaces
	trip.TotalPlaces = len(tripPlaces)

	_, err = rethink.Table(tableName).Get(id).Update(trip).RunWrite(t.Conn)
	if err != nil {
		rest.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	w.WriteJson(&trip)
}
开发者ID:yetis-br,项目名称:travelPlanning,代码行数:32,代码来源:trip.go


示例14: GetAttempts

// GetAttempts ...
func GetAttempts(w rest.ResponseWriter, r *rest.Request) {
	accountID, applicationName, taskName, err := taskParams(r)
	if err != nil {
		rest.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	b := GetBase(r)
	lp := parseListQuery(r)
	var attempts []*models.Attempt
	lr := &models.ListResult{
		List: &attempts,
	}

	if err := b.GetAttempts(accountID, applicationName, taskName, lp, lr); err != nil {
		rest.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	if lr.Count == 0 {
		rest.NotFound(w, r)
		return
	}
	rt := make([]*Attempt, len(attempts))
	for idx, attempt := range attempts {
		rt[idx] = NewAttemptFromModel(attempt)
	}
	w.WriteJson(models.ListResult{
		List:    rt,
		HasMore: lr.HasMore,
		Total:   lr.Total,
		Count:   lr.Count,
		Page:    lr.Page,
		Pages:   lr.Pages,
	})
}
开发者ID:johnnoone,项目名称:hooky,代码行数:36,代码来源:attempt.go


示例15: UpdateTask

func UpdateTask(w rest.ResponseWriter, r *rest.Request) {
	newtask := Task{}
	err := r.DecodeJsonPayload(&newtask)
	if err != nil {
		rest.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	Id, _ := strconv.ParseInt(r.PathParam("id"), 0, 64)
	oldtask := store[Id]
	if oldtask == nil {
		rest.NotFound(w, r)
		return
	}
	if newtask.Desc != "" {
		oldtask.Desc = newtask.Desc
	}
	if newtask.Due != "" {
		oldtask.Due = newtask.Due
	}
	if newtask.Completed == true || newtask.Completed == false {
		oldtask.Completed = newtask.Completed
	}
	store[Id] = oldtask
	w.WriteJson(&oldtask)
}
开发者ID:palaniap,项目名称:GO_TaskManager,代码行数:25,代码来源:ceresti.go


示例16: GetContact

func (api *Api) GetContact(w rest.ResponseWriter, r *rest.Request) {
	_, err := api.validateAuthHeader(r.Request)

	if err != nil {
		rest.Error(w, "Authorization invalid", http.StatusUnauthorized)
		return
	}

	_id := r.PathParam("id")
	id, err := strconv.ParseInt(_id, 10, 64)

	contact := db.Contact{}
	if api.First(&contact, id).Error != nil {
		rest.NotFound(w, r)
		return
	}

	emberContact := db.EmberContactResponse{}
	emberContact.Contact = contact
	emberContact.ProfilePictureId = api.GetProfilePictureId(contact.OnionId)
	api.Model(&contact).Related(&contact.Circles, "Circles")
	emberContact.EmberCircles = make([]int64, len(contact.Circles))
	for i, circ := range contact.Circles {
		emberContact.EmberCircles[i] = circ.Id
	}

	w.WriteJson(
		&GetContactWrapper{
			Contact: emberContact,
		},
	)
}
开发者ID:Zwiebelring,项目名称:zwiebelnetz,代码行数:32,代码来源:contact_controller.go


示例17: PostUser

func (api *Api) PostUser(w rest.ResponseWriter, r *rest.Request) {
	user := User{}

	err := r.DecodeJsonPayload(&user)
	if err != nil {
		rest.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	lastInsertId, err := api.DB.Query("INSERT INTO " + TABLENAME + "(" + COLNAME + ") OUTPUT Inserted.ID VALUES('" + user.Name + "')")
	if err != nil {
		fmt.Println(err)
		return
	}

	if lastInsertId.Next() {
		var id int
		if err := lastInsertId.Scan(&id); err != nil {
			log.Fatal(err)
		}
		user.Id = id
	} else {
		rest.NotFound(w, r)
		return
	}
	if err := lastInsertId.Err(); err != nil {
		log.Fatal(err)
	}

	w.WriteJson(&user)
}
开发者ID:sohamsankaran,项目名称:go-database-drivers,代码行数:31,代码来源:sqlserver-json-rest.go


示例18: GetGameInfo

func (api *ChessApi) GetGameInfo(res rest.ResponseWriter, req *rest.Request) {
	u := getUser(req)

	id := req.PathParam("id")
	intId, err := strconv.Atoi(id)
	gameId := game.Id(intId)
	if err != nil {
		log.Debug("Recieved an invalid gameid, it was not an int: %s", id)
		rest.NotFound(res, req)
		return
	}

	gameInfo, found := api.Queries.GameInformation(gameId)
	if !found {
		log.Debug("Recieved an invalid gameid, it was not an int: %s", id)
		rest.NotFound(res, req)
		return
	}

	type Response struct {
		GameInfo        queries.GameInformation `json:",inline"`
		UserColor       game.Color              `json:",omitempty"`
		UserActive      bool
		DrawOfferToUser bool
	}

	response := new(Response)
	response.GameInfo = gameInfo

	if u.Uuid == gameInfo.White.Uuid {
		response.UserColor = game.White
		response.UserActive = gameInfo.ActiveColor == game.White

		if gameInfo.OutstandingDrawOffer && gameInfo.DrawOfferer == game.Black {
			response.DrawOfferToUser = true
		}
	} else if u.Uuid == gameInfo.Black.Uuid {
		response.UserColor = game.Black
		response.UserActive = gameInfo.ActiveColor == game.Black

		if gameInfo.OutstandingDrawOffer && gameInfo.DrawOfferer == game.White {
			response.DrawOfferToUser = true
		}
	}

	res.WriteJson(response)
}
开发者ID:gnidan,项目名称:foodtastechess,代码行数:47,代码来源:api.go


示例19: GetGameValidMoves

func (api *ChessApi) GetGameValidMoves(res rest.ResponseWriter, req *rest.Request) {
	id := req.PathParam("id")
	intId, err := strconv.Atoi(id)
	gameId := game.Id(intId)
	if err != nil {
		log.Debug("Recieved an invalid gameid, it was not an int: %s", id)
		rest.NotFound(res, req)
	}

	validMoves, found := api.Queries.ValidMoves(gameId)
	if !found {
		rest.NotFound(res, req)
		return
	}

	res.WriteJson(validMoves)
}
开发者ID:gnidan,项目名称:foodtastechess,代码行数:17,代码来源:api.go


示例20: UpdateContact

// UpdateContact add new contact
func (a *Api) UpdateContact(w rest.ResponseWriter, r *rest.Request) {
	name := r.PathParam("name")
	log.Println("POST")

	// contact := Contact{}

	var contacts []Contact
	err := a.Db.Where("name", "=", name).OrderBy("name").Limit(1).Find(&contacts)
	if err != nil {
		log.Println(err)
		rest.NotFound(w, r)
		return
	}

	err = r.DecodeJsonPayload(&contacts[0])
	if err != nil {
		log.Println(err)
		rest.Error(w, "Data error", http.StatusInternalServerError)
		return
	}

	if len(contacts) == 1 {
		// Start a transaction
		tx := a.Db.Begin()
		_, err = tx.Save(&contacts[0])
		if err != nil {
			log.Println(err)
			rest.Error(w, "Failed", http.StatusInternalServerError)
			return
		}

		// Commit changes
		err = tx.Commit()
		if err != nil {
			log.Println(err)
			rest.Error(w, "Failed", http.StatusInternalServerError)
			return
		}
	} else {
		log.Println(err)
		rest.NotFound(w, r)
		return
	}

	w.WriteJson(&contacts[0])
}
开发者ID:DimShadoWWW,项目名称:capturer,代码行数:47,代码来源:contact.go



注:本文中的github.com/ant0ine/go-json-rest/rest.NotFound函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang rest.Post函数代码示例发布时间:2022-05-24
下一篇:
Golang rest.NewApi函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap