本文整理匯總了Golang中github.com/garyburd/twister/web.Request.Redirect方法的典型用法代碼示例。如果您正苦於以下問題:Golang Request.Redirect方法的具體用法?Golang Request.Redirect怎麽用?Golang Request.Redirect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/garyburd/twister/web.Request
的用法示例。
在下文中一共展示了Request.Redirect方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: authCallbackHandler
// authCallbackHandler handles redirect from Facebook OAuth2 authorization page.
func authCallbackHandler(req *web.Request) {
code := req.Param.Get("code")
if code == "" {
// should display error_reason
req.Redirect("/", false)
return
}
f, err := getUrlEncodedForm("https://graph.facebook.com/oauth/access_token",
web.NewValues(
"client_id", appID, // defined in settings.go
"client_secret", appSecret, // defined in settings.go
"redirect_uri", req.URL.Scheme+"://"+req.URL.Host+"/callback",
"code", code))
if err != nil {
req.Error(web.StatusInternalServerError, err)
return
}
token := f.Get("access_token")
expires := f.Get("expires")
if expires == "" {
expires = "3600"
}
maxAge, err := strconv.Atoi(expires)
if err != nil {
maxAge = 3600
} else {
maxAge -= 30 // fudge
}
req.Redirect("/", false,
web.HeaderSetCookie, web.NewCookie("fbtok", token).
MaxAge(maxAge-30).String())
}
示例2: loginHandler
// loginHandler redirects to Facebook OAuth2 authorization page.
func loginHandler(req *web.Request) {
m := web.NewValues(
"client_id", appID, // defined in settings.go
"scope", "read_stream",
"redirect_uri", req.URL.Scheme+"://"+req.URL.Host+"/callback")
req.Redirect("https://graph.facebook.com/oauth/authorize?"+m.FormEncodedString(), false)
}
示例3: renameTag
func renameTag(req *web.Request) {
// oldTag := req.Param.Get("oldTag")
newTag := req.Param.Get("newTag")
// updateTag(oldTag, newTag)
url := fmt.Sprintf("/tag/%s", url.QueryEscape(newTag))
req.Redirect(url, false)
}
示例4: pathHandler
func pathHandler(req *web.Request, targetPattern string) {
if newPath := req.Param.Get("path"); newPath == "" {
req.Error(web.StatusNotFound, os.NewError("Not Found."))
} else {
newUrl := fmt.Sprintf(targetPattern, req.URL.Scheme, req.URL.Host, newPath)
req.Redirect(newUrl, true)
}
}
示例5: createCustomerHandler
func createCustomerHandler(req *web.Request) {
orderId := req.Param.Get("order")
name := req.Param.Get("name")
email := req.Param.Get("email")
id := NewUUID()
storeCustomer(id.String(), name, email)
req.Redirect("/order/?id="+orderId, false)
}
示例6: createEventHandler
func createEventHandler(req *web.Request) {
orderId := req.Param.Get("order")
name := req.Param.Get("name")
value := req.Param.Get("value")
id := NewUUID()
storeEvent(id.String(), orderId, name, value)
req.Redirect("/order/?id="+orderId, false)
}
示例7: viewHandler
func viewHandler(req *web.Request) {
title := req.URLParam["title"]
p, err := loadPage(title)
if err != nil {
req.Redirect("/edit/"+title, false)
return
}
renderTemplate(req, "view", p)
}
示例8: login
// login redirects the user to the Twitter authorization page.
func login(req *web.Request) {
callback := req.URL.Scheme + "://" + req.URL.Host + "/callback"
temporaryCredentials, err := oauthClient.RequestTemporaryCredentials(http.DefaultClient, callback)
if err != nil {
req.Error(web.StatusInternalServerError, err)
return
}
req.Redirect(oauthClient.AuthorizationURL(temporaryCredentials), false,
web.HeaderSetCookie, credentialsCookie("tmp", temporaryCredentials, 0))
}
示例9: saveHandler
func saveHandler(req *web.Request) {
body := req.Param.Get("body")
title := req.URLParam["title"]
p := &page{Title: title, Body: []byte(body)}
err := p.save()
if err != nil {
req.Error(web.StatusInternalServerError, err)
return
}
req.Redirect("/view/"+title, false)
}
示例10: createLineHandler
func createLineHandler(req *web.Request) {
orderId := req.Param.Get("order")
customer := req.Param.Get("customer")
name := req.Param.Get("name")
quantity := req.Param.Get("quantity")
price := req.Param.Get("price")
id := NewUUID()
quantityInt, _ := strconv.Atoi(quantity)
priceInt, _ := strconv.Atof64(price)
storeLine(id.String(), orderId, customer, name, quantityInt, priceInt)
req.Redirect("/order/?id="+orderId, false)
}
示例11: saveHandler
func saveHandler(req *web.Request) {
permalink := req.Param.Get("page-permalink")
title := req.Param.Get("page-title")
description := req.Param.Get("page-description")
pageTitle := req.Param.Get("page-page-title")
keywords := req.Param.Get("page-keywords")
content := req.Param.Get("page-content")
template := req.Param.Get("page-template")
byline := req.Param.Get("newsitem-byline")
blurb := req.Param.Get("newsitem-blurb")
fulldescription := req.Param.Get("newsitem-fulldescription")
imagepath := req.Param.Get("newsitem-imagepath")
externallink := req.Param.Get("newsitem-externallink")
newscategory := req.Param.Get("newsitem-newscategory")
contributedby := req.Param.Get("newsitem-contributedby")
n := &NewsItem{Page: Page{Permalink: permalink,
Title: title,
Description: description,
Keywords: keywords,
PageTitle: pageTitle,
Content: content,
Template: template},
Tags: strings.Split(req.Param.Get("newsitem-tags"), ",", -1),
ContributedBy: contributedby,
Byline: byline,
PostedTime: time.Seconds(),
Blurb: blurb,
ImagePath: imagepath,
ExternalLink: externallink,
NewsCategory: newscategory,
FullDescription: fulldescription}
mongo, err := mgo.Mongo("127.0.0.1")
defer mongo.Close()
if err != nil {
panic(err)
}
c := mongo.DB(*database).C("newsitems")
err = c.Upsert(bson.M{"page.permalink": permalink}, n)
if err != nil {
log.Println(err)
}
go removeCachedNewsItem(permalink)
req.Redirect("/"+permalink, false)
}
示例12: handleSign
func handleSign(r *web.Request) {
c := gae.Context(r)
g := &Greeting{
Content: r.Param.Get("content"),
Date: datastore.SecondsToTime(time.Seconds()),
}
if u := user.Current(c); u != nil {
g.Author = u.String()
}
if _, err := datastore.Put(c, datastore.NewIncompleteKey("Greeting"), g); err != nil {
r.Error(web.StatusInternalServerError, err)
return
}
r.Redirect("/", false)
}
示例13: authCallback
// authCallback handles OAuth callbacks from Twitter.
func authCallback(req *web.Request) {
temporaryCredentials, err := credentials(req, "tmp")
if err != nil {
req.Error(web.StatusNotFound, err)
return
}
s := req.Param.Get("oauth_token")
if s == "" {
req.Error(web.StatusNotFound, os.NewError("main: no token"))
return
}
if s != temporaryCredentials.Token {
req.Error(web.StatusNotFound, os.NewError("main: token mismatch"))
return
}
tokenCredentials, _, err := oauthClient.RequestToken(http.DefaultClient, temporaryCredentials, req.Param.Get("oauth_verifier"))
if err != nil {
req.Error(web.StatusNotFound, err)
return
}
req.Redirect("/", false,
web.HeaderSetCookie, credentialsCookie("tok", tokenCredentials, 30),
web.HeaderSetCookie, web.NewCookie("tmp", "").Delete().String())
}
示例14: logoutHandler
// logoutHandler logs the user out by clearing the access token cookie.
func logoutHandler(req *web.Request) {
req.Redirect("/", false,
web.HeaderSetCookie, web.NewCookie("fbtok", "").Delete().String())
}
示例15: paidHandler
func paidHandler(req *web.Request) {
orderId := req.Param.Get("order")
customerId := req.Param.Get("customer")
payLines(orderId, customerId)
req.Redirect("/order/?id="+orderId, false)
}