-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
127 lines (96 loc) · 3.04 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package main
import (
"time"
"fmt"
"github.com/ggpd/brackets/env"
"github.com/ggpd/brackets/routes"
//"github.com/gin-gonic/autotls"
"html/template"
"github.com/gin-gonic/gin"
"github.com/spf13/viper"
)
func main() {
router := gin.Default()
e := routes.CastEnv(env.New())
viper.SetConfigName("config")
viper.AddConfigPath(".")
err := viper.ReadInConfig()
if err != nil {
e.Log.Fatalf("Error reading config file: %s \n", err)
}
url := viper.GetString("app.url")
port := viper.GetInt("app.port")
userSQL := viper.GetString("sql.username")
passSQL := viper.GetString("sql.password")
databaseSQL := viper.GetString("sql.database")
hostSQL := viper.GetString("sql.host")
portSQL := viper.GetInt("sql.port")
passRedis := viper.GetString("redis.password")
hostRedis := viper.GetString("redis.host")
portRedis := viper.GetInt("redis.port")
sqlOptions := env.SQLOptions{
User: userSQL,
Password: passSQL,
Host: hostSQL,
Port: portSQL,
Database: databaseSQL,
}
redisOptions := env.RedisOptions{
Host: hostRedis,
Port: portRedis,
Password: passRedis,
}
e.ConnectDb(sqlOptions, redisOptions)
fm := template.FuncMap{
"age": env.Age,
"httpdob": env.HttpString,
"time": timeSt,
"date": dateSt,
}
router.SetFuncMap(fm)
router.LoadHTMLFiles("public/home.html",
"public/notfound.html",
"public/user/user_index.html",
"public/user/user_login.html",
"public/user/user_edit.html",
"public/user/user_register.html",
"public/user/users.html",
"public/team/team_index.html",
"public/team/team_edit.html",
"public/tournament/tournament_index.html",
"public/tournament/tournaments.html")
/*
* Register Routes
*/
router.NoRoute(routes.NotFoundRoute)
router.Static("/assets", "public/assets")
router.GET("/", e.GetHomeRoute)
router.GET("/login", e.GetLoginRoute)
router.POST("/login", e.PostLoginRoute)
router.GET("/logout", e.GetLogoutRoute)
router.GET("/register", e.GetRegisterRoute)
router.POST("/register", e.PostRegisterRoute)
router.GET("/settings", e.GetSettingsRoute)
router.POST("/settings", e.PostSettingsRoute)
router.GET("/tournament/:selector", e.GetTournamentRoute)
router.GET("/tournament", e.GetTournamentsRoute)
router.POST("/tournament/:selector/new", e.PostCreateTeamRoute)
router.POST("/tournament", e.PostCreateTournamentRoute)
router.GET("/team/:selector", e.GetTeamRoute)
router.GET("/team/:selector/edit", e.GetEditTeamRoute)
router.POST("/team/:selector/edit", e.PostEditTeamRoute)
router.POST("/team/:selector/add", e.PostAddPlayerRoute)
router.GET("/team/:selector/edit/:user/delete", e.GetDeletePlayerRoute)
router.POST("/team/:selector/game", e.PostCreateGameRoute)
router.GET("/user/:selector", e.GetUserRoute)
router.GET("/user", e.GetUsersRoute)
e.Log.Printf("Server starting...")
//e.Log.Fatal(autotls.Run(router, fmt.Sprintf("%v:%v", url, port)))
router.Run(fmt.Sprintf("%v:%v", url, port))
}
func dateSt(t time.Time) string{
return t.Format("Monday, January 2, 2006")
}
func timeSt(t time.Time) string {
return t.Format("3:04 PM")
}