1234567891011121314151617181920212223242526272829303132 |
- 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) *GContext {
- value := ctx.Value(GContextKey)
- if value == nil {
- return nil
- }
- if GCtx, ok := value.(*GContext); ok {
- return GCtx
- }
- return nil
- }
|