本文整理汇总了Golang中lib/wcg.Request.Local方法的典型用法代码示例。如果您正苦于以下问题:Golang Request.Local方法的具体用法?Golang Request.Local怎么用?Golang Request.Local使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib/wcg.Request
的用法示例。
在下文中一共展示了Request.Local方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例2: 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())
}
示例3: 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
}
示例4: 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
}