本文整理汇总了Golang中github.com/speedland/wcg.Request.HttpRequest方法的典型用法代码示例。如果您正苦于以下问题:Golang Request.HttpRequest方法的具体用法?Golang Request.HttpRequest怎么用?Golang Request.HttpRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/speedland/wcg.Request
的用法示例。
在下文中一共展示了Request.HttpRequest方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewContext
// Returns a Context Object.
func NewContext(req *wcg.Request) appengine.Context {
ctx := req.Local("__gaetest__context")
if ctx != nil {
return ctx.(appengine.Context)
}
return appengine.NewContext(req.HttpRequest())
}
示例2: queryShows
func queryShows(res *wcg.Response, req *wcg.Request, q *datastore.Query) (*showQueryResult, error) {
var appCtx = lib.NewAppContextFromRequest(req)
var showList []event.Show
var basePath = req.HttpRequest().URL.Path
per_page := 12 // Restict to 12 due to view rendering.
page := wcg.ParseInt(req.Query("page"), 0, 0, wcg.ParseIntMax)
if _, err := q.Offset(page * per_page).Limit(per_page).GetAll(&showList); err != nil {
return nil, err
}
if showList == nil {
return &showQueryResult{
Shows: make([]EventShow, 0),
}, nil
}
if list, err := NewEventShowList(appCtx, showList); err != nil {
return nil, err
} else {
p := &showQueryResult{
Shows: list,
Current: fmt.Sprintf("%s?page=%d&n=%d", basePath, page, per_page),
}
// prev url
if page > 0 {
p.Previous = fmt.Sprintf("%s?page=%d&n=%d", basePath, page-1, per_page)
}
// next url
if len(p.Shows) == per_page {
p.Next = fmt.Sprintf("%s?page=%d&n=%d", basePath, page+1, per_page)
}
return p, nil
}
}
示例3: updateAttributesFromForm
func updateAttributesFromForm(res *wcg.Response, req *wcg.Request, e *event.Event) error {
var err error
if err = eventFormValidator.Eval(req.HttpRequest().PostForm); err != nil {
return err
}
e.Title = req.Form("title")
e.Link = req.Form("link")
e.ImageLink = req.Form("image_link")
e.YAKeyword = req.Form("ya_keyword")
e.EventType = event.ParseEventType(req.Form("event_type"))
return nil
}
示例4: updateAttributesFromForm
func updateAttributesFromForm(res *wcg.Response, req *wcg.Request, p *blog.Post) error {
var err error
if err = postFormValidator.Eval(req.HttpRequest().PostForm); err != nil {
return err
}
p.Title = req.Form("title")
p.Content = req.Form("content")
p.Tags = blog.ParseTagString(req.Form("tags"))
p.IsDraft = req.Form("is_draft") == "true"
p.IsHidden = req.Form("is_hidden") == "true"
p.PublishAt, err = wcg.ParseDateTime(req.Form("publish_at"))
return nil
}
示例5: NewService
func NewService(req *wcg.Request) (*bigquery.Service, error) {
var ctx appengine.Context
tmp := req.Local("__gaetest__context")
if tmp != nil {
ctx = tmp.(appengine.Context)
} else {
ctx = appengine.NewContext(req.HttpRequest())
}
client, err := serviceaccount.NewClient(ctx, bigquery.BigqueryScope)
if err != nil {
return nil, err
}
svc, err := bigquery.New(client)
if err != nil {
return nil, err
}
return svc, nil
}
示例6: queryPosts
func queryPosts(res *wcg.Response, req *wcg.Request, per_page int) (*postQueryResult, error) {
var list []blog.Post
var basePath = req.HttpRequest().URL.Path
is_admin := (lib.GetUserKind(req) == lib.Admin) && (req.Query("is_admin") == "true")
if per_page == 0 {
per_page = wcg.ParseInt(req.Query("n"), 5, 0, 20) // default 5, max 20
}
page := wcg.ParseInt(req.Query("page"), 0, 0, wcg.ParseIntMax)
q := NewPostDriver(lib.NewAppContextFromRequest(req)).NewQuery()
q = q.Order("-PublishAt").Order("-CreatedAt")
if !is_admin {
q = q.Filter("PublishAt <=", time.Now()).Filter("IsDraft =", false).Filter("IsHidden =", false)
}
_, err := q.Offset(page * per_page).Limit(per_page).GetAll(&list)
if err != nil {
return nil, err
}
if list == nil {
list = make([]blog.Post, 0)
}
p := &postQueryResult{
Posts: list,
}
// prev url
if page > 0 {
p.Previous = fmt.Sprintf("%s?page=%d&n=%d", basePath, page-1, per_page)
if is_admin {
p.Previous = fmt.Sprintf("%s&is_admin=true", p.Previous)
}
}
// next url
if len(list) == per_page {
p.Next = fmt.Sprintf("%s?page=%d&n=%d", basePath, page+1, per_page)
if is_admin {
p.Next = fmt.Sprintf("%s&is_admin=true", p.Next)
}
}
return p, nil
}