当前位置: 首页>>代码示例>>Golang>>正文


Golang wcg.Request类代码示例

本文整理汇总了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)
	})
}
开发者ID:speedland,项目名称:service,代码行数:8,代码来源:util.go

示例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"}
}
开发者ID:speedland,项目名称:service,代码行数:26,代码来源:page.go

示例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)
}
开发者ID:speedland,项目名称:service,代码行数:7,代码来源:session.go

示例4: getAPITokenHeader

func getAPITokenHeader(req *wcg.Request) string {
	token := req.Header(request.APITokenHeader)
	if wcg.IsUUID(token) {
		return token
	}
	return ""
}
开发者ID:speedland,项目名称:service,代码行数:7,代码来源:header.go

示例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
	}
}
开发者ID:speedland,项目名称:service,代码行数:8,代码来源:debugger.go

示例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
}
开发者ID:speedland,项目名称:service,代码行数:12,代码来源:func_iepg.go

示例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
}
开发者ID:speedland,项目名称:service,代码行数:14,代码来源:taskqueue.go

示例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
}
开发者ID:speedland,项目名称:service,代码行数:51,代码来源:bigquery_logging.go

示例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(),
		},
	}
}
开发者ID:speedland,项目名称:service,代码行数:16,代码来源:user.go

示例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
	}
}
开发者ID:speedland,项目名称:service,代码行数:17,代码来源:header.go

示例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
}
开发者ID:speedland,项目名称:service,代码行数:20,代码来源:helper.go

示例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)
}
开发者ID:speedland,项目名称:service,代码行数:19,代码来源:remote_api.go

示例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
}
开发者ID:speedland,项目名称:service,代码行数:20,代码来源:image.go

示例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
}
开发者ID:speedland,项目名称:service,代码行数:31,代码来源:member_handler.go

示例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())
}
开发者ID:speedland,项目名称:service,代码行数:12,代码来源:util.go


注:本文中的lib/wcg.Request类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。