web/cmd/smweb/main.go

41 lines
640 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"
"mcquay.me/web"
2015-02-09 22:33:17 -08:00
)
2015-02-09 22:23:42 -08:00
func main() {
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
}
2017-01-26 19:44:31 -08:00
static := ""
if s := os.Getenv("STATIC"); s != "" {
static = s
}
tmpl := ""
if t := os.Getenv("TEMPLATES"); t != "" {
tmpl = t
}
sm := http.NewServeMux()
2017-01-26 19:44:31 -08:00
web.NewSite(sm, static, tmpl)
if err := http.ListenAndServe(fmt.Sprintf(":%d", port), sm); err != nil {
2016-02-12 21:38:47 -08:00
fmt.Fprintf(os.Stderr, "problem serving: %v\n", err)
os.Exit(1)
2015-02-09 22:23:42 -08:00
}
}