2021-01-01 20:49:09 +08:00
|
|
|
package rpcutils
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
2022-09-17 15:11:34 +08:00
|
|
|
func IsRest(ctx context.Context) bool {
|
|
|
|
|
if ctx == nil {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
_, ok := ctx.(*PlainContext)
|
|
|
|
|
return ok
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-01 20:49:09 +08:00
|
|
|
type PlainContext struct {
|
|
|
|
|
UserType string
|
|
|
|
|
UserId int64
|
|
|
|
|
|
|
|
|
|
ctx context.Context
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewPlainContext(userType string, userId int64) *PlainContext {
|
|
|
|
|
return &PlainContext{
|
|
|
|
|
UserType: userType,
|
|
|
|
|
UserId: userId,
|
|
|
|
|
ctx: context.Background(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *PlainContext) Deadline() (deadline time.Time, ok bool) {
|
|
|
|
|
return this.ctx.Deadline()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *PlainContext) Done() <-chan struct{} {
|
|
|
|
|
return this.ctx.Done()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *PlainContext) Err() error {
|
|
|
|
|
return this.ctx.Err()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *PlainContext) Value(key interface{}) interface{} {
|
|
|
|
|
return this.ctx.Value(key)
|
|
|
|
|
}
|