當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Context.Value方法代碼示例

本文整理匯總了Golang中github.com/flynn/flynn/Godeps/_workspace/src/golang.org/x/net/context.Context.Value方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.Value方法的具體用法?Golang Context.Value怎麽用?Golang Context.Value使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/flynn/flynn/Godeps/_workspace/src/golang.org/x/net/context.Context的用法示例。


在下文中一共展示了Context.Value方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: retrieveToken

// retrieveToken takes a *Config and uses that to retrieve an *internal.Token.
// This token is then mapped from *internal.Token into an *oauth2.Token which is returned along
// with an error..
func retrieveToken(ctx context.Context, c *Config, v url.Values) (*Token, error) {
	tk, err := internal.RetrieveToken(ctx, c.ClientID, c.ClientSecret, c.Endpoint.TokenURL, v)
	if err != nil {
		return nil, err
	}
	token := tokenFromInternal(tk)
	if notifierFunc, ok := ctx.Value(TokenRefreshNotifier).(TokenRefreshNotifierFunc); ok {
		notifierFunc(token)
	}
	return token, nil
}
開發者ID:devick,項目名稱:flynn,代碼行數:14,代碼來源:token.go

示例2: ContextClient

func ContextClient(ctx context.Context) (*http.Client, error) {
	for _, fn := range contextClientFuncs {
		c, err := fn(ctx)
		if err != nil {
			return nil, err
		}
		if c != nil {
			return c, nil
		}
	}
	if hc, ok := ctx.Value(HTTPClient).(*http.Client); ok {
		return hc, nil
	}
	return http.DefaultClient, nil
}
開發者ID:devick,項目名稱:flynn,代碼行數:15,代碼來源:transport.go

示例3: getApp

func (c *controllerAPI) getApp(ctx context.Context) *ct.App {
	return ctx.Value("app").(*ct.App)
}
開發者ID:GrimDerp,項目名稱:flynn,代碼行數:3,代碼來源:controller.go

示例4: SessionFromContext

func (api *API) SessionFromContext(ctx context.Context) *sessions.Session {
	return ctx.Value(ctxSessionKey).(*sessions.Session)
}
開發者ID:eldarion-gondor,項目名稱:cli,代碼行數:3,代碼來源:api.go

示例5: StartTimeFromContext

// StartTimeFromContext extracts a start time from a context.
func StartTimeFromContext(ctx context.Context) (start time.Time, ok bool) {
	start, ok = ctx.Value(ctxKeyStartTime).(time.Time)
	return
}
開發者ID:devick,項目名稱:flynn,代碼行數:5,代碼來源:ctxhelper.go

示例6: RequestIDFromContext

// RequestIDFromContext extracts a request ID from a context.
func RequestIDFromContext(ctx context.Context) (id string, ok bool) {
	id, ok = ctx.Value(ctxKeyReqID).(string)
	return
}
開發者ID:devick,項目名稱:flynn,代碼行數:5,代碼來源:ctxhelper.go

示例7: ParamsFromContext

// ParamsFromContext extracts params from a context.
func ParamsFromContext(ctx context.Context) (params httprouter.Params, ok bool) {
	params, ok = ctx.Value(ctxKeyParams).(httprouter.Params)
	return
}
開發者ID:devick,項目名稱:flynn,代碼行數:5,代碼來源:ctxhelper.go

示例8: LoggerFromContext

// LoggerFromContext extracts a logger from a context.
func LoggerFromContext(ctx context.Context) (logger log.Logger, ok bool) {
	logger, ok = ctx.Value(ctxKeyLogger).(log.Logger)
	return
}
開發者ID:devick,項目名稱:flynn,代碼行數:5,代碼來源:ctxhelper.go

示例9: ComponentNameFromContext

// ComponentNameFromContext extracts a component name from a context.
func ComponentNameFromContext(ctx context.Context) (componentName string, ok bool) {
	componentName, ok = ctx.Value(ctxKeyComponent).(string)
	return
}
開發者ID:devick,項目名稱:flynn,代碼行數:5,代碼來源:ctxhelper.go


注:本文中的github.com/flynn/flynn/Godeps/_workspace/src/golang.org/x/net/context.Context.Value方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。