grim/goserve

Implement the custom 404 page
draft
2020-01-04, Gary Kramlich
be14d492fb16
Implement the custom 404 page
package main
import (
"fmt"
"net/http"
"os"
)
func getenv(name, def string) string {
val := os.Getenv(name)
if val != "" {
return val
}
return def
}
func main() {
fs := http.FileServer(http.Dir(getenv("GOSERVE_ROOT", "html")))
if prefix := getenv("GOSERVE_PREFIX", ""); prefix != "" {
fmt.Printf("stripping prefix %q\n", prefix)
fs = http.StripPrefix(prefix, fs)
}
notFoundPage := getenv("GOSERVE_404_PAGE", "")
http.Handle("/", basicHandler(fs, notFoundPage))
addr := getenv("GOSERVE_ADDR", ":3000")
fmt.Printf("Listening on %s\n", addr)
http.ListenAndServe(addr, nil)
}