Compare commits

..

2 commits

Author SHA1 Message Date
wjqserver
9ec1d1f2c6 update deps 2025-06-22 18:12:29 +08:00
wjqserver
6c6a5a99b1 add slash settings && StaticFS 2025-06-22 18:06:19 +08:00
3 changed files with 46 additions and 1 deletions

View file

@ -202,6 +202,21 @@ func (engine *Engine) SetTLSServerConfigurator(fn func(*http.Server)) {
engine.TLSServerConfigurator = fn engine.TLSServerConfigurator = fn
} }
// 是否开启末尾slash重定向
func (engine *Engine) SetRedirectTrailingSlash(enable bool) {
engine.RedirectTrailingSlash = enable
}
// 是否开启固定路径重定向
func (engine *Engine) SetRedirectFixedPath(enable bool) {
engine.RedirectFixedPath = enable
}
// 是否开启MethodNotAllowed
func (engine *Engine) SetHandleMethodNotAllowed(enable bool) {
engine.HandleMethodNotAllowed = enable
}
// SetLogger传入实例 // SetLogger传入实例
func (engine *Engine) SetLogger(logger *reco.Logger) { func (engine *Engine) SetLogger(logger *reco.Logger) {
engine.LogReco = logger engine.LogReco = logger
@ -934,6 +949,34 @@ func (group *RouterGroup) StaticFile(relativePath, filePath string) {
group.OPTIONS(relativePath, FileHandle) group.OPTIONS(relativePath, FileHandle)
} }
// StaticFS
func (engine *Engine) StaticFS(relativePath string, fs http.FileSystem) {
// 清理路径
relativePath = path.Clean(relativePath)
// 确保相对路径以 '/' 结尾,以便 FileServer 正确处理子路径
if !strings.HasSuffix(relativePath, "/") {
relativePath += "/"
}
// 注册一个捕获所有路径的路由,使用 FileServer 处理器
engine.ANY(relativePath+"*filepath", FileServer(fs))
}
// Group的StaticFS
func (group *RouterGroup) StaticFS(relativePath string, fs http.FileSystem) {
// 清理路径
relativePath = path.Clean(relativePath)
// 确保相对路径以 '/' 结尾,以便 FileServer 正确处理子路径
if !strings.HasSuffix(relativePath, "/") {
relativePath += "/"
}
// 注册一个捕获所有路径的路由,使用 FileServer 处理器
group.ANY(relativePath+"*filepath", FileServer(fs))
}
// 维护一个Methods列表 // 维护一个Methods列表
var ( var (
MethodGet = "GET" MethodGet = "GET"

2
go.mod
View file

@ -4,7 +4,7 @@ go 1.24.4
require ( require (
github.com/WJQSERVER-STUDIO/go-utils/copyb v0.0.4 github.com/WJQSERVER-STUDIO/go-utils/copyb v0.0.4
github.com/WJQSERVER-STUDIO/httpc v0.7.0 github.com/WJQSERVER-STUDIO/httpc v0.7.1
github.com/fenthope/reco v0.0.3 github.com/fenthope/reco v0.0.3
github.com/go-json-experiment/json v0.0.0-20250517221953-25912455fbc8 github.com/go-json-experiment/json v0.0.0-20250517221953-25912455fbc8
) )

2
go.sum
View file

@ -2,6 +2,8 @@ github.com/WJQSERVER-STUDIO/go-utils/copyb v0.0.4 h1:JLtFd00AdFg/TP+dtvIzLkdHwKU
github.com/WJQSERVER-STUDIO/go-utils/copyb v0.0.4/go.mod h1:FZ6XE+4TKy4MOfX1xWKe6Rwsg0ucYFCdNh1KLvyKTfc= github.com/WJQSERVER-STUDIO/go-utils/copyb v0.0.4/go.mod h1:FZ6XE+4TKy4MOfX1xWKe6Rwsg0ucYFCdNh1KLvyKTfc=
github.com/WJQSERVER-STUDIO/httpc v0.7.0 h1:iHhqlxppJBjlmvsIjvLZKRbWXqSdbeSGGofjHGmqGJc= github.com/WJQSERVER-STUDIO/httpc v0.7.0 h1:iHhqlxppJBjlmvsIjvLZKRbWXqSdbeSGGofjHGmqGJc=
github.com/WJQSERVER-STUDIO/httpc v0.7.0/go.mod h1:M7KNUZjjhCkzzcg9lBPs9YfkImI+7vqjAyjdA19+joE= github.com/WJQSERVER-STUDIO/httpc v0.7.0/go.mod h1:M7KNUZjjhCkzzcg9lBPs9YfkImI+7vqjAyjdA19+joE=
github.com/WJQSERVER-STUDIO/httpc v0.7.1 h1:D3NlfY52pwKIOSzkdRrLinUynyKELrcPZEO8QjlBq2M=
github.com/WJQSERVER-STUDIO/httpc v0.7.1/go.mod h1:M7KNUZjjhCkzzcg9lBPs9YfkImI+7vqjAyjdA19+joE=
github.com/fenthope/reco v0.0.3 h1:RmnQ0D9a8PWtwOODawitTe4BztTnS9wYwrDbipISNq4= github.com/fenthope/reco v0.0.3 h1:RmnQ0D9a8PWtwOODawitTe4BztTnS9wYwrDbipISNq4=
github.com/fenthope/reco v0.0.3/go.mod h1:mDkGLHte5udWTIcjQTxrABRcf56SSdxBOCLgrRDwI/Y= github.com/fenthope/reco v0.0.3/go.mod h1:mDkGLHte5udWTIcjQTxrABRcf56SSdxBOCLgrRDwI/Y=
github.com/go-json-experiment/json v0.0.0-20250517221953-25912455fbc8 h1:o8UqXPI6SVwQt04RGsqKp3qqmbOfTNMqDrWsc4O47kk= github.com/go-json-experiment/json v0.0.0-20250517221953-25912455fbc8 h1:o8UqXPI6SVwQt04RGsqKp3qqmbOfTNMqDrWsc4O47kk=