Documentation
¶
Index ¶
- func HashPasswordByBcrypt(password []byte) ([]byte, error)
- func ShowLogo()
- func VerifyPasswordByBcrypt(hashedPassword, originalPassword []byte) bool
- type Context
- func (own *Context) AddError(err error)
- func (own *Context) BindJSON(data any) error
- func (own *Context) BindXML(obj any) error
- func (own *Context) GetClientIP() string
- func (own *Context) GetContentType() string
- func (own *Context) GetContextValue(key any) (any, bool)
- func (own *Context) GetCookieValue(name string) (string, error)
- func (own *Context) GetErrors() []error
- func (own *Context) GetFormFile(filename string) (multipart.File, *multipart.FileHeader, error)
- func (own *Context) GetFormValue(key string) string
- func (own *Context) GetJWTClaims() (any, bool)
- func (own *Context) GetMultipartFormValue(key string) string
- func (own *Context) GetPathValue(name string) string
- func (own *Context) GetPostFormValue(key string) string
- func (own *Context) GetQueryValue(key string) string
- func (own *Context) GetRemoteIP() string
- func (own *Context) GetRequestBody() ([]byte, error)
- func (own *Context) GetRequestHeader(key string) string
- func (own *Context) GetResponseHeader(key string) string
- func (own *Context) GetServiceName() string
- func (own *Context) GetStartTime() time.Time
- func (own *Context) GetStatusCode() int
- func (own *Context) GetURL() *url.URL
- func (own *Context) IsWebsocket() bool
- func (own *Context) ResponseBytes(code int, data []byte) error
- func (own *Context) ResponseError(code int, error string)
- func (own *Context) ResponseFileAttachment(filepath string)
- func (own *Context) ResponseFileAttachmentFromFS(filepath string, fs http.FileSystem)
- func (own *Context) ResponseFileContent(filepath string)
- func (own *Context) ResponseFileContentFromFS(filepath string, fs http.FileSystem)
- func (own *Context) ResponseHTML(filename, tmplName string, data any) error
- func (own *Context) ResponseJSON(code int, data any) error
- func (own *Context) ResponsePlain(code int, data string) error
- func (own *Context) ResponseRedirect(code int, location string)
- func (own *Context) ResponseSSEvent(event func(ctx context.Context) <-chan *sse.Message) error
- func (own *Context) ResponseXML(code int, data any) error
- func (own *Context) SaveUploadedFile(file *multipart.FileHeader, target string, perm ...fs.FileMode) error
- func (own *Context) SetCookie(cookie *http.Cookie)
- func (own *Context) SetCookieData(name, value string, maxAge int, path, domain string, secure, httpOnly bool)
- func (own *Context) SetJWTClaims(claims any)
- func (own *Context) SetRequestHeader(key, value string)
- func (own *Context) SetResponseHeader(key, value string)
- func (own *Context) SetSameSite(sameSite http.SameSite)
- func (own *Context) SetStatusCode(code int)
- func (own *Context) WithContext(ctx context.Context) *Context
- type Engine
- func (own *Engine) AddURLBlacklist(urls ...string)
- func (own Engine) DELETE(pattern string, handle HandleFunc, tags ...string)
- func (own Engine) GET(pattern string, handle HandleFunc, tags ...string)
- func (own *Engine) GetAllHandlerCollectors() []*collector.Collector
- func (own *Engine) GetHTTPHandler() http.Handler
- func (own *Engine) GetHandler(method, pattern string) (Handler, bool)
- func (own Engine) Group(prefix string) Group
- func (own Engine) HEAD(pattern string, handle HandleFunc, tags ...string)
- func (own Engine) OPTIONS(pattern string, handle HandleFunc, tags ...string)
- func (own Engine) PATCH(pattern string, handle HandleFunc, tags ...string)
- func (own Engine) POST(pattern string, handle HandleFunc, tags ...string)
- func (own Engine) PUT(pattern string, handle HandleFunc, tags ...string)
- func (own *Engine) Run(addr string) error
- func (own *Engine) RunFd(fd int) (err error)
- func (own *Engine) RunListener(listener net.Listener) (err error)
- func (own *Engine) RunTLS(addr, certFile, keyFile string) error
- func (own *Engine) RunUnix(file string) error
- func (own *Engine) ServeHTTP(resp http.ResponseWriter, req *http.Request)
- func (own Engine) SetStatic(relativePath, rootPath string, tags ...string)
- func (own Engine) SetStaticFS(relativePath string, fs http.FileSystem, tags ...string)
- func (own Engine) UseMiddlewares(middlewares ...MiddlewareFunc)
- func (own *Engine) WaitSignalAndShutdown(timeout time.Duration, doBeforeShutdown func() error) error
- type Group
- type HandleFunc
- type Handler
- type JSON
- type MiddlewareFunc
- type Router
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HashPasswordByBcrypt ¶
HashPasswordByBcrypt 加密密码
func VerifyPasswordByBcrypt ¶
VerifyPasswordByBcrypt 验证密码
Types ¶
type Context ¶
type Context struct {
Request *http.Request // 原始请求
Response response.Writer // 原始响应
// contains filtered or unexported fields
}
Context 定义上下文的结构
func (*Context) GetContextValue ¶
GetContextValue 获取上下文附带的键值对参数
func (*Context) GetCookieValue ¶
GetCookieValue 获取 cookie 值
func (*Context) GetFormFile ¶
GetFormFile 获取上传的文件信息
func (*Context) GetFormValue ¶
GetFormValue 获取表单信息, 可查询 URL 参数和 x-www-form-urlencoded 格式的 body
func (*Context) GetJWTClaims ¶
GetJWTClaims 获取 JWT 声明
func (*Context) GetMultipartFormValue ¶
GetMultipartFormValue 仅支持查询 multipart/form-data 格式的 body
func (*Context) GetPathValue ¶
GetPathValue 获取动态路由参数
func (*Context) GetPostFormValue ¶
GetPostFormValue 仅支持查询 x-www-form-urlencoded 格式的 body
func (*Context) GetQueryValue ¶
GetQueryValue 获取查询参数
func (*Context) GetRequestBody ¶
GetRequestBody 获取请求体数据
func (*Context) GetRequestHeader ¶
GetRequestHeader 获取请求头字段信息
func (*Context) GetResponseHeader ¶
GetResponseHeader 获取响应头字段信息
func (*Context) ResponseBytes ¶
ResponseBytes 响应字节数据
func (*Context) ResponseError ¶
ResponseError 响应错误信息
func (*Context) ResponseFileAttachment ¶
ResponseFileAttachment 响应文件附件(下载文件)
func (*Context) ResponseFileAttachmentFromFS ¶
func (own *Context) ResponseFileAttachmentFromFS(filepath string, fs http.FileSystem)
ResponseFileAttachmentFromFS 从指定的文件系统响应文件附件(下载文件)
func (*Context) ResponseFileContent ¶
ResponseFileContent 响应文件内容(页面显示)
func (*Context) ResponseFileContentFromFS ¶
func (own *Context) ResponseFileContentFromFS(filepath string, fs http.FileSystem)
ResponseFileContentFromFS 从指定的文件系统响应文件内容(页面显示)
func (*Context) ResponseHTML ¶
ResponseHTML 响应 HTML 内容
func (*Context) ResponseJSON ¶
ResponseJSON 响应 JSON 格式的数据
func (*Context) ResponsePlain ¶
ResponsePlain 响应纯文本内容
func (*Context) ResponseRedirect ¶
ResponseRedirect 响应重定向
func (*Context) ResponseSSEvent ¶
ResponseSSEvent 发起 SSE 事件响应
func (*Context) ResponseXML ¶
ResponseXML 响应 XML 格式的数据
func (*Context) SaveUploadedFile ¶
func (own *Context) SaveUploadedFile(file *multipart.FileHeader, target string, perm ...fs.FileMode) error
SaveUploadedFile 将上传的表单文件保存到指定的路径
func (*Context) SetCookieData ¶
func (own *Context) SetCookieData(name, value string, maxAge int, path, domain string, secure, httpOnly bool)
SetCookieData 设置 cookie
func (*Context) SetJWTClaims ¶
SetJWTClaims 设置 JWT 声明信息
func (*Context) SetRequestHeader ¶
SetRequestHeader 设置请求头
func (*Context) SetResponseHeader ¶
SetResponseHeader 设置响应头
func (*Context) SetSameSite ¶
SetSameSite 设置 cookie
type Engine ¶
type Engine struct {
// Name 引擎名称
Name string
// MaxMultipartMemory 解析 multipart/form-data 多部分表单时最大使用的内存
MaxMultipartMemory int64
// UseH2C 是否使用 HTTP2
UseH2C bool
// contains filtered or unexported fields
}
Engine 定义引擎的结构
func (*Engine) AddURLBlacklist ¶
AddURLBlacklist 添加路由黑名单
func (Engine) DELETE ¶
func (own Engine) DELETE(pattern string, handle HandleFunc, tags ...string)
DELETE 处理 DELETE 请求
func (Engine) GET ¶
func (own Engine) GET(pattern string, handle HandleFunc, tags ...string)
GET 处理 GET 请求
func (*Engine) GetAllHandlerCollectors ¶
GetAllHandlerCollectors 获取所有处理器的指标采集器
func (*Engine) GetHTTPHandler ¶
GetHTTPHandler 获取 http.Handler
func (*Engine) GetHandler ¶
GetHandler 获取指定的处理器
func (Engine) HEAD ¶
func (own Engine) HEAD(pattern string, handle HandleFunc, tags ...string)
HEAD 处理 HEAD 请求
func (Engine) OPTIONS ¶
func (own Engine) OPTIONS(pattern string, handle HandleFunc, tags ...string)
OPTIONS 处理 OPTIONS 请求
func (Engine) PATCH ¶
func (own Engine) PATCH(pattern string, handle HandleFunc, tags ...string)
PATCH 处理 PATCH 请求
func (Engine) POST ¶
func (own Engine) POST(pattern string, handle HandleFunc, tags ...string)
POST 处理 POST 请求
func (Engine) PUT ¶
func (own Engine) PUT(pattern string, handle HandleFunc, tags ...string)
PUT 处理 PUT 请求
func (*Engine) RunListener ¶
RunListener 通过指定的网络监听和服务 HTTP 请求
func (*Engine) ServeHTTP ¶
func (own *Engine) ServeHTTP(resp http.ResponseWriter, req *http.Request)
ServeHTTP 继承 http.Handler 接口
func (Engine) SetStatic ¶
SetStatic 设置静态文件服务
参数:
- relativePath:URI 中的相对路径
- rootPath:静态文件服务的根目录
- tags:第1个参数为路由名称,后续参数为路由标签
注意:
- 在处理 index.html 这类默认索引文件时,会尝试重定向到目录路径
func (Engine) SetStaticFS ¶
func (own Engine) SetStaticFS(relativePath string, fs http.FileSystem, tags ...string)
SetStaticFS 设置静态文件服务
参数:
- relativePath:URI 中的相对路径
- fs:http.FileSystem 文件系统
- tags:第1个参数为路由名称,后续参数为路由标签
注意:
- 在处理 index.html 这类默认索引文件时,会尝试重定向到目录路径
func (Engine) UseMiddlewares ¶
func (own Engine) UseMiddlewares(middlewares ...MiddlewareFunc)
UseMiddlewareFuncs 使用路由组中间件处理函数
type Group ¶
type Group interface {
// Group 路由分组
Group(prefix string) Group
// UseMiddlewares 使用路由中间件函数
UseMiddlewares(middlewares ...MiddlewareFunc)
// GET 处理 GET 请求
GET(pattern string, handle HandleFunc, tags ...string)
// PUT 处理 PUT 请求
PUT(pattern string, handle HandleFunc, tags ...string)
// POST 处理 POST 请求
POST(pattern string, handle HandleFunc, tags ...string)
// HEAD 处理 HEAD 请求
HEAD(pattern string, handle HandleFunc, tags ...string)
// PATCH 处理 PATCH 请求
PATCH(pattern string, handle HandleFunc, tags ...string)
// DELETE 处理 DELETE 请求
DELETE(pattern string, handle HandleFunc, tags ...string)
// OPTIONS 处理 OPTIONS 请求
OPTIONS(pattern string, handle HandleFunc, tags ...string)
// SetStatic 设置静态文件服务
SetStatic(relativePath, rootPath string, tags ...string)
// SetStaticFS 设置静态文件服务
SetStaticFS(relativePath string, fs http.FileSystem, tags ...string)
}
Group 定义路由组的接口类型
type Handler ¶
type Handler interface {
// ServeHTTP 处理 HTTP 请求
ServeHTTP(ctx *Context)
// Enable 启用处理器
Enable()
/*Disable 禁用指定路由
- 禁用指定路由后,也不会调用该路由上的任一中间件,且响应状态码为 423
*/
Disable()
// IsEnabled 是否启用该处理器
IsEnabled() bool
// GetCollector 获取指标采集器
GetCollector() *collector.Collector
}
Handler 定义处理器的接口类型
type MiddlewareFunc ¶
type MiddlewareFunc func(next HandleFunc) HandleFunc
MiddlewareFunc 定义中间件函数的类型
type Router ¶
type Router interface {
// ServeHTTP 实现 http.Handler 接口
ServeHTTP(resp http.ResponseWriter, req *http.Request)
// Insert 插入路由
Insert(method, pattern string, handler Handler)
// Search 搜索路由
Search(method, path string) (Handler, map[string]string, bool)
// AddBlacklist 添加路由黑名单
AddBlacklist(urls ...string)
}
Router 定义路由器的接口类型