-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
95 lines (72 loc) · 2.3 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
package main
import (
"./handler/user"
"./handler/survival"
"./handler/contents"
"./handler/chat"
"./struct/DB"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
_ "os"
_ "fmt"
"html/template"
"io"
"github.com/jinzhu/gorm"
_ "github.com/mattn/go-sqlite3"
)
type Renderer struct {
templates *template.Template
}
func (r *Renderer) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
return r.templates.ExecuteTemplate(w, name, data)
}
func main() {
e := echo.New()
e.Use(middleware.Recover())
e.Use(middleware.Logger())
e.Use(middleware.CORS())
db, err := gorm.Open("sqlite3", "DB/main.sqlite3")
if err != nil {
panic("failed to connect database")
}
defer db.Close()
db.AutoMigrate(&DB.Auth{})
db.AutoMigrate(&DB.IsSurvival{})
db.AutoMigrate(&DB.IsJoin{})
db.AutoMigrate(&DB.Team{})
db.AutoMigrate(&DB.AuthCode{})
db.AutoMigrate(&DB.Chat{})
e.Static("/js", "js")
e.Static("/css", "css")
e.Static("/img", "img")
a := e.Group("/admin")
a.Use(middleware.BasicAuth(func(username, password string, c echo.Context) (bool, error) {
if username == "admin" && password == "admin" {
c.Set("userid", username)
return true, nil
}
return false, nil
}))
a.GET("", Contents.Admin)
a.POST("/evolution/:userid", User.Evolution(db))
e.File("/", "html/login.html")
e.File("/create", "html/create.html")
e.File("/team", "html/team.html")
e.GET("/client/:userid", Contents.Client(db))
e.GET("/code/:userid", User.GenerateAuthCode(db))
e.POST("/login", User.Login(db))
e.POST("/create", User.Create(db))
e.POST("/delete/:userid", User.Delete(db))
e.GET("/survival", Survival.IsSurvivals(db))
e.GET("/join", User.IsJoins(db))
e.GET("/survival/:userid", Survival.IsSurvivalMe(db))
e.GET("/join/:userid", User.IsJoinMe(db))
e.POST("/join/:userid", User.Join(db))
e.POST("/dontjoin/:userid", User.DontJoin(db))
e.POST("/resporn/:userid", Survival.Resporn(db))
e.POST("/dead/:userid", Survival.Dead(db))
e.GET("/chat", Chat.Read(db))
e.POST("/chat", Chat.Create(db))
e.POST("/team/:userid", User.SetTeam(db))
e.Start(":8080")
}