-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
67 lines (59 loc) · 1.48 KB
/
Copy pathmain.go
File metadata and controls
67 lines (59 loc) · 1.48 KB
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
package main
import (
"auth/service/api"
"auth/service/console"
"auth/service/database"
"auth/service/database/types"
authMiddleware "auth/service/middleware"
"fmt"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
"gorm.io/gorm/logger"
"log"
"net/http"
)
func Init() {
db, err := gorm.Open(sqlite.Open("database.database"), &gorm.Config{
Logger: logger.Default.LogMode(logger.Silent),
})
if err != nil {
panic(fmt.Sprint("Failed to open database connection:", err))
}
d, _ := db.DB()
// for sqlite, enable foreign_keys support.
var enabled bool
d.QueryRow("PRAGMA foreign_keys = ON;").Scan(&enabled)
err = db.AutoMigrate(
&types.User{},
&types.Origin{},
&types.SecurityConfig{},
&types.OAuthProvider{},
&types.Role{},
&types.UserRole{},
&types.EmailFilter{},
&types.Lockout{},
)
if err != nil {
panic(fmt.Sprint("GORM failed to migrate types to proper SQL tables."))
}
database.DB = db
}
func main() {
Init()
server := echo.New()
server.Use(middleware.CORSWithConfig(middleware.CORSConfig{
AllowCredentials: true,
UnsafeWildcardOriginWithAllowCredentials: true,
}))
server.Use(authMiddleware.DynamicCORS)
console.SetupEndpoints(server)
api.SetupEndpoints(server)
// HealthChecker Endpoint
server.GET("/test", func(ctx echo.Context) error {
log.Println("Someone entered the service.")
return ctx.JSON(http.StatusOK, "")
})
log.Fatal(server.Start(":9999"))
}