lu static file serving middleware, based on fasthttp.FS.
package main
import (
"log"
"github.com/valyala/fasthttp"
"github.com/vincentLiuxiang/lu"
"github.com/lugolang/static"
)
func main() {
app := lu.New()
fs := static.DefaultFS
// fs.Root = "/static/file/path/"
Static := static.New(fs)
app.Get("/static", Static)
server := &fasthttp.Server{
Handler: app.Handler,
Concurrency: 1024 * 1024,
Name: "lu",
MaxConnsPerIP: 50,
}
if err := server.ListenAndServe(":8080"); err != nil {
log.Fatalf("error in lu server: %s", err)
}
}
the config of fs is totally same with fasthttp.FS
-
The default value of fs.Root is ".", it means you should put your static file (html/css/js etc.) to the directory where your go program starts.
-
However you can custom it in your way.
- The default value is []string{"index.html"}
- It specify the index file. For example, when you access to http://xxxxxx:xxx/home/ , static will search the directory
fs.Root + /home/
to find the files in fs.IndexNames , and response to the client when find one. - if no file is found , static will call next(nil) to pass the request to next non-error-middleware