package
1.2.0
Repository: https://github.com/save95/go-pkg.git
Documentation: pkg.go.dev

# Functions

CORS 跨域处理 usage: r.Use(middleware.CORS()) r.Use(middleware.CORS( middleware.WithCORSAllowOriginFunc(func(origin string) bool { //return origin == "https://xxxx.com" return true }), middleware.WithCORSAllowHeaders("X-Custom-Key"), middleware.WithCORSExposeHeaders("X-Custom-Key"), middleware.WithCORSMaxAge(24*time.Hour), )).
HttpCache http 响应缓存 usage: r.Use(middleware.HttpCache( middleware.WithHttpCacheDebug(), middleware.WithHttpCacheLogger(global.Log), middleware.WithHttpCacheJWTOption(global.JWTOption(false)), middleware.WithHttpCacheGlobalDuration(5*time.Minute), middleware.WithHttpCacheRedisStore(redis.NewClient(&redis.Options{ Addr: global.Config.HttpCache.Addr, Password: global.Config.HttpCache.Password, DB: global.Config.HttpCache.DB, })), middleware.WithHttpCacheGlobalSkipFields("v"), middleware.WithHttpCacheRouteSkipFiledPolicy("/user/", true), )).
HttpContext 注入自定义上下文 usage: r.Use(middleware.HttpContext()).
HttpLogger http 日志中间件; 如果有其他内置日志,则该中间件不操作;内置日志有: HttpPrinter 等 usage: r.Use(middleware.HttpLogger(middleware.HttpLoggerOption{ Logger: global.Log, OnlyError: global.Config.Log.HttpLogOnlyError, })).
HttpPrinter 打印 http 信息中间件;展示 request / response 等信息 usage: r.Use(middleware.HttpContext(global.Log)) router.Any("/endpoint", middleware.HttpPrinter(global.Log), ping.Controller{}.Endpoint).
JWT jwt 鉴权中间件 Deprecated 请使用 JWTWith 替代.
JWTStatefulWith 有状态的 jwt 鉴权中间件 需要配合 jwt.NewStatefulToken 使用(在用户登录成功后,调用该函数创建token) usage: ra := router.Group( "/user", middleware.JWTStatefulWith( &jwt.Option{ RoleConvert: NewRole, RefreshDuration: 0, // 0-不自动刷新 Secret: []byte(global.Config.App.Secret), }, jwtstore.NewSingleRedisStore(global.SessionStoreClient), // 单地登录 ), middleware.Roles([]types.IRole{global.RoleBroker, global.RoleStar, global.RoleMember}), ).
JWTStatefulWithout 有状态的 jwt 鉴权中间件,仅校验 jwt 是否合法,不校验状态 需要配合 jwt.NewStatefulToken 使用(在用户登录成功后,调用该函数创建token).
JWTWith jwt 鉴权中间件 在用户登录成功后,配合 jwt.NewToken 生成 token.
RESTFul Restful 标准检测解析中间件.
RESTFulWithIgnores 忽略指定 path 的Restful 标准检测解析中间件 一般,用在部分直接下载或浏览器直接访问的接口.
RoleFunc 角色控制器中间件。 如果用户满足指定角色要求,则使用调用 action,并在完成后进入下一个中间件; 如果用户不满足指定角色要求,则直接进入下一个中间件.
RoleFuncAbort 角色控制器独占中间件。 如果用户符合指定角色,则使用调用 action,并在完成后进入下一个中间件; 如果用户不满足指定角色要求,则中断链路,返回 http status 400 错误.
Roles 角色权限中间件.
Session 校验 session keyPairs cookie 键名 secret cookie 存储加密密钥.
SessionWithStore 校验 session keyPairs cookie 键名.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
WithRole 角色权限中间件.
WithXSSDebug 设置调试模式.
WithXSSGlobalFieldPolicy 指定全局字段过滤策略.
WithXSSGlobalPolicy 指定全局过滤策略.
WithXSSGlobalSkipFields 指定全局忽略字段.
WithXSSRouteFieldPolicy 指定路由的字段策略 routeRule 路由规则,如果路由包含该字符串则匹配成功.
WithXSSRoutePolicy 指定路由策略 routeRule 路由规则,如果路由包含该字符串则匹配成功.
XSSFilter XSS 过滤 usage: r.Use(middleware.XSSFilter( //middleware.XSSDebug(), middleware.WithXSSGlobalPolicy(xss.PolicyStrict), middleware.WithXSSGlobalFieldPolicy(xss.PolicyUGC, "content", "details"), middleware.WithXSSGlobalSkipFields("password"), middleware.WithXSSRoutePolicy("admin", xss.PolicyUGC), middleware.WithXSSRoutePolicy("/callback/", xss.PolicyNone), middleware.WithXSSRoutePolicy("/endpoint", xss.PolicyNone), middleware.WithXSSRoutePolicy("/ping", xss.PolicyNone), middleware.WithXSSRouteFieldPolicy("/user/", xss.PolicyUGC, "content"), )).

# Structs

No description provided by the author
No description provided by the author
No description provided by the author