moved code out of main, made web package
This commit is contained in:
+9
-18
@@ -6,22 +6,15 @@ import (
|
||||
"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"))
|
||||
static := ""
|
||||
if s := os.Getenv("STATIC"); s != "" {
|
||||
static = s
|
||||
}
|
||||
|
||||
port := 8000
|
||||
if os.Getenv("PORT") != "" {
|
||||
p, err := strconv.Atoi(os.Getenv("PORT"))
|
||||
@@ -31,13 +24,11 @@ func main() {
|
||||
}
|
||||
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 {
|
||||
|
||||
sm := http.NewServeMux()
|
||||
|
||||
web.NewServer(sm, static)
|
||||
if err := http.ListenAndServe(fmt.Sprintf(":%d", port), sm); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "problem serving: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user