added static asset go files
This commit is contained in:
parent
467cda77bf
commit
e372a4e04e
3
Makefile
Normal file
3
Makefile
Normal 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
29
main.go
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
16
static/index.html
Normal file
16
static/index.html
Normal 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>
|
6
static/jquery-2.0.0.min.js
vendored
6
static/jquery-2.0.0.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user