Build Status Go Report Card GoDoc Conventional Commits License

srv is a simple, secure and modern HTTP server, written in Go, to serve static sites, single-page applications or a file with ease. You can use it through its command-line interface, Docker image or programmatically. As it’s an http.Handler implementation, it should be easy to integrate it into your application. The following key features make srv unique and differentiable from the existing solutions and the http.FileServer implementation.

  • Programmatic API.
  • HTTP/2 and TLS support.
  • Custom error handler and pages.
  • Basic HTTP authentication.
  • Hide dot files by default.
  • Directory listing is disabled by default.
  • Encoding negotiation with support of gzip, Deflate and Brotli compression algorithms.


go get                  # get dependency
go install -i   # build and install command-line interface bin



srv can be use through its provided command-line. The following text is the output of the srv -help command.

srv [options]

-addr      The server address, "" by default.
-auth      The basic auth credentials (password must be hashed with bcrypt and escaped with '').
-authfile  The basic auth credentials file following the ".htpasswd" format.
-dir       The directory containing the files to serve, "." by default.
-cert      The TLS certificate.
-key       The TLS private key.
-help      Prints this text.


An official docker image is available on Docker Hub. The following Dockerfile shows how to use the provided base image to serve your static sites or files through a running Docker container. By default, the base image will serve all files available in the /var/www/ directory and listen for TCP connections on 8080.

FROM kevinpollet/srv:latest
COPY . /var/www/

Then, you can build and run your Docker image with the following commands. Your static site or files will be available on http://localhost:8080.

docker build . -t moby:latest
docker run -d -p 8080:8080 moby:latest


package main

import (


func main() {
	customErrorHandler := func(fs http.FileSystem, rw http.ResponseWriter, err error) {

	http.Handle("/static", srv.NewFileServer("examples/hello",

	log.Fatal(http.ListenAndServe(":8080", nil))


The examples directory contains the following examples:

  • hello — A simple static site that can be served from the command-line.
  • docker — A simple static site that can be served from a docker container.


Contributions are welcome!

Want to file a bug, request a feature or contribute some code?

  1. Check out the Code of Conduct.
  2. Check for an existing issue corresponding to your bug or feature request.
  3. Open an issue to describe your bug or feature request.