本文整理匯總了Golang中web.Context.Redirect方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.Redirect方法的具體用法?Golang Context.Redirect怎麽用?Golang Context.Redirect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類web.Context
的用法示例。
在下文中一共展示了Context.Redirect方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: index
func index(ctx *web.Context, val string) string {
switch val {
case "Liberator":
ctx.Redirect(302, util.Settings.WebHome())
}
return val
}
示例2: update
func update(ctx *web.Context) {
if ctx.Params["submit"] == "Delete" {
ctx.SetCookie(web.NewCookie(cookieName, "", -1))
} else {
ctx.SetCookie(web.NewCookie(cookieName, ctx.Params["cookie"], 0))
}
ctx.Redirect(301, "/")
}
示例3: ReadPost
func (c *Index) ReadPost(ctx *web.Context, postId string) string {
p := PostModelInit()
result := p.RenderPost(postId)
viewVars := make(map[string]interface{})
viewVars["Title"] = result.Title
viewVars["Content"] = result.Content
viewVars["Date"] = time.Unix(result.Created, 0).Format(blogConfig.Get("dateFormat"))
viewVars["Id"] = objectIdHex(result.Id.String())
// To be used within the {{Comments}} blog
viewVars["PostId"] = objectIdHex(result.Id.String())
if result.Status == 0 {
sessionH := session.Start(ctx, h)
defer sessionH.Save()
if sessionH.Data["logged"] == nil {
ctx.Redirect(302, "/")
return ""
}
}
if blogConfig.Get("enableComment") != "" {
viewVars["EnableComment"] = true
} else {
viewVars["EnableComment"] = false
}
// Render comments
comments := make([]map[string]string, 0)
for i, v := range result.Comments {
comments = append(comments, map[string]string{
"Number": strconv.Itoa(i + 1),
"Date": time.Unix(v.Created, 0).Format(blogConfig.Get("dateFormat")),
"Id": v.Id[0:9],
"RealId": v.Id,
"Content": v.Content,
"Author": v.Author})
}
viewVars["Comments"] = comments
if next, exists := p.GetNextId(objectIdHex(result.Id.String())); exists {
viewVars["Next"] = next
}
if last, exists := p.GetLastId(objectIdHex(result.Id.String())); exists {
viewVars["Last"] = last
}
sessionH := session.Start(ctx, h)
defer sessionH.Save()
viewVars["Admin"] = false
if sessionH.Data["logged"] != nil {
viewVars["Admin"] = true
}
output := mustache.RenderFile("templates/view-post.mustache", viewVars)
return render(output, result.Title)
}
示例4: create_person
func create_person(ctx *web.Context) {
var p Personne
Personnes := gouda.M(p)
p.Id = 0
p.Nom = ctx.Request.Params["nom"][0]
p.Age, _ = strconv.Atoi(ctx.Request.Params["age"][0])
Personnes.Save(p)
ctx.Redirect(302, "/")
}
示例5: redirect
/*redirects the shortened URL to the real URL*/
func redirect(ctx *web.Context, key string) {
/*fetch our URL*/
url, _ := redisClient.Get(getRedisKey(key))
if url == nil {
printError(ctx, "I can't find that URL")
} else {
/*redirect*/
ctx.Redirect(301, string(url))
}
}
示例6: newPostGet
func newPostGet(ctx *web.Context) string {
sessionH := session.Start(ctx, h)
defer sessionH.Save()
if sessionH.Data["logged"] == nil {
ctx.Redirect(302, "/admin/login")
return ""
}
output := mustache.RenderFile("templates/new-post.mustache")
return render(output, "New Post")
}
示例7: update_person
func update_person(ctx *web.Context) {
var p Personne
Personnes := gouda.M(p)
i, _ := strconv.Atoi(ctx.Request.Params["id"][0])
p = Personnes.Where(gouda.F("id").Eq(i)).First().(Personne)
p.Nom = ctx.Request.Params["nom"][0]
p.Age, _ = strconv.Atoi(ctx.Request.Params["age"][0])
Personnes.Save(p)
ctx.Redirect(302, "/person/"+fmt.Sprint(p.Id))
}
示例8: adminLoginGet
func adminLoginGet(ctx *web.Context) string {
sessionH := session.Start(ctx, h)
defer sessionH.Save()
if sessionH.Data["logged"] != nil {
ctx.Redirect(302, "/admin/post/list")
return ""
}
output := mustache.RenderFile("templates/admin-login.mustache")
return render(output, "Login")
}
示例9: adminIndexGet
func adminIndexGet(ctx *web.Context) string {
sessionH := session.Start(ctx, h)
defer sessionH.Save()
if sessionH.Data["logged"] != nil {
ctx.Redirect(302, "/admin/post/list")
return ""
}
ctx.Redirect(302, "/admin/login")
return ""
}
示例10: index
// renders /
func index(ctx *web.Context) string {
css, ok := ctx.Params["css"]
if ok {
SetCSS(ctx, css)
ctx.Redirect(302, "/")
return "ok"
}
//posts := postsForMonth(time.LocalTime()) //Db.GetLastNPosts(10)
// posts := lastPosts(0xff)
posts := postsForLastNDays(4)
if len(posts) <= 0 {
posts = lastPosts(23)
}
//fmt.Printf("posts: %#v\n", posts)
//embedded struct - our mustache templates need a NumOfComments field to render
//but we don't want to put that field into the BlogPost Struct so it won't get stored
//into the DB
type MyPost struct {
BlogPost
NumOfComments int
}
//posts ordered by date. this is ugly. TODO: look up if mustache hase something to handle this situation
type Date struct {
Date string
Posts []MyPost
}
Db := DBGet()
defer Db.Close()
//loop through our posts and put them into the appropriate date structure
dates := []Date{}
var cur_date time.Time
var date *Date
for _, p := range posts {
post_date := time.SecondsToLocalTime(p.Timestamp)
if !(cur_date.Day == post_date.Day && cur_date.Month == post_date.Month && cur_date.Year == post_date.Year) {
cur_date = *post_date
dates = append(dates, Date{Date: cur_date.Format("Mon Jan _2 2006")})
date = &dates[len(dates)-1]
}
p.Comments, _ = Db.GetComments(p.Id)
mp := MyPost{p, len(p.Comments)}
date.Posts = append(date.Posts, mp)
}
m := map[string]interface{}{
"Dates": dates,
}
tmpl, _ := mustache.ParseFile("templ/index.mustache")
s := tmpl.Render(&m, getCSS(ctx))
return s
}
示例11: resolve
// function to resolve a shorturl and redirect
func resolve(ctx *web.Context, short string) {
kurl, err := load(short)
if err == nil {
go redis.Hincrby(kurl.Key, "Clicks", 1)
ctx.Redirect(http.StatusMovedPermanently,
kurl.LongUrl)
} else {
ctx.Redirect(http.StatusMovedPermanently,
ROLL)
}
}
示例12: newPostPost
func newPostPost(ctx *web.Context) {
sessionH := session.Start(ctx, h)
defer sessionH.Save()
if sessionH.Data["logged"] == nil {
ctx.Redirect(302, "/admin/login")
return
}
p := PostModelInit()
p.Create(ctx.Params["title"], ctx.Params["content"])
ctx.Redirect(302, "/admin/post/list")
}
示例13: adminDelPage
func adminDelPage(ctx *web.Context, id string) {
sessionH := session.Start(ctx, h)
defer sessionH.Save()
if sessionH.Data["logged"] == nil {
ctx.Redirect(302, "/admin/login")
return
}
p := PageModelInit()
p.Delete(id)
ctx.Redirect(302, "/admin/page/list")
}
示例14: adminEditPagePost
func adminEditPagePost(ctx *web.Context, id string) {
sessionH := session.Start(ctx, h)
defer sessionH.Save()
if sessionH.Data["logged"] == nil {
ctx.Redirect(302, "/admin/login")
return
}
p := PageModelInit()
p.Update(ctx.Params["title"], ctx.Params["content"], id)
ctx.Redirect(302, "/admin/page/list")
}
示例15: delPost
func delPost(ctx *web.Context, postId string) {
sessionH := session.Start(ctx, h)
defer sessionH.Save()
if sessionH.Data["logged"] == nil {
ctx.Redirect(302, "/admin/login")
return
}
p := PostModelInit()
p.Delete(postId)
ctx.Redirect(302, "/admin/post/list")
}