mmg/main.go

33 lines
723 B
Go
Raw Normal View History

2013-05-08 22:43:18 -07:00
package main
import (
"flag"
"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/gorilla/sessions"
2013-05-08 22:43:18 -07:00
)
2013-05-08 23:21:18 -07:00
const MAX = 12
2013-05-08 22:43:18 -07:00
var addr = flag.String("addr", ":8000", "address I'll listen on.")
var static_files = flag.String("static", "./static", "location of static files")
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()
http.Handle("/",
http.FileServer(http.Dir(*static_files)))
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)
2013-05-08 22:43:18 -07:00
if err := http.ListenAndServe(*addr, nil); err != nil {
log.Fatal("ListenAndServe:", err)
}
}