An Static For A Goravel Extend Package
将public目录下的文件挂载至应用根路径
This is a directory standard, but you can change it if you like.
Directory | Action |
---|---|
config | Store the config files |
middleware | Store the middleware files |
- Add package
go get -u github.com/hongyukeji/goravel-static
- Use
2.1注册服务和2.2中间件任选一种即可
- 2.1:Register service provider
// config/app.go
static "github.com/hongyukeji/goravel-static"
"providers": []foundation.ServiceProvider{
...
&static.ServiceProvider{},
}
- 2.2:Use middleware
// app/http/kernel.go
import staticmiddleware "github.com/hongyukeji/goravel-static/middleware"
func (kernel Kernel) Middleware() []http.Middleware {
return []http.Middleware{
staticmiddleware.Static(), // add static middleware
}
}
- Publish Configuration
go run . artisan vendor:publish --package=github.com/hongyukeji/goravel-static
- Testing
访问格式:[你的应用网址]/[public目录下的文件名]
例如:http://127.0.0.1:3000/logo.png
The console will print file
.