代码拉取完成,页面将自动刷新
package router
import (
"io/fs"
"gitee.com/zengxinqian/hall"
)
// Group returns a new group.
// Path autocorrection, including trailing slashes, is enabled by default.
func (g *Group[Req, Resp]) Group(path string) *Group[Req, Resp] {
validatePath(path)
if len(g.prefix) > 0 && path == "/" {
return g
}
return g.router.Group(g.prefix + path)
}
// GET is a shortcut for group.Handle(hall.MethodGet, path, handler)
func (g *Group[Req, Resp]) GET(path string, handler hall.Handler[Req, Resp]) {
validatePath(path)
g.router.GET(g.prefix+path, handler)
}
// HEAD is a shortcut for group.Handle(hall.MethodHead, path, handler)
func (g *Group[Req, Resp]) HEAD(path string, handler hall.Handler[Req, Resp]) {
validatePath(path)
g.router.HEAD(g.prefix+path, handler)
}
// POST is a shortcut for group.Handle(hall.MethodPost, path, handler)
func (g *Group[Req, Resp]) POST(path string, handler hall.Handler[Req, Resp]) {
validatePath(path)
g.router.POST(g.prefix+path, handler)
}
// PUT is a shortcut for group.Handle(hall.MethodPut, path, handler)
func (g *Group[Req, Resp]) PUT(path string, handler hall.Handler[Req, Resp]) {
validatePath(path)
g.router.PUT(g.prefix+path, handler)
}
// PATCH is a shortcut for group.Handle(hall.MethodPatch, path, handler)
func (g *Group[Req, Resp]) PATCH(path string, handler hall.Handler[Req, Resp]) {
validatePath(path)
g.router.PATCH(g.prefix+path, handler)
}
// DELETE is a shortcut for group.Handle(hall.MethodDelete, path, handler)
func (g *Group[Req, Resp]) DELETE(path string, handler hall.Handler[Req, Resp]) {
validatePath(path)
g.router.DELETE(g.prefix+path, handler)
}
// CONNECT is a shortcut for group.Handle(hall.MethodOptions, path, handler)
func (g *Group[Req, Resp]) CONNECT(path string, handler hall.Handler[Req, Resp]) {
validatePath(path)
g.router.CONNECT(g.prefix+path, handler)
}
// OPTIONS is a shortcut for group.Handle(hall.MethodOptions, path, handler)
func (g *Group[Req, Resp]) OPTIONS(path string, handler hall.Handler[Req, Resp]) {
validatePath(path)
g.router.OPTIONS(g.prefix+path, handler)
}
// TRACE is a shortcut for group.Handle(hall.MethodOptions, path, handler)
func (g *Group[Req, Resp]) TRACE(path string, handler hall.Handler[Req, Resp]) {
validatePath(path)
g.router.TRACE(g.prefix+path, handler)
}
// ANY is a shortcut for group.Handle(router.MethodWild, path, handler)
//
// WARNING: Use only for routes where the request method is not important
func (g *Group[Req, Resp]) ANY(path string, handler hall.Handler[Req, Resp]) {
validatePath(path)
g.router.ANY(g.prefix+path, handler)
}
func (g *Group[Req, Resp]) GETFunc(uri string, handlerFunc hall.HandlerFunc[Req, Resp], codecs ...interface{}) {
g.GET(uri, g.router.Wrap(handlerFunc, codecs...))
}
func (g *Group[Req, Resp]) POSTFunc(uri string, handlerFunc hall.HandlerFunc[Req, Resp], codecs ...interface{}) {
g.POST(uri, g.router.Wrap(handlerFunc, codecs...))
}
func (g *Group[Req, Resp]) PUTFunc(uri string, handlerFunc hall.HandlerFunc[Req, Resp], codecs ...interface{}) {
g.PUT(uri, g.router.Wrap(handlerFunc, codecs...))
}
func (g *Group[Req, Resp]) DELETEFunc(uri string, handlerFunc hall.HandlerFunc[Req, Resp], codecs ...interface{}) {
g.DELETE(uri, g.router.Wrap(handlerFunc, codecs...))
}
func (g *Group[Req, Resp]) TRACEFunc(uri string, handlerFunc hall.HandlerFunc[Req, Resp], codecs ...interface{}) {
g.TRACE(uri, g.router.Wrap(handlerFunc, codecs...))
}
func (g *Group[Req, Resp]) OPTIONSFunc(uri string, handlerFunc hall.HandlerFunc[Req, Resp], codecs ...interface{}) {
g.OPTIONS(uri, g.router.Wrap(handlerFunc, codecs...))
}
func (g *Group[Req, Resp]) HEADFunc(uri string, handlerFunc hall.HandlerFunc[Req, Resp], codecs ...interface{}) {
g.HEAD(uri, g.router.Wrap(handlerFunc, codecs...))
}
func (g *Group[Req, Resp]) PATCHFunc(uri string, handlerFunc hall.HandlerFunc[Req, Resp], codecs ...interface{}) {
g.PATCH(uri, g.router.Wrap(handlerFunc, codecs...))
}
func (g *Group[Req, Resp]) ANYFunc(uri string, handlerFunc hall.HandlerFunc[Req, Resp], codecs ...interface{}) {
g.ANY(uri, g.router.Wrap(handlerFunc, codecs...))
}
// ServeFiles serves files from the given file system root path.
// The path must end with "/{filepath:*}", files are then served from the local
// path /defined/root/dir/{filepath:*}.
// For example if root is "/etc" and {filepath:*} is "passwd", the local file
// "/etc/passwd" would be served.
// Internally a httpal.FSHandler is used, therefore http.NotFound is used instead
// Use:
//
// router.ServeFiles("/src/{filepath:*}", "./")
func (g *Group[Req, Resp]) ServeFiles(path string, rootPath string) {
validatePath(path)
g.router.ServeFiles(g.prefix+path, rootPath)
}
// ServeFS serves files from the given file system.
// The path must end with "/{filepath:*}", files are then served from the local
// path /defined/root/dir/{filepath:*}.
// For example if root is "/etc" and {filepath:*} is "passwd", the local file
// "/etc/passwd" would be served.
// Internally a httpal.FSHandler is used, therefore http.NotFound is used instead
// Use:
//
// router.ServeFS("/src/{filepath:*}", myFilesystem)
func (g *Group[Req, Resp]) ServeFS(path string, filesystem fs.FS) {
validatePath(path)
g.router.ServeFS(g.prefix+path, filesystem)
}
// ServeFilesCustom serves files from the given file system settings.
// The path must end with "/{filepath:*}", files are then served from the local
// path /defined/root/dir/{filepath:*}.
// For example if root is "/etc" and {filepath:*} is "passwd", the local file
// "/etc/passwd" would be served.
// Internally a httpal.FSHandler is used, therefore http.NotFound is used instead
// of the Router's NotFound handler.
// Use:
//
// router.ServeFilesCustom("/src/{filepath:*}", *customFS)
func (g *Group[Req, Resp]) ServeFilesCustom(path string, fs fs.FS) {
validatePath(path)
g.router.ServeFilesCustom(g.prefix+path, fs)
}
// Handle registers a new request handler with the given path and method.
//
// For GET, POST, PUT, PATCH and DELETE requests the respective shortcut
// functions can be used.
//
// This function is intended for bulk loading and to allow the usage of less
// frequently used, non-standardized or custom methods (e.g. for internal
// communication with a proxy).
func (g *Group[Req, Resp]) Handle(method, path string, handler hall.Handler[Req, Resp]) {
validatePath(path)
g.router.Handle(method, g.prefix+path, handler)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。