本文整理汇总了Golang中github.com/speedland/wcg.Request.URL方法的典型用法代码示例。如果您正苦于以下问题:Golang Request.URL方法的具体用法?Golang Request.URL怎么用?Golang Request.URL使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/speedland/wcg.Request
的用法示例。
在下文中一共展示了Request.URL方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getResponseHelper
func getResponseHelper(req *wcg.Request) ResponseHelper {
app := req.Local(LOCAL_APP_KEY).(*App)
if strings.HasPrefix(req.URL().Path, "/api") {
return app.Api
}
return app.Page
}
示例2: Created
// HTTP 201 Created
func (api *ApiHelper) Created(res *wcg.Response, req *wcg.Request, id string) {
loc := path.Join(req.URL().Path, fmt.Sprintf("%s.json", id))
res.WriteJsonWithStatus(201, nil, map[string]interface{}{
"ok": true,
"id": id,
"location": wcg.AbsoluteUrl(req, loc),
})
}
示例3: Forbidden
func (ph *PageHelper) Forbidden(res *wcg.Response, req *wcg.Request) {
res.SetLocal("Ref", req.URL().RequestURI())
res.TemplatesWithStatus(
403,
nil,
"403.html", "header.html", "footer.html",
)
}
示例4: ahAuthHandler
func ahAuthHandler(res *wcg.Response, req *wcg.Request) bool {
if strings.HasPrefix(req.URL().Path, "/_ah/") {
req.User = &ApiUser{
token: &models.ApiToken{
Token: "x-appengine-ah",
Description: "Dummy API Token (_ah user)",
CreatedAt: time.Now(),
},
lastLogin: time.Now(),
}
return true
}
return false
}
示例5: showBlogHandler
func showBlogHandler(res *wcg.Response, req *wcg.Request) {
blog, posts, err := fetchBlog(res, req, true)
if err != nil {
return
}
res.SetLocal("Og", &supports.Og{Title: blog.Title,
Type: "blog", Url: wcg.AbsoluteUrl(req, req.URL().Path),
Description: blog.Description, SiteName: AppConfig.SiteTitle,
})
res.SetLocal("blog", blog)
res.SetLocal("is_owner", blog.OwnerId == req.User.Id())
res.SetLocal("posts", posts)
res.SetLocal("js", "/static/js/blog.js")
res.Templates("blog.html", "header.html", "footer.html", "parts/post_part.html")
}
示例6: _processRequest
func (p *Page) _processRequest(res *wcg.Response, req *wcg.Request) {
// instance of Page
pi := &Page{}
pi.App = p.App
pi.Title = p.Title
pi.Path = p.Path
pi.assetPath = p.assetPath
if p.templates != nil {
pi.templates = make([]string, len(p.templates))
for i := range p.templates {
pi.templates[i] = p.templates[i]
}
}
pi.Ogp("site_name", "SPEEDLAND Project")
// pre process to update page attributes
if p.handler != nil {
p.handler(res, req, pi)
if res.IsClosed() {
return
}
}
// automatically set ogp attributes if not set.
if _, ok := pi.ogp["title"]; !ok {
pi.Ogp("title", fmt.Sprintf("%s: %s", pi.App.Title, pi.Title))
}
if _, ok := pi.ogp["url"]; !ok {
pi.Ogp("url", wcg.AbsoluteUrl(req, req.URL().RequestURI()))
}
// set default OGP from app settings.
for k, v := range pi.App.DefaultOgp {
pi.Ogp(k, v)
}
res.SetLocal("Page", pi)
res.SetLocal("Ogp", pi.ogp)
res.SetLocal("Request", req)
res.SetLocal("TrackingCode", TrackingCode)
res.SetLocal("__JsBundle__", pi.GetAssetPath())
res.SetLocal("__APP_COMMIT", APP_COMMIT)
res.SetLocal("__APP_TIMESTAMP", APP_TIMESTAMP)
template_paths := []string{"./header.html", "./footer.html"}
res.Templates(append(pi.GetTemplates(), template_paths...)...)
}
示例7: showPostHandler
func showPostHandler(res *wcg.Response, req *wcg.Request) {
blog, _, err := fetchBlog(res, req, false)
if err != nil {
return
}
post, err := fetchPost(res, req, blog)
if err != nil {
return
}
res.SetLocal("Og", &supports.Og{Title: post.Title, Type: "article",
Url: wcg.AbsoluteUrl(req, req.URL().Path), SiteName: blog.Title,
Description: wcg.Shorten(post.Content, 80),
})
res.SetLocal("blog", blog)
res.SetLocal("post", post)
res.SetLocal("is_owner", post.OwnerId == req.User.Id())
res.SetLocal("js", "/static/js/post.js")
res.Templates("post.html", "header.html", "footer.html", "parts/post_part.html")
}