本文整理汇总了Golang中lib/wcg.Request类的典型用法代码示例。如果您正苦于以下问题:Golang Request类的具体用法?Golang Request怎么用?Golang Request使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Request类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: RunInBackground
// RunInBackground a wrapper for runtime.RunInBackground
func RunInBackground(req *wcg.Request, f func(*wcg.Request)) {
bgReq := req.Clone()
runtime.RunInBackground(NewContext(req), func(ctx context.Context) {
bgReq.SetLocal("__gaebg_context", ctx)
f(bgReq)
})
}
示例2: GetTemplates
func (pi *PageResponse) GetTemplates(req *wcg.Request) []string {
if pi.StatusCode >= 400 {
file := fmt.Sprintf("%d.html", pi.StatusCode)
_, err := os.Stat(path.Join(wcg.ViewConfig.BaseDir, file))
if os.IsNotExist(err) {
return []string{"500.html", "header.html", "footer.html"}
}
return []string{file, "header.html", "footer.html"}
}
// succses case
var _p = pi.templatePath
if _p == "" {
_p = req.URL().Path
}
if strings.HasPrefix(_p, "/") {
_p = fmt.Sprintf(".%s", _p) // make path (/path/to/endpoint/) relative (./path/to/endpoint)
}
if path.Ext(_p) == "" {
_p = path.Join(_p, "/index.html")
}
_, err := os.Stat(path.Join(wcg.ViewConfig.BaseDir, _p))
if os.IsNotExist(err) {
return []string{"default.html", "header.html", "footer.html"}
}
return []string{_p, "header.html", "footer.html"}
}
示例3: canSkipSessionMiddleware
func canSkipSessionMiddleware(req *wcg.Request) bool {
return req.Header(request.APITokenHeader) != "" ||
request.IsStatic(req) ||
request.IsHook(req) ||
request.IsCron(req) ||
request.IsTask(req)
}
示例4: getAPITokenHeader
func getAPITokenHeader(req *wcg.Request) string {
token := req.Header(request.APITokenHeader)
if wcg.IsUUID(token) {
return token
}
return ""
}
示例5: debugger
func debugger(res *wcg.Response, req *wcg.Request) {
if !gates.CanPass(req, "debugger") {
return
}
if req.Header("x-ajax-request") == "true" {
// TODO: implement debugger here
}
}
示例6: getIEPGURLResolver
// getIEPGURLResolver returns iepgURLResolver object.
// the mock object in '__test_iepg_url_resolver' local variable in the request can be used for testing.
func getIEPGURLResolver(req *wcg.Request) *iepgURLResolver {
if req.IsTest() {
if v := req.Local("__test_iepg_url_resolver"); v != nil {
if v1, ok := v.(*iepgURLResolver); ok {
return v1
}
}
}
return defaultIEPGURLResolver
}
示例7: PushTask
// PushTask to push a task into the queue.
func (queue *PushQueue) PushTask(req *wcg.Request, urlPath string, form url.Values) error {
var queueName string
if req.IsTest() || lib.IsOnLocalGAE() {
queueName = "default"
} else {
queueName = queue.Name
}
if _, err := taskqueue.Add(gae.NewContext(req), taskqueue.NewPOSTTask(urlPath, form), queueName); err != nil {
req.Logger.Errorf("[Queue] Error adding a task (%s) into the queue (%q): %v", urlPath, queueName, err)
return err
}
return nil
}
示例8: sendToBigQuery
func sendToBigQuery(req *wcg.Request) error {
var errors = make([]error, 0)
var svc *bigquery.Service
var records []*wcg.LogRecord
var tmp interface{}
data := make(map[string][]*bigquery.TableDataInsertAllRequestRows)
if tmp = req.Local(requestLocalLogCacheKey); tmp == nil {
return nil
}
records = tmp.([]*wcg.LogRecord)
svc, err := bq.NewService(req)
if err != nil {
return err
}
for _, r := range records {
tableID, row, err := bqTransform(r)
if err != nil {
errors = append(errors, err)
continue
}
if rows, ok := data[tableID]; ok {
rows = append(rows, row)
} else {
data[tableID] = []*bigquery.TableDataInsertAllRequestRows{row}
}
}
for tableID, rows := range data {
ret, err := svc.Tabledata.InsertAll(
LogSinkConfig.BigqueryProject,
LogSinkConfig.BigqueryDataset,
tableID,
&bigquery.TableDataInsertAllRequest{
Kind: "bigquery#tableDataInsertAllRequest",
Rows: rows,
}).Do()
if err != nil {
errors = append(errors, err)
continue
}
if len(ret.InsertErrors) > 0 {
errors = append(errors, fmt.Errorf("InsertErrors: %s", ret.InsertErrors[0]))
continue
}
}
if len(errors) > 0 {
return logTransmissionError(errors)
}
return nil
}
示例9: NewTaskUser
// NewTaskUser creatse a *APITokenUser for the task
func NewTaskUser(req *wcg.Request) *APITokenUser {
return &APITokenUser{
&models.APIToken{
Token: "x-appengine-taskqueue",
Description: fmt.Sprintf(
"TaskName=%q, QueueName=%q",
req.Header("X-AppEngine-TaskName"),
req.Header("X-AppEngine-QueueName"),
),
CreatedAt: time.Now(),
AlertOn: time.Duration(0),
LastAccess: time.Now(),
},
}
}
示例10: authorizeByAPIToken
func authorizeByAPIToken(req *wcg.Request) {
tokenString := req.Header(request.APITokenHeader)
if !lib.IsOnGAE() && !lib.IsProduction() && tokenString == string(request.APITestUser.Token) {
req.User = request.APITestUser
return
}
if !wcg.IsUUID(tokenString) {
// Do not access APIToken entity if it's not a valid UUID.
return
}
_, ent, err := entities.APIToken.Get().Key(tokenString).Cache(true).One(req)
if err == nil {
req.User = &request.APITokenUser{ent.(*models.APIToken)}
return
}
}
示例11: NewService
// NewService returns a new bigquery service accessor instance
func NewService(req *wcg.Request) (*bigquery.Service, error) {
var ctx context.Context
tmp := req.Local("__gaetest__context")
if tmp != nil {
ctx = tmp.(context.Context)
} else {
ctx = appengine.NewContext(req.HTTPRequest())
}
client, err := NewHTTPClient(ctx)
if err != nil {
return nil, err
}
svc, err := bigquery.New(client)
if err != nil {
return nil, err
}
return svc, nil
}
示例12: newRemoteAPIContext
func newRemoteAPIContext(req *wcg.Request, host string) (context.Context, error) {
// TODO: migrate file to datastore?
if !lib.IsOnLocalGAE() && !req.IsTest() {
return nil, fmt.Errorf("RemoteAPI use on GAE is not supported yet.")
}
var hc *http.Client
var err error
const defaultCredentialEnvKey = "GOOGLE_APPLICATION_CREDENTIALS"
if os.Getenv(defaultCredentialEnvKey) != "" {
hc, err = google.DefaultClient(gae.NewContext(req), remoteCtxScopes...)
} else {
return nil, ErrNoRemoteAPIKeyIsConfigured
}
if err != nil {
return nil, err
}
return remote_api.NewRemoteContext(host, hc)
}
示例13: newMediaClient
func newMediaClient(req *wcg.Request) (*media.Client, error) {
const fallbackServer = "speedland-ng-dev.appspot.com"
kind := entities.OAuth2ClientSettings
if lib.IsOnLocalGAE() || req.IsTest() {
kind = kind.NewRemote(fallbackServer)
}
_, settings, err := kind.Get().Key(OAuth2ClientKey).One(req)
if err != nil {
return nil, err
}
if settings == nil {
if lib.IsOnLocalGAE() || req.IsTest() {
return nil, fmt.Errorf("OAuthClient `%s` is not configured on %s", OAuth2ClientKey, fallbackServer)
}
return nil, fmt.Errorf("OAuthClient `%s` is not configured", OAuth2ClientKey)
}
return media.NewClient(
settings.(*models.OAuth2ClientSettings).GenClient(urlfetch.NewContext(req)),
), nil
}
示例14: findArtistAndMember
func findArtistAndMember(req *wcg.Request) *hplink.Member {
var artist *hplink.Artist
var member *hplink.Member
var funcs = []func(){
func() {
_, ent := entities.Artist.Get().Key(
req.Param(paramKeyArtist),
).MustOne(req)
if ent != nil {
artist = ent.(*hplink.Artist)
}
},
func() {
_, ent := entities.Member.Get().Key(
fmt.Sprintf("%s.%s", req.Param(paramKeyArtist), req.Param(paramKeyMember)),
).MustOne(req)
if ent != nil {
member = ent.(*hplink.Member)
}
},
}
iterator.ParallelSlice(funcs, func(i int, v func()) error {
v()
return nil
})
if artist == nil || member == nil {
return nil
}
member.Artist = artist
return member
}
示例15: NewContext
// NewContext a wrapper for appengine.NewContext
func NewContext(req *wcg.Request) context.Context {
ctx := req.Local("__gaetest__context")
if ctx != nil {
return ctx.(context.Context)
}
ctx = req.Local("__gaebg_context")
if ctx != nil {
return ctx.(context.Context)
}
return appengine.NewContext(req.HTTPRequest())
}