本文整理匯總了Golang中github.com/codegangsta/martini-contrib/render.Render類的典型用法代碼示例。如果您正苦於以下問題:Golang Render類的具體用法?Golang Render怎麽用?Golang Render使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Render類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: HandleIndex
func HandleIndex(r render.Render) {
tip := models.Tips{}
db := GetDBInstance()
total, err := db.C("tips").Count()
if err != nil || total == 0 {
r.HTML(200, "500", nil)
return
}
index := getRandomIndex(total)
if index == total {
index = total - 1
}
db.C("tips").Find(nil).Skip(index).One(&tip)
if db.Session != nil {
defer db.Session.Close()
}
r.HTML(200, "index", map[string]interface{}{
"Comment": tip.Comment,
"Content": tip.Content,
"Id": tip.Id.Hex(),
"IsIndex": true})
}
示例2: popularLinks
func popularLinks(r render.Render) {
links, err := store.Popular()
if err != nil {
log.WithField("package", "web").Error(err)
r.JSON(500, map[string]string{
"error": err.Error(),
})
return
}
var formattedLinks []map[string]interface{}
for _, link := range links {
formattedLinks = append(formattedLinks, map[string]interface{}{
"id": link.ID(),
"title": link.Title,
"url": link.URL,
"score": link.Score,
})
}
r.JSON(200, formattedLinks)
}
示例3: HandleCreateIRLMoji
func HandleCreateIRLMoji(r render.Render, bindErr binding.Errors, im models.IRLMoji, db *models.DB, backchannel Backchannel) {
if bindErr.Count() > 0 {
r.JSON(400, JsonErrBinding(bindErr))
return
}
if backchannel.UserId() == "" {
r.JSON(403, JsonErr("The provided credentials were invalid."))
return
}
user, err := db.GetUserWithId(backchannel.UserId())
if err != nil {
r.JSON(403, "Could not find a user with your credentials.")
return
}
// Now let's create that user, shall we?
insertedIM, err := db.InsertIM(user.Id, im.Emoji, im.Picture)
if err != nil {
log.Println("Error creating user:", err.Error())
r.JSON(500, JsonErr("Sorry, an internal server error has occurred."))
return
}
r.JSON(200, map[string]*models.IRLMoji{"irlmoji": insertedIM})
}
示例4: ArticlesIndex
func ArticlesIndex(r render.Render) {
hal := HAL{}
hal.Links = map[string]Link{
"self": Link{"/articles", false},
"show": Link{"/articles/{id}", true},
}
//result := []Todo{}
//
//rows, err := rethink.Table("todos").Run(session)
//if err != nil {
// log.Println(err)
//}
//
//for rows.Next() {
// var t Todo
// err := rows.Scan(&t)
// if err != nil {
// log.Println(err)
// }
// result = append(result, t)
//}
//r.JSON(200, result)
//r.JSON(200, "hello")
r.JSON(200, hal)
}
示例5: AddComment
// Called on a POST to /events/:id/comments
// Assuming valid comment; Adds the comment under the given id
func AddComment(db *mgo.Database, r render.Render, comment models.Comment, p martini.Params) {
var eventId bson.ObjectId
// Create a unique id
comment.Id = bson.NewObjectId()
if bson.IsObjectIdHex(p["event_id"]) {
eventId = bson.ObjectIdHex(p["event_id"])
} else {
r.JSON(400, "Bad Request: Invalid Event ID")
return
}
comment.EventId = eventId
// TODO Should be the user Id
comment.CreatedBy = bson.NewObjectId()
comment.CreatedAt = time.Now().UTC()
err := db.C("comments").Insert(comment)
if err != nil {
panic(err)
}
r.JSON(201, comment)
}
示例6: HandleRandomJsonTip
func HandleRandomJsonTip(r render.Render) {
db := GetDBInstance()
tip := models.Tips{}
api := models.API{}
total, _ := db.C("tips").Count()
index := getRandomIndex(total)
db.C("tips").Find(nil).Skip(index).One(&tip)
err := db.C("apis").Find(bson.M{"type": "json"}).One(&api)
api.Count++
if err != nil {
db.C("apis").Insert(&models.API{Id: bson.NewObjectId(), Type: "json", Count: 0})
} else {
db.C("apis").Update(bson.M{"type": "json"}, bson.M{"type": "json", "count": api.Count})
}
data, err := json.Marshal(api)
if err == nil {
sendAll(data)
}
if db.Session != nil {
defer db.Session.Close()
}
r.JSON(200, tip)
}
示例7: SearchAnswersNew
func SearchAnswersNew(r render.Render, db *mgo.Database, req *http.Request, session sessions.Session) {
lastGameIdSearched := session.Get("last_game_id_searched")
templateData := map[string]interface{}{"metatitle": "Battle Answers", "currentPath": req.URL.Path,
"lastGameIdSearched": lastGameIdSearched, "games": models.GetGameRecs(db, nil)}
r.HTML(200, "search_answers/new", templateData)
}
示例8: handleTemplate
func handleTemplate(r render.Render, req *http.Request, t Template, s ServerList) {
tmpl_data := make(map[string]interface{})
tmpl_data["title"] = t.Title
tmpl_data["server"] = getServerInfo(req, s)
r.HTML(200, t.Tmpl, tmpl_data)
}
示例9: EventListHandler
func EventListHandler(r render.Render) {
search := bson.M{"data.start_time": bson.M{"$gte": time.Now()}}
sort := "data.start_time"
var results []Event
err := db.Find(&Event{}, search).Sort(sort).All(&results)
if err != nil && err != mgo.ErrNotFound {
panic(err)
}
if err == mgo.ErrNotFound {
fmt.Println("No such object in db. Redirect")
//http.Redirect(w, r, "/404/", http.StatusFound)
return
}
type templateData struct {
Context *conf.Context
Events []Event
}
data := templateData{conf.DefaultContext(conf.Config), results}
r.HTML(200, "event_list", data)
}
示例10: getDrop
func getDrop(params martini.Params, db *database.Database, r render.Render) {
d, err := db.GetDrop(params["url"])
if err != nil {
r.JSON(500, map[string]interface{}{"error": err.Error()})
} else {
r.JSON(200, map[string]interface{}{"drop": d})
}
}
示例11: GetPost
func GetPost(params martini.Params, r render.Render) {
hd := services.GetDb()
var results []models.Posts
hd.Where("id", "=", params["id"]).Limit(1).Find(&results)
r.JSON(200, results)
}
示例12: ProjectGet
func ProjectGet(db gorm.DB, r render.Render, params martini.Params) {
var project models.Project
if err := db.First(&project, params["id"]).Error; err != nil {
r.JSON(http.StatusNotFound, map[string]interface{}{"error": "Project not found"})
return
}
r.JSON(http.StatusOK, project)
}
示例13: ListPosts
func ListPosts(params martini.Params, r render.Render) {
hd := services.GetDb()
var results []models.Posts
hd.Find(&results)
r.JSON(200, results)
}
示例14: removeHero
func removeHero(db HeroDB, parms martini.Params, r render.Render) {
u := (db).(*heroDB)
id, _ := strconv.Atoi(parms["id"])
delete(u.heros, id)
r.JSON(http.StatusOK, nil)
}
示例15: validateSession
func validateSession(r render.Render, s sessions.Session) {
isLogin := s.Get("IsLogin")
if isLogin == nil {
fmt.Println("Not login...")
r.Redirect("/admin/login")
}
}