| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- package common
- import (
- "context"
- "time"
- context2 "git.ikuban.com/server/kratos-utils/http/context"
- )
- 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}
- newCtx := context2.AppendToContext(ctx, "user_id", accountID)
- newCtx = context2.AppendToContext(newCtx, "account_id", accountID)
- 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
- }
- func (this *AccountContext) Deadline() (deadline time.Time, ok bool) {
- return
- }
- func (*AccountContext) Done() <-chan struct{} {
- return nil
- }
- func (this *AccountContext) Err() error {
- return nil
- }
- func (this *AccountContext) Value(key interface{}) interface{} {
- return this.ctx.Value(key)
- }
|