-
-
Notifications
You must be signed in to change notification settings - Fork 201
/
route.go
101 lines (77 loc) · 2.82 KB
/
route.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
96
97
98
99
100
101
/*
Nging is a toolbox for webmasters
Copyright (C) 2018-present Wenhui Shen <swh@admpub.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package route
import (
"github.com/webx-top/echo"
"github.com/webx-top/echo/defaults"
"github.com/webx-top/echo/logger"
"github.com/admpub/nging/v5/application/library/route"
)
var (
routeRegister = route.NewRegister(defaults.Default)
)
func init() {
route.Default.Backend = routeRegister
}
func IRegister() route.IRegister {
return routeRegister
}
func MetaHandler(handler interface{}, m echo.H, requests ...interface{}) echo.Handler {
return routeRegister.MetaHandler(m, handler, requests...)
}
func MetaHandlerWithRequest(handler interface{}, m echo.H, requests interface{}, methods ...string) echo.Handler {
return routeRegister.MetaHandlerWithRequest(m, handler, requests, methods...)
}
func HandlerWithRequest(handler interface{}, requests interface{}, methods ...string) echo.Handler {
return routeRegister.HandlerWithRequest(handler, requests, methods...)
}
func Routes() []*echo.Route {
return routeRegister.Routes()
}
func Logger() logger.Logger {
return routeRegister.Logger()
}
func Pre(middlewares ...interface{}) {
routeRegister.Pre(middlewares...)
}
func PreToGroup(groupName string, middlewares ...interface{}) {
routeRegister.PreToGroup(groupName, middlewares...)
}
func Use(middlewares ...interface{}) {
routeRegister.Use(middlewares...)
}
func UseToGroup(groupName string, middlewares ...interface{}) {
routeRegister.UseToGroup(groupName, middlewares...)
}
func AddGroupNamer(namers ...func(string) string) {
routeRegister.AddGroupNamer(namers...)
}
func Register(fn func(echo.RouteRegister)) {
routeRegister.Register(fn)
}
func SetRootGroup(groupName string) {
routeRegister.SetRootGroup(groupName)
}
func Host(hostName string, middlewares ...interface{}) *route.Host {
return routeRegister.Host(hostName, middlewares...)
}
func Apply() {
echo.PanicIf(echo.Fire(`nging.route.apply.before`))
routeRegister.Apply()
echo.PanicIf(echo.Fire(`nging.route.apply.after`))
}
func RegisterToGroup(groupName string, fn func(echo.RouteRegister), middlewares ...interface{}) route.MetaSetter {
return routeRegister.RegisterToGroup(groupName, fn, middlewares...)
}