mmg/main.go
Stephen McQuay c6419060ff use go generate
brought in jteeuwen/go-bindata and friends.

I honestly like their interface much, much better than the previous one.
2015-01-12 23:29:14 -08:00

55 lines
1.0 KiB
Go

package main
import (
"flag"
"fmt"
"log"
"math/rand"
"net/http"
"os"
"time"
"github.com/elazarl/go-bindata-assetfs"
"github.com/gorilla/sessions"
)
//go:generate go-bindata -o static.go static/
const MAX = 12
var port = flag.Int("port", 8000, "listen on this port")
var store = sessions.NewCookieStore([]byte(os.Getenv("MMG_SECRET_KEY")))
func main() {
rand.Seed(time.Now().UTC().UnixNano())
flag.Parse()
http.HandleFunc("/api/v0/addsub/problem/", addsub)
http.HandleFunc("/api/v0/mul/problem/", mul)
http.HandleFunc("/api/v0/attempt/", attempt)
http.Handle(
"/",
http.FileServer(
&assetfs.AssetFS{
Asset: Asset,
AssetDir: AssetDir,
Prefix: "static",
},
),
)
http.HandleFunc(
"/reset/",
reset,
)
hostname, err := os.Hostname()
if err != nil {
log.Fatal("problem getting hostname:", err)
}
log.Printf("serving at: http://%s:%d/", hostname, *port)
if err := http.ListenAndServe(fmt.Sprintf(":%d", *port), nil); err != nil {
log.Fatal("ListenAndServe:", err)
}
}