本文整理汇总了Golang中github.com/speedland/wcg.Request.Local方法的典型用法代码示例。如果您正苦于以下问题:Golang Request.Local方法的具体用法?Golang Request.Local怎么用?Golang Request.Local使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/speedland/wcg.Request
的用法示例。
在下文中一共展示了Request.Local方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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
}
示例3: GetCurrentApp
func GetCurrentApp(req *wcg.Request) *App {
if app := req.Local(LOCAL_APP_KEY); app != nil {
return app.(*App)
} else {
return nil
}
}
示例4: sendToBigQuery
func sendToBigQuery(req *wcg.Request) error {
var errors = make([]error, 0)
var svc *bigquery.Service
var records []*wcg.LogRecord
data := make(map[string][]*bigquery.TableDataInsertAllRequestRows)
if tmp := req.Local(requestLocalLogCacheKey); tmp == nil {
return nil
} else {
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
}
示例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
}