commit
8548fe5772
@ -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"] |
@ -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 |
||||||
|
} |
Loading…
Reference in new issue