Initial commit.

This commit is contained in:
jerostre 2017-06-23 07:28:11 -07:00
commit 8548fe5772
2 changed files with 32 additions and 0 deletions

8
Dockerfile Normal file
View File

@ -0,0 +1,8 @@
FROM golang:latest as builder
COPY serve.go /
WORKDIR /
RUN CGO_ENABLED=0 go build -a -installsuffix cgo -o serve .
FROM scratch
COPY --from=builder /serve /
CMD ["/serve"]

24
serve.go Normal file
View File

@ -0,0 +1,24 @@
package main
import (
"net/http"
"os"
)
func main() {
host := env("HOST", "")
port := env("PORT", "8080")
folder := env("FOLDER", "/web") + "/"
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, folder+r.URL.Path)
})
http.ListenAndServe(host+":"+port, nil)
}
func env(key, fallback string) string {
if value := os.Getenv(key); 0 < len(value) {
return value
}
return fallback
}