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


Golang Context.Redirect方法代码示例

本文整理汇总了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
}
开发者ID:gtalent,项目名称:LiberatorAdventures,代码行数:7,代码来源:web.go

示例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, "/")
}
开发者ID:rcoh,项目名称:modata,代码行数:8,代码来源:cookie.go

示例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)
}
开发者ID:JessonChan,项目名称:bloody.go,代码行数:57,代码来源:index.go

示例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, "/")
}
开发者ID:zetaben,项目名称:gouda,代码行数:9,代码来源:sample_web_app.go

示例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))
	}
}
开发者ID:hernan43,项目名称:gourl,代码行数:11,代码来源:gourl.go

示例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")
}
开发者ID:Quasimo,项目名称:bloody.go,代码行数:10,代码来源:admin.go

示例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))
}
开发者ID:zetaben,项目名称:gouda,代码行数:10,代码来源:sample_web_app.go

示例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")
}
开发者ID:Quasimo,项目名称:bloody.go,代码行数:10,代码来源:admin.go

示例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 ""
}
开发者ID:Quasimo,项目名称:bloody.go,代码行数:10,代码来源:admin.go

示例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
}
开发者ID:kybernetyk,项目名称:fettemama,代码行数:55,代码来源:index.go

示例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)
	}
}
开发者ID:vormplus,项目名称:kurz.go,代码行数:12,代码来源:kurz.go

示例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")
}
开发者ID:Quasimo,项目名称:bloody.go,代码行数:11,代码来源:admin.go

示例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")
}
开发者ID:Quasimo,项目名称:bloody.go,代码行数:12,代码来源:admin.go

示例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")
}
开发者ID:Quasimo,项目名称:bloody.go,代码行数:12,代码来源:admin.go

示例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")
}
开发者ID:Quasimo,项目名称:bloody.go,代码行数:12,代码来源:admin.go


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