-
Notifications
You must be signed in to change notification settings - Fork 0
/
ding.go
50 lines (44 loc) · 1.13 KB
/
ding.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
package dingadmin
import (
"strconv"
"github.com/dingdinglz/dingadmin/tool"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/gofiber/fiber/v2/middleware/recover"
"github.com/gofiber/template/html/v2"
)
type App struct {
Server *fiber.App
config Config
dingMenus []Menu
dingMenuGroups []MenuGroup
}
func New(configs ...Config) *App {
app := &App{}
if len(configs) > 0 {
app.config = configs[0]
} else {
app.config = DefaultConfig
}
engine := html.New(app.config.Theme, ".html")
engine.ShouldReload = true
app.Server = fiber.New(fiber.Config{Views: engine})
return app
}
func NewWithFiberConfig(serverConfig fiber.Config, configs ...Config) *App {
app := &App{}
if len(configs) > 0 {
app.config = configs[0]
} else {
app.config = DefaultConfig
}
engine := html.New(app.config.Theme, ".html")
serverConfig.Views = engine
app.Server = fiber.New(serverConfig)
return app
}
func (app *App) Serve() error {
bindRouters(app)
app.Server.Use(logger.New(), recover.New())
return app.Server.Listen(tool.StringBuilder("0.0.0.0:", strconv.Itoa(app.config.Port)))
}