Skip to content

lu static file serving middleware, based on fasthttp.FS.

License

Notifications You must be signed in to change notification settings

lugolang/static

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

static

Build Status Coverage Status Go Report Card

lu static file serving middleware, based on fasthttp.FS.

example

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

fs.Root string

  • 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.

fs.IndexNames []string

  • 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

About

lu static file serving middleware, based on fasthttp.FS.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages