Explorar el Código

新增添加values的context

dcsunny hace 3 años
padre
commit
69ba598f39
Se han modificado 1 ficheros con 11 adiciones y 0 borrados
  1. 11 0
      common/context.go

+ 11 - 0
common/context.go

@@ -19,6 +19,17 @@ func NewContextWithAccountID(parentCtx context.Context, accountID int64) context
 	return newCtx
 }
 
+func NewContextWithValues(parentCtx context.Context, values map[string]interface{}) context.Context {
+	ctx := &AccountContext{ctx: parentCtx}
+	newCtx := context.Context(ctx)
+	for k, v := range values {
+		_k := k
+		_v := v
+		newCtx = context2.AppendToContext(ctx, _k, _v)
+	}
+	return newCtx
+}
+
 type AccountContext struct {
 	ctx context.Context
 }