Adds context support for nas, oss and s3

This commit is contained in:
Ersan
2018-03-14 18:36:54 -07:00
committed by kannappanr
parent bdb1a90720
commit 33fe42df8a
6 changed files with 86 additions and 77 deletions

View File

@@ -19,7 +19,9 @@ package logger
import "context"
// Key used for ContextSet/Get
const contextKey = "reqInfo"
type contextKeyType string
const contextLogKey = contextKeyType("miniolog")
// KeyVal - appended to ReqInfo.Tags
type KeyVal struct {
@@ -48,12 +50,12 @@ func (r *ReqInfo) AppendTags(key string, val string) {
// ContextSet sets ReqInfo in the context.
func ContextSet(ctx context.Context, req *ReqInfo) context.Context {
return context.WithValue(ctx, contextKey, req)
return context.WithValue(ctx, contextLogKey, req)
}
// ContextGet returns ReqInfo if set.
func ContextGet(ctx context.Context) *ReqInfo {
r, ok := ctx.Value(contextKey).(*ReqInfo)
r, ok := ctx.Value(contextLogKey).(*ReqInfo)
if ok {
return r
}