本文整理汇总了Golang中github.com/martini-contrib/render.Render.Error方法的典型用法代码示例。如果您正苦于以下问题:Golang Render.Error方法的具体用法?Golang Render.Error怎么用?Golang Render.Error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/martini-contrib/render.Render
的用法示例。
在下文中一共展示了Render.Error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: SearchPage
func SearchPage(user common.User, session sessions.Session, r render.Render, req *http.Request) {
src, err := handleSearch(req.URL.Query())
if err != nil {
r.Error(400)
}
status := common.GetCodeSourceStatus(src)
id := rand.Int63()
params := req.URL.Query()
usr := params.Get("user")
repo := params.Get("repo")
session.Set(id, usr+"/"+repo)
data := struct {
common.User
Pagename string
Theme string
SourceStatus string
WS_ID int64
Source *common.CodeSource
}{user, "search", "standard", string(status), id, src}
r.HTML(200, "search", data)
}
示例2: Add
func (this *Schedules) Add(req *http.Request, authUser models.AuthUser, render render.Render) {
var schedule models.Schedule
if decode(req, render, &schedule) != nil {
return
}
schedule.Id = 0
schedule.UserId = authUser.Id
errors := models.NewErrors()
if err := schedule.Validate(this.db, errors); err != nil {
render.Error(500)
return
}
if errors.Count() > 0 {
render.JSON(400, errors)
return
}
if this.db.Save(&schedule).Error != nil {
render.Error(500)
return
}
}
示例3: CreateAdmin
func CreateAdmin(r render.Render, req *http.Request) {
if len(cache.Users) > 0 {
r.Error(404)
return
}
if req.Method == "GET" {
r.HTML(200, "user_add", map[string]interface{}{})
return
}
req.ParseForm()
values := req.Form
m := &model.User{}
m.Account = values.Get("account")
m.Password = model.Md5(values.Get("password"))
m.Info = values.Get("info")
m.Name = values.Get("name")
if !checkNull([]string{m.Account, m.Password, m.Info, m.Name}...) {
service.Logs.Error("args err")
return
}
m.Status = model.UserStatusAdmin
_, err := dao.AddUser(m)
if err != nil {
service.Logs.Error("dao.InsertUser err(%v)", err)
return
}
r.Redirect("/", 302)
return
}
示例4: 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)
}
示例5: allLists
func allLists(db *bolt.DB, params martini.Params, req *http.Request, r render.Render) {
var lists []DistributionList
err := db.View(
func(tx *bolt.Tx) error {
b := tx.Bucket([]byte(bucketDistributionLists))
return b.ForEach(func(k, v []byte) error {
var d DistributionList
err := json.Unmarshal(v, &d)
// TODO(dgryski): skip invalid keys instead of aborting on corrupt db?[
if err != nil {
return err
}
lists = append(lists, d)
return nil
})
})
if err != nil {
r.Error(http.StatusInternalServerError)
return
}
r.JSON(http.StatusOK, lists)
}
示例6: GetPaste
func GetPaste(params martini.Params, ren render.Render, r *http.Request, cf *swift.Connection, mc *memcache.Client) {
cachedPaste, err := mc.Get(params["pasteid"])
format := params["format"]
if err != nil {
log.Println(err)
}
var paste Paste
paste.PasteId = params["pasteid"]
if cachedPaste == nil {
log.Println("Asking swift for ", params["pasteid"])
cfPaste, err := cf.ObjectGetBytes("go-cfpaste", params["pasteid"])
if err != nil {
if err.Error() == "Object Not Found" {
ren.HTML(404, "404", paste)
return
} else {
log.Println(err)
ren.Error(500)
return
}
}
err = json.Unmarshal(cfPaste, &paste)
PanicIf(err)
} else {
log.Println("Cache hit for ", params["pasteid"])
err = json.Unmarshal(cachedPaste.Value, &paste)
PanicIf(err)
}
if format == "json" {
ren.JSON(200, paste)
} else {
ren.HTML(200, "paste", paste)
}
return
}
示例7: ServeHTTP
func (h BuildersHandler) ServeHTTP(r render.Render) {
if builders, err := GetBuilders(h.c); err == nil {
r.JSON(200, builders)
} else {
r.Error(500)
}
}
示例8: 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)
}
示例9: 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)
}
示例10: GetUsers
// GET /users
func GetUsers(r render.Render) {
users := []db.User{}
if db.DB.Find(&users).RecordNotFound() {
r.Error(404)
} else {
r.HTML(200, "users", users)
}
}
示例11: GetUsersEdit
// GET /users/user/:uuid/edit
func GetUsersEdit(r render.Render, params martini.Params) {
user := db.User{}
if db.DB.Where("uuid = ?", params["uuid"]).First(&user).RecordNotFound() {
r.Error(404)
} else {
r.HTML(200, "users/edit", user)
}
}
示例12: List
func List(r render.Render, params martini.Params, db *mgo.Database) {
var available []models.AvailableTopic
err := db.C(availableCollection).Find(nil).Sort("-updated_on").All(&available)
if err != nil {
r.Error(400)
}
r.HTML(200, "available/list", available)
}
示例13: Retrieve
func Retrieve(c martini.Context, params martini.Params, r render.Render) {
id, _ := strconv.Atoi(params["id"])
post, err := retrieve(id)
if err != nil {
r.Error(404)
return
}
c.Map(post)
}
示例14: MediaHead
func MediaHead(db gorm.DB, r render.Render, params martini.Params) {
media := models.Media{}
id, _ := strconv.Atoi(params["id"])
if err := db.First(&media, id).Error; err != nil {
r.Error(http.StatusNotFound)
return
}
r.Redirect(media.Url)
}
示例15: 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)
}
}