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


Golang Context.Value方法代碼示例

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


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

示例1: Logf

func Logf(ctx netcontext.Context, level int64, format string, args ...interface{}) {
	if f, ok := ctx.Value(&logOverrideKey).(logOverrideFunc); ok {
		f(level, format, args...)
		return
	}
	logf(fromContext(ctx), level, format, args...)
}
開發者ID:nildev,項目名稱:account,代碼行數:7,代碼來源:api_common.go

示例2: WithCallOverride

func WithCallOverride(ctx netcontext.Context, f CallOverrideFunc) netcontext.Context {
	// We avoid appending to any existing call override
	// so we don't risk overwriting a popped stack below.
	var cofs []CallOverrideFunc
	if uf, ok := ctx.Value(&callOverrideKey).([]CallOverrideFunc); ok {
		cofs = append(cofs, uf...)
	}
	cofs = append(cofs, f)
	return netcontext.WithValue(ctx, &callOverrideKey, cofs)
}
開發者ID:nildev,項目名稱:account,代碼行數:10,代碼來源:api_common.go

示例3: callOverrideFromContext

func callOverrideFromContext(ctx netcontext.Context) (CallOverrideFunc, netcontext.Context, bool) {
	cofs, _ := ctx.Value(&callOverrideKey).([]CallOverrideFunc)
	if len(cofs) == 0 {
		return nil, nil, false
	}
	// We found a list of overrides; grab the last, and reconstitute a
	// context that will hide it.
	f := cofs[len(cofs)-1]
	ctx = netcontext.WithValue(ctx, &callOverrideKey, cofs[:len(cofs)-1])
	return f, ctx, true
}
開發者ID:nildev,項目名稱:account,代碼行數:11,代碼來源:api_common.go

示例4: ContextClient

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

示例5: transactionFromContext

func transactionFromContext(ctx netcontext.Context) *transaction {
	t, _ := ctx.Value(&transactionKey).(*transaction)
	return t
}
開發者ID:nildev,項目名稱:account,代碼行數:4,代碼來源:transaction.go

示例6: fromContext

func fromContext(ctx netcontext.Context) appengine.Context {
	c, _ := ctx.Value(&contextKey).(appengine.Context)
	return c
}
開發者ID:nildev,項目名稱:account,代碼行數:4,代碼來源:api_classic.go

示例7: ctxNamespace

// ctxNamespace returns the active namespace for a context.
// It defaults to "" if no namespace was specified.
func ctxNamespace(ctx context.Context) string {
	v, _ := ctx.Value(nsKey{}).(string)
	return v
}
開發者ID:nildev,項目名稱:account,代碼行數:6,代碼來源:datastore.go

示例8: FromContext

// FromContext returns the peer information in ctx if it exists.
func FromContext(ctx context.Context) (p *Peer, ok bool) {
	p, ok = ctx.Value(peerKey{}).(*Peer)
	return
}
開發者ID:nildev,項目名稱:account,代碼行數:5,代碼來源:peer.go

示例9: fromContext

func fromContext(ctx netcontext.Context) *context {
	c, _ := ctx.Value(&contextKey).(*context)
	return c
}
開發者ID:nildev,項目名稱:account,代碼行數:4,代碼來源:api.go

示例10: cc

// cc returns the internal *cloudContext (cc) state for a context.Context.
// It panics if the user did it wrong.
func cc(ctx context.Context) *cloudContext {
	if c, ok := ctx.Value(contextKey{}).(*cloudContext); ok {
		return c
	}
	panic("invalid context.Context type; it should be created with cloud.NewContext")
}
開發者ID:nildev,項目名稱:account,代碼行數:8,代碼來源:cloud.go

示例11: FromContext

// FromContext returns the Trace bound to the context, if any.
func FromContext(ctx context.Context) (tr Trace, ok bool) {
	tr, ok = ctx.Value(contextKey).(Trace)
	return
}
開發者ID:nildev,項目名稱:account,代碼行數:5,代碼來源:trace.go

示例12: StreamFromContext

// StreamFromContext returns the stream saved in ctx.
func StreamFromContext(ctx context.Context) (s *Stream, ok bool) {
	s, ok = ctx.Value(streamKey).(*Stream)
	return
}
開發者ID:nildev,項目名稱:account,代碼行數:5,代碼來源:transport.go

示例13: FullyQualifiedAppID

// FullyQualifiedAppID returns the fully-qualified application ID.
// This may contain a partition prefix (e.g. "s~" for High Replication apps),
// or a domain prefix (e.g. "example.com:").
func FullyQualifiedAppID(ctx netcontext.Context) string {
	if id, ok := ctx.Value(&appIDOverrideKey).(string); ok {
		return id
	}
	return fullyQualifiedAppID(ctx)
}
開發者ID:nildev,項目名稱:account,代碼行數:9,代碼來源:api_common.go

示例14: NamespaceFromContext

func NamespaceFromContext(ctx netcontext.Context) string {
	// If there's no namespace, return the empty string.
	ns, _ := ctx.Value(&namespaceKey).(string)
	return ns
}
開發者ID:nildev,項目名稱:account,代碼行數:5,代碼來源:api_common.go

示例15: FromContext

// FromContext returns the MD in ctx if it exists.
func FromContext(ctx context.Context) (md MD, ok bool) {
	md, ok = ctx.Value(mdKey{}).(MD)
	return
}
開發者ID:nildev,項目名稱:account,代碼行數:5,代碼來源:metadata.go


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