mmg/main.go

55 lines
1.0 KiB
Go
Raw Normal View History

2013-05-08 22:43:18 -07:00
package main
import (
"flag"
2015-01-12 20:01:38 -08:00
"fmt"
2013-05-08 22:43:18 -07:00
"log"
2013-05-09 00:48:56 -07:00
"math/rand"
2013-05-08 22:43:18 -07:00
"net/http"
2013-05-09 00:53:17 -07:00
"os"
2013-05-09 00:48:56 -07:00
"time"
2014-12-07 21:23:31 -08:00
"github.com/elazarl/go-bindata-assetfs"
2014-12-07 21:23:31 -08:00
"github.com/gorilla/sessions"
2013-05-08 22:43:18 -07:00
)
//go:generate go-bindata -o static.go static/
2013-05-08 23:21:18 -07:00
const MAX = 12
2015-01-12 20:01:38 -08:00
var port = flag.Int("port", 8000, "listen on this port")
2013-05-08 22:43:18 -07:00
2013-05-09 00:53:17 -07:00
var store = sessions.NewCookieStore([]byte(os.Getenv("MMG_SECRET_KEY")))
2013-05-08 22:43:18 -07:00
func main() {
2013-05-09 00:48:56 -07:00
rand.Seed(time.Now().UTC().UnixNano())
2013-05-08 22:43:18 -07:00
flag.Parse()
2014-12-07 21:23:31 -08:00
http.HandleFunc("/api/v0/addsub/problem/", addsub)
http.HandleFunc("/api/v0/mul/problem/", mul)
http.HandleFunc("/api/v0/attempt/", attempt)
http.Handle(
2014-12-07 21:44:05 -08:00
"/",
http.FileServer(
&assetfs.AssetFS{
Asset: Asset,
AssetDir: AssetDir,
Prefix: "static",
},
),
2014-12-07 21:44:05 -08:00
)
2014-12-07 21:57:41 -08:00
http.HandleFunc(
"/reset/",
reset,
)
2015-01-12 20:01:38 -08:00
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 {
2013-05-08 22:43:18 -07:00
log.Fatal("ListenAndServe:", err)
}
}