-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
76 lines (67 loc) · 1.94 KB
/
server.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"log"
"net/http"
"strings"
"github.com/Casxt/TimeLine/components/index"
"github.com/Casxt/TimeLine/api"
"github.com/Casxt/TimeLine/components/image"
"github.com/Casxt/TimeLine/components/line"
"github.com/Casxt/TimeLine/components/profile"
"github.com/Casxt/TimeLine/components/signin"
"github.com/Casxt/TimeLine/components/signup"
"github.com/Casxt/TimeLine/database"
"github.com/Casxt/TimeLine/static"
)
func route(res http.ResponseWriter, req *http.Request) {
path := req.URL.Path
log.Println(req.RemoteAddr[0:strings.LastIndex(req.RemoteAddr, ":")], req.Method, path)
switch {
case strings.HasPrefix(strings.ToLower(path), "/api"):
api.Route(res, req)
case strings.HasPrefix(strings.ToLower(path), "/signin"):
signin.Route(res, req)
case strings.HasPrefix(strings.ToLower(path), "/signup"):
signup.Route(res, req)
case strings.HasPrefix(strings.ToLower(path), "/static"):
static.Route(res, req)
case strings.HasPrefix(strings.ToLower(path), "/image"):
image.Route(res, req)
case strings.HasPrefix(strings.ToLower(path), "/line"):
line.Route(res, req)
case strings.HasPrefix(strings.ToLower(path), "/profile"):
profile.Route(res, req)
default:
index.Route(res, req)
}
}
//SetUp will setup database table
func SetUp() {
if err := database.Open(); err != nil {
log.Println("database Open filed")
return
}
defer database.Close()
course, selfCourse, err := database.Begin(nil)
if err != nil {
log.Fatalln(err)
return
}
if err := database.CreateUserTable(course); err != nil {
database.Rollback(course, selfCourse)
return
}
if err := database.CreateLineTable(course); err != nil {
database.Rollback(course, selfCourse)
return
}
if err := database.CreateGroupTable(course); err != nil {
database.Rollback(course, selfCourse)
return
}
if err := database.CreateSliceTable(course); err != nil {
database.Rollback(course, selfCourse)
return
}
database.Commit(course, selfCourse)
}