Documentation ¶
Index ¶
- Variables
- func CheckNoLogParams(origin string) bool
- type RouterRegister
- type WebContext
- type WebHandlerFunc
- type WebRoute
- func (wrc *WebRoute) Any(pattern string, handlers ...WebHandlerFunc) WebRouter
- func (wrc *WebRoute) DELETE(pattern string, handlers ...WebHandlerFunc) WebRouter
- func (wrc *WebRoute) GET(pattern string, handlers ...WebHandlerFunc) WebRouter
- func (wrc *WebRoute) Group(pattern string, handlers ...WebHandlerFunc) WebRouter
- func (wrc *WebRoute) HEAD(pattern string, handlers ...WebHandlerFunc) WebRouter
- func (wrc *WebRoute) OPTIONS(pattern string, handlers ...WebHandlerFunc) WebRouter
- func (wrc *WebRoute) PATCH(pattern string, handlers ...WebHandlerFunc) WebRouter
- func (wrc *WebRoute) POST(pattern string, handlers ...WebHandlerFunc) WebRouter
- func (wrc *WebRoute) PUT(pattern string, handlers ...WebHandlerFunc) WebRouter
- func (wrc *WebRoute) Static(relativePath, root string) WebRouter
- func (wrc *WebRoute) StaticFS(relativePath string, fs http.FileSystem) WebRouter
- func (wrc *WebRoute) StaticFile(relativePath, filepath string) WebRouter
- func (wrc *WebRoute) Use(middleware ...WebHandlerFunc) WebRouter
- type WebRouter
- type WebServer
- func (webServer *WebServer) Delims(left, right string) *WebServer
- func (webServer *WebServer) HandleContext(wc *WebContext)
- func (webServer *WebServer) NoMethod(handlers ...WebHandlerFunc)
- func (webServer *WebServer) NoRoute(handlers ...WebHandlerFunc)
- func (webServer *WebServer) Register(rr RouterRegister)
- func (webServer *WebServer) RunGrace(addr string, timeouts ...time.Duration) error
- func (webServer *WebServer) SecureJsonPrefix(prefix string) *WebServer
- func (webServer *WebServer) Use(middleware ...WebHandlerFunc) WebRouter
Constants ¶
This section is empty.
Variables ¶
var DefaultWebServerMiddlewares = []WebHandlerFunc{ ginInterceptor, ginWebHandler(gin.Recovery()), recovery, }
DefaultWebServerMiddlewares 默认的Http Server中间件 其实应该保证TowerLogware 不panic,但是无法保证,多一个recovery来保证业务日志崩溃后依旧有访问日志
var NoLogParamsRules logParams
NoLogParamsRules 不想打印的路由分组
Functions ¶
func CheckNoLogParams ¶
CheckNoLogParams 判断是否需要打印入参出参日志, 不需要打印返回true
Types ¶
type WebContext ¶
type WebContext struct { *gin.Context *logx.LogContext *tracex.TraceContext *alarmx.AlarmContext }
WebContext http 的context WebContext 继承了 gin.Context, 并且扩展了日志功能
func NewWebContext ¶
func NewWebContext(ginContext *gin.Context) *WebContext
NewWebContext 创建 http contextx
type WebRoute ¶
type WebRoute struct { RouterGroup *gin.RouterGroup // contains filtered or unexported fields }
WebRoute struct 它实现了gin.IRoutes, gin.IRoute
func (*WebRoute) Any ¶
func (wrc *WebRoute) Any(pattern string, handlers ...WebHandlerFunc) WebRouter
Any 注册所有的方法
func (*WebRoute) DELETE ¶
func (wrc *WebRoute) DELETE(pattern string, handlers ...WebHandlerFunc) WebRouter
DELETE 注册DELETE方法
func (*WebRoute) GET ¶
func (wrc *WebRoute) GET(pattern string, handlers ...WebHandlerFunc) WebRouter
GET 注册GET方法
func (*WebRoute) Group ¶
func (wrc *WebRoute) Group(pattern string, handlers ...WebHandlerFunc) WebRouter
Group creates a new web router group
func (*WebRoute) HEAD ¶
func (wrc *WebRoute) HEAD(pattern string, handlers ...WebHandlerFunc) WebRouter
HEAD 注册HEAD方法
func (*WebRoute) OPTIONS ¶
func (wrc *WebRoute) OPTIONS(pattern string, handlers ...WebHandlerFunc) WebRouter
OPTIONS 注册OPTIONS方法
func (*WebRoute) PATCH ¶
func (wrc *WebRoute) PATCH(pattern string, handlers ...WebHandlerFunc) WebRouter
PATCH 注册PATCH方法
func (*WebRoute) POST ¶
func (wrc *WebRoute) POST(pattern string, handlers ...WebHandlerFunc) WebRouter
POST 注册POST方法
func (*WebRoute) PUT ¶
func (wrc *WebRoute) PUT(pattern string, handlers ...WebHandlerFunc) WebRouter
PUT 注册PUT方法
func (*WebRoute) StaticFS ¶
func (wrc *WebRoute) StaticFS(relativePath string, fs http.FileSystem) WebRouter
StaticFS 静态文件
func (*WebRoute) StaticFile ¶
StaticFile 静态文件
func (*WebRoute) Use ¶
func (wrc *WebRoute) Use(middleware ...WebHandlerFunc) WebRouter
Use attachs a global middleware to the router. ie. the middleware attached though Use() will be included in the handlers chain for every single request. Even 404, 405, static files... For example, this is the right place for a logger or error management middleware.
type WebRouter ¶
type WebRouter interface { // Group gin.IRoute.Group Group(string, ...WebHandlerFunc) WebRouter // Use gin.IRoutes.Use Use(...WebHandlerFunc) WebRouter Any(pattern string, handlers ...WebHandlerFunc) WebRouter GET(pattern string, handlers ...WebHandlerFunc) WebRouter POST(pattern string, handlers ...WebHandlerFunc) WebRouter DELETE(pattern string, handlers ...WebHandlerFunc) WebRouter PATCH(pattern string, handlers ...WebHandlerFunc) WebRouter PUT(pattern string, handlers ...WebHandlerFunc) WebRouter OPTIONS(pattern string, handlers ...WebHandlerFunc) WebRouter HEAD(pattern string, handlers ...WebHandlerFunc) WebRouter StaticFile(relativePath, filepath string) WebRouter Static(relativePath, root string) WebRouter StaticFS(relativePath string, fs http.FileSystem) WebRouter }
WebRouter interface WebRequest Router 它合并了 gin.IRoute 和 gin.IRoutes
type WebServer ¶
WebServer 基于http协议的服务 这里的实现是基于gin框架, 封装了gin的所有的方法 gin 的核心是高效路由, 但是gin.Engine和gin.IRouter(s)的高耦合让我们无法复用, gin的作者认为它的路由就是引擎吧
func (*WebServer) HandleContext ¶
func (webServer *WebServer) HandleContext(wc *WebContext)
HandleContext re-enter a contextx that has been rewritten. This can be done by setting c.Request.URL.Path to your new target. Disclaimer: You can loop yourself to death with this, use wisely.
func (*WebServer) NoMethod ¶
func (webServer *WebServer) NoMethod(handlers ...WebHandlerFunc)
NoMethod sets the handlers called when... TODO. 重写gin方法
func (*WebServer) NoRoute ¶
func (webServer *WebServer) NoRoute(handlers ...WebHandlerFunc)
NoRoute adds handlers for NoRoute. It return a 404 code by default. 重写gin方法
func (*WebServer) Register ¶
func (webServer *WebServer) Register(rr RouterRegister)
RegisterRouter 注册路由
func (*WebServer) SecureJsonPrefix ¶
SecureJsonPrefix sets the secureJsonPrefix used in Context.SecureJSON. 重写gin方法
func (*WebServer) Use ¶
func (webServer *WebServer) Use(middleware ...WebHandlerFunc) WebRouter
Use adds middleware to the group, see example code in github.