You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

58 lines
1.1 KiB

  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "log"
  6. "math/rand"
  7. "net/http"
  8. "os"
  9. "time"
  10. "github.com/elazarl/go-bindata-assetfs"
  11. "github.com/gorilla/sessions"
  12. "github.com/prometheus/client_golang/prometheus"
  13. )
  14. //go:generate go-bindata -o static.go static/
  15. const MAX = 12
  16. var port = flag.Int("port", 8000, "listen on this port")
  17. var store = sessions.NewCookieStore([]byte(os.Getenv("MMG_SECRET_KEY")))
  18. func main() {
  19. rand.Seed(time.Now().UTC().UnixNano())
  20. flag.Parse()
  21. http.Handle("/metrics", prometheus.Handler())
  22. http.HandleFunc("/api/v0/addsub/problem/", addsub)
  23. http.HandleFunc("/api/v0/mul/problem/", mul)
  24. http.HandleFunc("/api/v0/attempt/", attempt)
  25. http.Handle(
  26. "/",
  27. http.FileServer(
  28. &assetfs.AssetFS{
  29. Asset: Asset,
  30. AssetDir: AssetDir,
  31. AssetInfo: AssetInfo,
  32. Prefix: "static",
  33. },
  34. ),
  35. )
  36. http.HandleFunc(
  37. "/reset/",
  38. reset,
  39. )
  40. hostname, err := os.Hostname()
  41. if err != nil {
  42. log.Fatal("problem getting hostname:", err)
  43. }
  44. log.Printf("serving at: http://%s:%d/", hostname, *port)
  45. if err := http.ListenAndServe(fmt.Sprintf(":%d", *port), nil); err != nil {
  46. log.Fatal("ListenAndServe:", err)
  47. }
  48. }