-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
40 lines (33 loc) · 1.08 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"github.com/glxxyz/gohanzi/pages"
"github.com/glxxyz/gohanzi/repo"
"log"
"net/http"
"os"
)
func main() {
log.Print("Server started")
http.HandleFunc("/", pages.Handler(pages.IndexHandler))
http.HandleFunc("/homophones", pages.Handler(pages.HomophonesHandler))
http.HandleFunc("/radicals", pages.Handler(pages.RadicalsHandler))
// Serve static files out of the public directory.
// By configuring a static handler in app.yaml, App Engine serves all the
// static content itself. As a result, the following two lines are in
// effect for development only.
static := http.FileServer(http.Dir("static"))
http.Handle("/static/", http.StripPrefix("/static", static))
// Redirect some URLs from root to static server
http.Handle("/favicon.ico", static)
http.Handle("/favicon.png", static)
port := os.Getenv("PORT")
if port == "" {
port = "8080"
log.Printf("Defaulting to port %s", port)
}
go repo.EnsureResourcesLoaded("src/repo/data/")
log.Printf("Listening on port %s", port)
if err := http.ListenAndServe(":"+port, nil); err != nil {
log.Fatal(err)
}
}