12345678910111213141516171819202122232425262728293031323334 |
- package router
- import (
- "context"
- "github.com/gogf/gf/v2/frame/g"
- "github.com/gogf/gf/v2/net/ghttp"
- )
- // GContext 网关上下文
- type GContext struct {
- UserId string // 上下文用户信息
- SessData g.Map // 当前Session管理对象
- RouterRule *Router // 路由校验规则
- ServerAddr string // 服务地址
- }
- const GContextKey = "jyCtx"
- // UpdateGContext 更新上下文GContext
- func UpdateGContext(r *ghttp.Request, GCtx *GContext) {
- r.SetCtxVar(GContextKey, GCtx)
- }
- // GetGContext 获取上下文GContext
- func GetGContext(ctx context.Context) *GContext {
- value := ctx.Value(GContextKey)
- if value == nil {
- return nil
- }
- if GCtx, ok := value.(*GContext); ok {
- return GCtx
- }
- return nil
- }
|