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