forked from nwplus/nwhacks2016
/
main.go
54 lines (44 loc) · 1.28 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"log"
"mime"
"net/http"
"github.com/gorilla/mux"
"github.com/jinzhu/gorm"
_ "github.com/mattn/go-sqlite3"
)
type User struct {
Email, Name, University, Location, TShirtSize, LinkedIn, GitHub, PersonalSite string
TravelReimbursement int
NeedsTravelReimbursement, Accepted, Waitlisted bool
}
func main() {
// Had to do this because returns svg as text/xml when running on AppEngine: http://goo.gl/hwZSp2
mime.AddExtensionType(".svg", "image/svg+xml")
db, err := gorm.Open("sqlite3", "/tmp/gorm.db")
if err != nil {
log.Fatal(err)
}
db.CreateTable(&User{})
s := &server{db}
r := mux.NewRouter()
sr := r.PathPrefix("/api").Subrouter()
sr.HandleFunc("/register", s.registerHandler)
r.HandleFunc("/{rest:.*}", s.staticHandler)
http.Handle("/", r)
log.Fatal(http.ListenAndServe(":8182", nil))
}
type server struct {
db gorm.DB
}
func (s *server) staticHandler(w http.ResponseWriter, r *http.Request) {
log.Println("path:", r.URL.Path)
if r.URL.Path == "/" {
http.ServeFile(w, r, "static/app.html")
} else {
http.ServeFile(w, r, "static/"+r.URL.Path)
}
}
func (s *server) registerHandler(w http.ResponseWriter, r *http.Request) {
log.Println("path:", r.URL.Path)
}