# README
Simple golang file server
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.
Example
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
Testing
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
Changelog
Changes log can be found here.
Support
If you will find any package errors, please, make an issue in current repository.
License
This is open-sourced software licensed under the MIT License.
# Functions
JSONErrorHandler respond with simple json-formatted response, if json format was requested (defined in `Accept` header).
NewFileServer creates new file server with default settings.
StaticHTMLPageErrorHandler allows to use user-defined local file with HTML for error page generating.
# Structs
FileServer is a main file server structure (implements `http.Handler` interface).
Settings describes file server options.
# Type aliases
ErrorHandlerFunc is used as handler for errors processing.
ErrorPageTemplate is error page template in string representation.