httpx

package
v1.0.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 13, 2023 License: GPL-3.0 Imports: 14 Imported by: 0

README

  • web_context -> log_context -> alarm trace

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultWebServerMiddlewares = []WebHandlerFunc{
	ginInterceptor,
	ginWebHandler(gin.Recovery()),
	recovery,
}

DefaultWebServerMiddlewares 默认的Http Server中间件 其实应该保证TowerLogware 不panic,但是无法保证,多一个recovery来保证业务日志崩溃后依旧有访问日志

View Source
var NoLogParamsRules logParams

NoLogParamsRules 不想打印的路由分组

Functions

func CheckNoLogParams

func CheckNoLogParams(origin string) bool

CheckNoLogParams 判断是否需要打印入参出参日志, 不需要打印返回true

Types

type RouterRegister

type RouterRegister func(*WebServer)

RouterRegister 路由注册者

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 WebHandlerFunc

type WebHandlerFunc func(*WebContext)

WebHandlerFunc http请求的处理者

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) Static

func (wrc *WebRoute) Static(relativePath, root string) WebRouter

Static 静态文件

func (*WebRoute) StaticFS

func (wrc *WebRoute) StaticFS(relativePath string, fs http.FileSystem) WebRouter

StaticFS 静态文件

func (*WebRoute) StaticFile

func (wrc *WebRoute) StaticFile(relativePath, filepath string) WebRouter

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

type WebServer struct {
	// 重写所有的路由相关的方法
	*WebRoute
	// 继承引擎本身的其他方法
	*gin.Engine
}

WebServer 基于http协议的服务 这里的实现是基于gin框架, 封装了gin的所有的方法 gin 的核心是高效路由, 但是gin.Engine和gin.IRouter(s)的高耦合让我们无法复用, gin的作者认为它的路由就是引擎吧

func NewWebServer

func NewWebServer(mode string) *WebServer

NewWebServer 创建WebServer

func (*WebServer) Delims

func (webServer *WebServer) Delims(left, right string) *WebServer

Delims 设置模板的分解符 重写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) RunGrace

func (webServer *WebServer) RunGrace(addr string, timeouts ...time.Duration) error

RunGrace 实现Server接口

func (*WebServer) SecureJsonPrefix

func (webServer *WebServer) SecureJsonPrefix(prefix string) *WebServer

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL