/
init.go
40 lines (33 loc) · 1.06 KB
/
init.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
package core
import (
"github.com/gofiber/fiber/v2"
"gorm.io/gorm"
)
var dbMap = map[string]func([]*gorm.DB){}
var routerRootNoCheckMap = map[string]func(fiber.Router){}
var routerAPICheckMap = map[string]func(fiber.Router){}
var routerAdminCheckMap = map[string]func(fiber.Router){}
func RegisterDatabase(dbType string, f func([]*gorm.DB)) {
if _, ok := dbMap[dbType]; ok {
panic("duplicate db type: " + dbType)
}
dbMap[dbType] = f
}
func RegisterRootNoCheckRouter(routerType string, f func(fiber.Router)) {
if _, ok := routerRootNoCheckMap[routerType]; ok {
panic("duplicate router type: " + routerType)
}
routerRootNoCheckMap[routerType] = f
}
func RegisterAPICheckRouter(routerType string, f func(fiber.Router)) {
if _, ok := routerAPICheckMap[routerType]; ok {
panic("duplicate router type: " + routerType)
}
routerAPICheckMap[routerType] = f
}
func RegisterAdminCheckRouter(routerType string, f func(fiber.Router)) {
if _, ok := routerAdminCheckMap[routerType]; ok {
panic("duplicate router type: " + routerType)
}
routerAdminCheckMap[routerType] = f
}