當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。