Skip to content

avto-dev/go-simple-fileserver

Repository files navigation

Simple golang file server

Release version Project language Build Status Coverage Go Report License

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.

Installation

To install package, use go get:

$ go get github.com/avto-dev/go-simple-fileserver

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

Release date Commits since latest release

Changes log can be found here.

Support

Issues Issues

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.