allow hosting on alternate port.

This commit is contained in:
Stephen McQuay 2016-02-12 21:38:47 -08:00
parent d76a9bff9f
commit a926bdc955

View File

@ -1,8 +1,10 @@
package main
import (
"fmt"
"net/http"
"os"
"strconv"
"github.com/elazarl/go-bindata-assetfs"
"mcquay.me/web"
@ -20,13 +22,23 @@ func main() {
} else {
fs = http.Dir(os.Getenv("SM_STATIC"))
}
port := 8000
if os.Getenv("PORT") != "" {
p, err := strconv.Atoi(os.Getenv("PORT"))
if err != nil {
fmt.Fprintf(os.Stderr, "couldn't parse port: %v\n", err)
os.Exit(1)
}
port = p
}
// XXX: beware: I've copy/pasted this twice now and been confused because
// I ought to have been using my own servemux
http.Handle(
"/",
http.FileServer(fs),
)
if err := http.ListenAndServe(":8000", nil); err != nil {
panic(err)
if err := http.ListenAndServe(fmt.Sprintf(":%d", port), nil); err != nil {
fmt.Fprintf(os.Stderr, "problem serving: %v\n", err)
os.Exit(1)
}
}