web/cmd/smweb/main.go

45 lines
895 B
Go
Raw Normal View History

2015-02-09 22:23:42 -08:00
package main
2015-02-09 22:33:17 -08:00
import (
2016-02-12 21:38:47 -08:00
"fmt"
2015-02-09 22:33:17 -08:00
"net/http"
2015-02-09 23:11:06 -08:00
"os"
2016-02-12 21:38:47 -08:00
"strconv"
"github.com/elazarl/go-bindata-assetfs"
"mcquay.me/web"
2015-02-09 22:33:17 -08:00
)
2015-02-09 22:23:42 -08:00
func main() {
2015-02-09 23:11:06 -08:00
var fs http.FileSystem
if os.Getenv("SM_DEV") == "" {
fs = &assetfs.AssetFS{
2016-02-12 21:37:58 -08:00
Asset: web.Asset,
AssetDir: web.AssetDir,
AssetInfo: web.AssetInfo,
Prefix: "static",
2015-02-09 23:11:06 -08:00
}
} else {
fs = http.Dir(os.Getenv("SM_STATIC"))
}
2016-02-12 21:38:47 -08:00
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
}
2015-06-11 20:37:34 -07:00
// XXX: beware: I've copy/pasted this twice now and been confused because
// I ought to have been using my own servemux
2015-02-09 22:23:42 -08:00
http.Handle(
"/",
2015-02-09 23:11:06 -08:00
http.FileServer(fs),
2015-02-09 22:23:42 -08:00
)
2016-02-12 21:38:47 -08:00
if err := http.ListenAndServe(fmt.Sprintf(":%d", port), nil); err != nil {
fmt.Fprintf(os.Stderr, "problem serving: %v\n", err)
os.Exit(1)
2015-02-09 22:23:42 -08:00
}
}