-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (39 loc) · 1.06 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
package main
import (
"./handler/user"
"./struct/DB"
"./utils/myMiddleware"
"net/http"
"github.com/labstack/echo"
_ "github.com/labstack/echo/middleware"
"github.com/jinzhu/gorm"
_ "github.com/mattn/go-sqlite3"
)
func main() {
db := connectDB("main.sqlite3")
defer db.Close()
db.AutoMigrate(&DB.Auth{})
db.AutoMigrate(&DB.AuthCode{})
isLoginDB := connectDB("login.sqlite3")
defer isLoginDB.Close()
isLoginDB.AutoMigrate(&DB.LoginStatus{})
e := echo.New()
e.GET("/code/:userid", user.GenerateAuthCode(db))
e.POST("/login", user.Login(db, isLoginDB))
e.POST("/create", user.Create(db))
g := e.Group("/test", myMiddleware.CustomMiddleware(db))
g.GET("", test(db))
e.Start(":8080")
}
func test(db *gorm.DB) echo.HandlerFunc {
return func(c echo.Context) error {
return c.NoContent(http.StatusOK)
}
}
func connectDB(name string) *gorm.DB {
db, err := gorm.Open("sqlite3", name)
if err != nil {
panic("failed to connect database")
}
return db
}