In production mode, embed static content

This commit is contained in:
nemunaire 2019-09-02 15:41:37 +02:00
parent 0876fc3c2e
commit deb4ff03ca

View File

@ -5,7 +5,6 @@ import (
"log" "log"
"net/http" "net/http"
"os" "os"
"path/filepath"
) )
var mux = http.NewServeMux() var mux = http.NewServeMux()
@ -55,12 +54,8 @@ func main() {
log.Println("Registering handlers...") log.Println("Registering handlers...")
authFunc := func(r *http.Request) *User { return Authenticate(*htpasswd, r) } authFunc := func(r *http.Request) *User { return Authenticate(*htpasswd, r) }
staticDir, _ := filepath.Abs("static") if err := sanitizeStaticOptions(); err != nil {
if _, err := os.Stat(staticDir); os.IsNotExist(err) { log.Fatal(err)
staticDir, _ = filepath.Abs(filepath.Join(filepath.Dir(os.Args[0]), "static"))
if _, err := os.Stat(staticDir); os.IsNotExist(err) {
log.Fatal(err)
}
} }
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {