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


Golang Context.Value方法代碼示例

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


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

示例1: LogError

// LogError logs the error to the owner of the context.
//
// If this context was created with ContextWithErrorLog, then this method
// passes the error to context creator over an unbuffered channel.
//
// If this context was created by other means, this method is a no-op.
func LogError(ctx context.Context, err error) {
    v := ctx.Value(errLogKey)
    errs, ok := v.(privateChanType)
    if !ok {
        return
    }
    errs <- err
}
開發者ID:musha68k,項目名稱:go-ipfs,代碼行數:14,代碼來源:context.go

示例2: checkCtxTTL

// setting the TTL on published records is an experimental feature.
// as such, i'm using the context to wire it through to avoid changing too
// much code along the way.
func checkCtxTTL(ctx context.Context) (time.Duration, bool) {
    v := ctx.Value("ipns-publish-ttl")
    if v == nil {
        return 0, false
    }

    d, ok := v.(time.Duration)
    return d, ok
}
開發者ID:eminence,項目名稱:go-ipfs,代碼行數:12,代碼來源:publisher.go

示例3: MetadataFromContext

func MetadataFromContext(ctx context.Context) (Metadata, error) {
    value := ctx.Value(metadataKey)
    if value != nil {
        metadata, ok := value.(Metadata)
        if ok {
            return metadata, nil
        }
    }
    return nil, errors.New("context contains no metadata")
}
開發者ID:ymonk,項目名稱:openbazaar-go,代碼行數:10,代碼來源:context.go

示例4: PublishQueryEvent

func PublishQueryEvent(ctx context.Context, ev *QueryEvent) {
    ich := ctx.Value(RoutingQueryKey)
    if ich == nil {
        return
    }

    ch, ok := ich.(chan<- *QueryEvent)
    if !ok {
        return
    }

    select {
    case ch <- ev:
    case <-ctx.Done():
    }
}
開發者ID:ccsblueboy,項目名稱:go-ipfs,代碼行數:16,代碼來源:query.go


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