|
|
@@ -2,13 +2,39 @@ package common
|
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
+ "time"
|
|
|
|
|
|
context2 "git.ikuban.com/server/kratos-utils/http/context"
|
|
|
)
|
|
|
|
|
|
-func NewContext(accountID int64) context.Context {
|
|
|
- ctx := context.Background()
|
|
|
- ctx = context2.AppendToContext(ctx, "user_id", accountID)
|
|
|
- ctx = context2.AppendToContext(ctx, "account_id", accountID)
|
|
|
+func NewContext(parentCtx context.Context) context.Context {
|
|
|
+ ctx := &AccountContext{ctx: parentCtx}
|
|
|
return ctx
|
|
|
}
|
|
|
+
|
|
|
+func NewContextWithAccountID(parentCtx context.Context, accountID int64) context.Context {
|
|
|
+ ctx := &AccountContext{ctx: parentCtx}
|
|
|
+ ctx = context2.AppendToContext(ctx, "user_id", accountID).(*AccountContext)
|
|
|
+ ctx = context2.AppendToContext(ctx, "account_id", accountID).(*AccountContext)
|
|
|
+ return ctx
|
|
|
+}
|
|
|
+
|
|
|
+type AccountContext struct {
|
|
|
+ ctx context.Context
|
|
|
+}
|
|
|
+
|
|
|
+func (this *AccountContext) Deadline() (deadline time.Time, ok bool) {
|
|
|
+ return this.ctx.Deadline()
|
|
|
+}
|
|
|
+
|
|
|
+func (*AccountContext) Done() <-chan struct{} {
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+func (this *AccountContext) Err() error {
|
|
|
+ return this.ctx.Err()
|
|
|
+}
|
|
|
+
|
|
|
+func (this *AccountContext) Value(key interface{}) interface{} {
|
|
|
+ return this.ctx.Value(key)
|
|
|
+}
|