| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- package common
- import (
- "context"
- "time"
- context2 "git.ikuban.com/server/kratos-utils/v2/transport/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, "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)
- }
|