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"
|
2015-02-09 23:01:28 -08:00
|
|
|
|
|
|
|
"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:15:47 -08:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2017-01-26 19:15:47 -08:00
|
|
|
sm := http.NewServeMux()
|
|
|
|
|
2017-01-26 19:44:31 -08:00
|
|
|
web.NewSite(sm, static, tmpl)
|
2017-01-26 19:15:47 -08:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|