Simple static http server with minimum dependencies written in go
884
The aim of this project is to offer a simple http server with :
To realize this aim, the server is written in go with no additional modules.
Because of that, for example, under a Linux OS the required dependencies are only :
$ ldd simple-static-http-server
linux-vdso.so.1 (0x00007ffd3d8e6000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f1c79ab6000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f1c796c5000)
/lib64/ld-linux-x86-64.so.2 (0x00007f1c79cd5000)
The size is also very small. For example, under Ubuntu 18.04 :
$ ll simple-static-http-server
-rwxrwxr-x 1 ubuntu01 ubuntu01 6.5M Feb 12 13:53 simple-static-http-server
Go to the releases page and download the last version version for your operating system.
go build -o simple-static-http-server
go get github.com/stretchr/testify/assert
go test
All configurations are defined by command line arguments. These arguments is printed by the flag -h :
$ ./simple-static-http-server -h
Usage of ./simple-static-http-server:
-d string
Directory which contains static files to be served (default "/home/ubuntu01/workspace-go/simple-static-http-server")
-p int
Port (default 8080)
The default directory to be served is the current directory and the default is 8080.
To change it, use the flag -d and -p.
For example, to serve the directory /staic on port 9090.
$ ./simple-static-http-server -d /static -p 9090
In case of error, logs are printed.
$ ./simple-static-http-server -d /static -p 80
2019/02/12 14:17:04 Cannot start the http server : listen tcp :80: bind: permission denied
In addition, the following exit codes are available.
Just copy the binary !
A docker image is available on dockerhub squareitservices/static-http-server.
The docker image is based on alpine with just the only one required dependecy libc6-compat.
The dockerfile is a multi stage build which build the binary from sources and then create the docker image :
docker build -t static-http-server:tag .
The docker image is also light :
$ docker images | grep squareitservices/static-http-server
squareitservices/static-http-server latest 7b91cb0d4b15 3 days ago 12.3MB
Content type
Image
Digest
Size
6.3 MB
Last updated
about 7 years ago
docker pull squareitservices/static-http-server