web/cmd/smweb/main.go

45 lines
895 B
Go

package main
import (
"fmt"
"net/http"
"os"
"strconv"
"github.com/elazarl/go-bindata-assetfs"
"mcquay.me/web"
)
func main() {
var fs http.FileSystem
if os.Getenv("SM_DEV") == "" {
fs = &assetfs.AssetFS{
Asset: web.Asset,
AssetDir: web.AssetDir,
AssetInfo: web.AssetInfo,
Prefix: "static",
}
} 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(fmt.Sprintf(":%d", port), nil); err != nil {
fmt.Fprintf(os.Stderr, "problem serving: %v\n", err)
os.Exit(1)
}
}