added static asset go files

This commit is contained in:
Stephen McQuay 2014-12-07 21:44:05 -08:00
parent 467cda77bf
commit e372a4e04e
7 changed files with 11003 additions and 9 deletions

3
Makefile Normal file
View File

@ -0,0 +1,3 @@
static.go: static/*
go get -v github.com/chsc/bin2go
bin2go -p main -s static.go -c -a static/*

29
main.go
View File

@ -14,19 +14,42 @@ import (
const MAX = 12
var addr = flag.String("addr", ":8000", "address I'll listen on.")
var static_files = flag.String("static", "./static", "location of static files")
var store = sessions.NewCookieStore([]byte(os.Getenv("MMG_SECRET_KEY")))
var statics map[string][]byte
func main() {
statics = map[string][]byte{
"/": staticIndexHtml,
"/jquery.js": staticJqueryJs,
"/math.css": staticMathCss,
"/math.js": staticMathJs,
"/addsub/": staticAddsubHtml,
"/mul/": staticMulHtml,
}
rand.Seed(time.Now().UTC().UnixNano())
flag.Parse()
http.Handle("/",
http.FileServer(http.Dir(*static_files)))
http.HandleFunc("/api/v0/addsub/problem/", addsub)
http.HandleFunc("/api/v0/mul/problem/", mul)
http.HandleFunc("/api/v0/attempt/", attempt)
http.HandleFunc(
"/",
static,
)
if err := http.ListenAndServe(*addr, nil); err != nil {
log.Fatal("ListenAndServe:", err)
}
}
func static(w http.ResponseWriter, req *http.Request) {
if content, ok := statics[req.URL.Path]; !ok {
http.Error(w, "file not found", http.StatusNotFound)
return
} else {
_, err := w.Write(content)
if err != nil {
http.Error(w, "problem writing response", http.StatusInternalServerError)
return
}
}
}

10958
static.go Normal file

File diff suppressed because it is too large Load Diff

16
static/index.html Normal file
View File

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Mardson's Math Game</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="/math.css" rel="stylesheet" media="screen">
</head>
<body>
<section id="content">
<ul>
<li><a href="/addsub/">addition and subtraction</a></li>
<li><a href="/mul/">multiplication</a></li>
</ul>
</section>
</body>
</html>

File diff suppressed because one or more lines are too long