本文整理匯總了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)
}
示例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 ""
}
示例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)
}
}
示例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"))
}
示例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, "/")
}
示例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
}
示例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
}
示例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 ""
}
示例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 ""
}
示例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
}
}
示例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})
}
示例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 ""
}
示例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")
}
}
示例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")
}
}
示例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 + "/")
}