package router import ( "context" "github.com/gogf/gf/v2/net/ghttp" ) // GContext 网关上下文 type GContext struct { 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) (gCtx *GContext) { gCtx = &GContext{ RouterRule: &Router{}, } value := ctx.Value(GContextKey) if value == nil { return } gCtx, _ = value.(*GContext) return }