本文整理汇总了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)
}
示例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
}
}
示例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)
}
示例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)
}
示例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, ¶m); 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)
}
示例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)
}
示例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)
}
示例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,
},
},
)
}
示例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)
}
示例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)
}
示例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,
})
}
示例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,
})
}
示例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)
}
示例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,
})
}
示例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)
}