This package provides basic file server functionality with:
- In memory caching with TTL and limits (like maximal cached files count and maximal file size)
- Overridable error handlers
- "Index" file serving (like
index
nginx directive) - Redirection to the "parent" directory, when index file requested
- "Allowed methods" list
Most use-case is SPA assets serving.
To install package, use go get
:
$ go get github.com/avto-dev/go-simple-fileserver
fs, err := fileserver.NewFileServer(fileserver.Settings{
FilesRoot: "./web",
IndexFileName: "index.html",
ErrorFileName: "__error__.html",
RedirectIndexFileToRoot: true,
AllowedHTTPMethods: []string{http.MethodGet},
CacheEnabled: true,
CacheTTL: time.Second * 5,
CacheMaxFileSize: 1024 * 64, // 64 KiB
CacheMaxItems: 512,
})
if err != nil {
log.Fatal(err)
}
log.Fatal(http.ListenAndServe(":9000", fs))
To run this example execute go run .
in ./examples
directory.
More information can be found in the godocs: http://godoc.org/github.com/avto-dev/go-simple-fileserver
For package testing we use built-in golang testing feature and docker-ce
+ docker-compose
as develop environment. So, just write into your terminal after repository cloning:
$ make test
Changes log can be found here.
If you will find any package errors, please, make an issue in current repository.
This is open-sourced software licensed under the MIT License.