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


Golang Context.Redirect方法代码示例

本文整理汇总了Golang中github.com/hoisie/web.Context.Redirect方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Redirect方法的具体用法?Golang Context.Redirect怎么用?Golang Context.Redirect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/hoisie/web.Context的用法示例。


在下文中一共展示了Context.Redirect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Remove

func Remove(ctx *web.Context, val string) string {
	id, err := strconv.Atoi(val)
	if err != nil {
		return "Invalid or malformed id"
	}

	db := util.GetDb()

	_, submit_exists := ctx.Params["doit"]
	if submit_exists {
		db.Exec("DELETE FROM entries WHERE id=$1", id)
		ctx.Redirect(302, "/manage/existing")
		return "Redirect"
	}

	// Get the post
	row := db.QueryRow("SELECT title FROM entries WHERE id=$1", id)
	entry := new(util.Entry)
	row.Scan(&entry.Title)

	send := map[string]interface{}{
		"Title": entry.Title,
	}

	return util.RenderTemplate("remove.mustache", send)
}
开发者ID:stevenleeg,项目名称:goblog,代码行数:26,代码来源:remove.go

示例2: logout

func logout(ctx *web.Context) string {
	session, _ := CookieStore.Get(ctx.Request, "monet-session")
	session.Values["authenticated"] = false
	session.Save(ctx.Request, ctx.ResponseWriter)
	ctx.Redirect(302, "/admin/login/")
	return ""
}
开发者ID:elimisteve,项目名称:monet,代码行数:7,代码来源:admin.go

示例3: serveLinkWithExtras

/*
	serve a link with extras (a path relative to the short-link and/or GET parameters)
	Parameters:
		ctx:	the context of the http request
		hash:	the short-hash of the link
		extras:	the extra path component
*/
func serveLinkWithExtras(ctx *web.Context, hash string, extras string) {
	//make the hash all uppercase
	upperHash := strings.ToUpper(hash)

	//Check to see if a link exists for the given hash
	link, numReports, exists, err := db_linkForHash(upperHash)
	if err != nil {
		//There was an error in the database
		internalError(ctx, errors.New("Database Error: "+err.Error()))
	} else if exists {
		//Check to see if the link has been flagged for review
		if numReports >= NUM_REPORTS_TO_FLAG {

			redir := link

			//If there were any path extras passed to us, append them to the redir link
			if extras != "" {
				redir += "/" + extras
			}

			//If there are any GET parameters being passed to us, append them to the redir link
			if len(ctx.Params) > 0 {
				params := "?"
				for k, v := range ctx.Params {
					params += k + "=" + v + "&"
				}
				//remove the trailing ampersand and append to the redir link
				redir += strings.TrimSuffix(params, "&")
			}

			flaggedLink(ctx, hash, redir)
			return

		} else {
			//The hash=>link exists
			redir := link

			//If there were any path extras passed to us, append them to the redir link
			if extras != "" {
				redir += "/" + extras
			}

			//If there are any GET parameters being passed to us, append them to the redir link
			if len(ctx.Params) > 0 {
				params := "?"
				for k, v := range ctx.Params {
					params += k + "=" + v + "&"
				}
				//remove the trailing ampersand and append to the redir link
				redir += strings.TrimSuffix(params, "&")
			}

			//if the hash exists in the link table, issue a '302 Found' to the client with the link URL
			ctx.Redirect(302, redir)
		}
	} else {
		//No link exists for the hash, so serve a '404 Not Found' error page
		error404(ctx, hash)
	}
}
开发者ID:JGets,项目名称:reduse,代码行数:67,代码来源:pageFunc.go

示例4: Publish

func (c *Controller) Publish(ctx *web.Context) {
	if !c.sessionManager.LoggedIn(ctx) {
		ctx.Redirect(303, "/login")
		return
	}
	ctx.WriteString(c.Page("publish.html"))
}
开发者ID:JanSichula,项目名称:coconut,代码行数:7,代码来源:controller.go

示例5: update

func update(ctx *web.Context) {
	if ctx.Params["submit"] == "Delete" {
		ctx.SetCookie(web.NewCookie(cookieName, "", -1))
	} else {
		ctx.SetSecureCookie(cookieName, ctx.Params["cookie"], 0)
	}
	ctx.Redirect(301, "/")
}
开发者ID:hoisie,项目名称:web,代码行数:8,代码来源:secure_cookie.go

示例6: RequireAuthentication

func RequireAuthentication(ctx *web.Context) bool {
	session, _ := CookieStore.Get(ctx.Request, "monet-session")

	if session.Values["authenticated"] != true {
		ctx.Redirect(302, "/admin/login/")
		return true
	}
	return false
}
开发者ID:elimisteve,项目名称:monet,代码行数:9,代码来源:admin.go

示例7: 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.Unix(p.Timestamp, 0)
		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:youngking,项目名称:fettemama,代码行数:55,代码来源:index.go

示例8: postDelete

func postDelete(ctx *web.Context, slug string) string {
	if app.RequireAuthentication(ctx) {
		return ""
	}
	db.Cursor(&Post{}).Remove(M{"slug": slug})
	referer := ctx.Request.Header.Get("referer")
	if len(referer) == 0 {
		referer = "/admin/"
	}
	ctx.Redirect(302, referer)
	return ""
}
开发者ID:jseaidou,项目名称:monet,代码行数:12,代码来源:admin.go

示例9: pageDelete

func pageDelete(ctx *web.Context, url string) string {
	if app.RequireAuthentication(ctx) {
		return ""
	}
	db.Cursor(&Page{}).Remove(M{"url": url})
	referer := ctx.Request.Header.Get("referer")
	if len(referer) == 0 {
		referer = "/admin/"
	}
	ctx.Redirect(302, referer)
	return ""
}
开发者ID:jseaidou,项目名称:monet,代码行数:12,代码来源:admin.go

示例10: S3GetHandler

func S3GetHandler(ctx *web.Context, key string) (ret string) {
	val := FakeS3[key]
	if val == "" {
		ctx.Abort(404, "Not Found")
		return
	} else if val == "FAIL" {
		ctx.Redirect(301, "htttttttp://idon'twork")
		return
	} else {
		return val
	}
}
开发者ID:jpoz,项目名称:s3meta,代码行数:12,代码来源:s3_test.go

示例11: login

func login(ctx *web.Context) string {
	if ctx.Params != nil {
		p := ctx.Params
		if ValidateUser(p["username"], p["password"]) {
			session, _ := CookieStore.Get(ctx.Request, "monet-session")
			session.Values["authenticated"] = true
			session.Save(ctx.Request, ctx.ResponseWriter)
			ctx.Redirect(302, "/admin/")
		}
	}
	return adminBase.Render("admin/login.mandira", ctx.Params, M{"login": true})
}
开发者ID:elimisteve,项目名称:monet,代码行数:12,代码来源:admin.go

示例12: addNewFeed

// Handler for adding a new feed
func addNewFeed(ctx *web.Context) string {
	url := ctx.Params["url"]
	source, err := loadFeed(url)
	if err != nil {
		return err.Error()
	}

	lock.Lock()
	folders["uncategorized"] = append(folders["uncategorized"], source)
	lock.Unlock()

	ctx.Redirect(303, "/")
	return ""
}
开发者ID:swenson,项目名称:littlereader,代码行数:15,代码来源:reader.go

示例13: login

// Checks login
func login(wr *web.Context) {

	// Login user
	if wr.Params["username"] != "" && wr.Params["password"] != "" {
		username := wr.Params["username"]
		password := wr.Params["password"]
		loginName := jailgo.Authenticate(username, password)

		// If you have a valid user
		if loginName != nil {
			log.Println("DEBUG Controller *Username type: ", loginName.User)
			wr.SetSecureCookie("user", loginName.User, 20000) //15 minutes for session
			wr.Redirect(303, "/jail?check=ok")

			// If you haven't
		} else {
			wr.Redirect(303, "/jail?check=err")
		}

		// Maybe you're going out
	} else if wr.Params["logout"] != "" {
		wr.SetSecureCookie("user", "off", 0)
		wr.Redirect(303, "/jail?check=out")
	} else {

		// If you wrote nothing
		log.Println("DEBUG Controller user: ", wr.Params["username"])
		log.Println("DEBUG Controller pass: ", wr.Params["password"])
		wr.Redirect(303, "/jail?check=err")
	}
}
开发者ID:elbing,项目名称:jailblog,代码行数:32,代码来源:jailBlogController.go

示例14: updateArt

// Update database for articles and render main page
func updateArt(wr *web.Context) {
	loginUser, err := wr.GetSecureCookie("user")
	if err {
		log.Println("DEBUG User logged updating article: ", loginUser)
		jailgo.Updateart(wr.Params["title"], wr.Params["description"])

		// Redirect to the main page which will show the specified art
		wr.Redirect(303, "/jail")

		// We could show this art directly using show(wr, art_num)
		// but see: http://en.wikipedia.org/wiki/Post/Redirect/Get
	} else {
		wr.Redirect(303, "/jail?check=err")
	}
}
开发者ID:elbing,项目名称:jailblog,代码行数:16,代码来源:jailBlogController.go

示例15: pageAdd

func pageAdd(ctx *web.Context) string {
	if app.RequireAuthentication(ctx) {
		return ""
	}

	if ctx.Request.Method == "GET" {
		ctx.Params["Url"] = strings.TrimLeft(ctx.Params["Url"], "/")
		return adminBase.Render("blog/admin/pages-edit.mandira", ctx.Params)
	}

	var page = new(Page)
	page.FromParams(ctx.Params)
	db.Upsert(page)
	ctx.Redirect(302, "/admin/")
	return ""
	//ctx.Redirect(302, "/admin/posts/edit/" + post.Slug + "/")
}
开发者ID:jseaidou,项目名称:monet,代码行数:17,代码来源:admin.go


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