当前位置: 首页>>代码示例>>Golang>>正文


Golang rest.NotFound函数代码示例

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


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


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