File tree 6 files changed +11
-16
lines changed
6 files changed +11
-16
lines changed Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ func main() {
44
44
middlewares := DefaultGinMiddlewares ()
45
45
app := webserver .NewGinEngine (middlewares ... )
46
46
// 注册路由
47
- routes .Register (app )
47
+ routes .InitRouter (app )
48
48
// 运行服务
49
49
webserver .Run (app )
50
50
}
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ func TestPing(t *testing.T) {
15
15
viper .Set ("basic_auth.username" , "admin" )
16
16
viper .Set ("basic_auth.password" , "admin" )
17
17
defer viper .Reset ()
18
- Register (r )
18
+ InitRouter (r )
19
19
recorder , err := goutils .RequestHTTPHandler (
20
20
r ,
21
21
"GET" ,
Original file line number Diff line number Diff line change @@ -37,8 +37,8 @@ const (
37
37
DisableGinSwaggerEnvkey = "DISABLE_GIN_SWAGGER"
38
38
)
39
39
40
- // Register 在 gin engine 上注册 url 对应的 HandlerFunc
41
- func Register (httpHandler http.Handler ) {
40
+ // InitRouter 在 gin engine 上注册 url 对应的 HandlerFunc
41
+ func InitRouter (httpHandler http.Handler ) {
42
42
app , ok := httpHandler .(* gin.Engine )
43
43
if ! ok {
44
44
panic ("HTTP handler must be *gin.Engine" )
@@ -88,3 +88,8 @@ func Register(httpHandler http.Handler) {
88
88
// 注册其他 gin HandlerFunc
89
89
Routes (app )
90
90
}
91
+
92
+ // Routes 注册 API URL 路由
93
+ func Routes (app * gin.Engine ) {
94
+ // TODO: 在这里注册你的 gin API,如: app.GET("/", HandlerFunc)
95
+ }
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import (
10
10
"github.com/stretchr/testify/assert"
11
11
)
12
12
13
- func TestRegisterRoutes (t * testing.T ) {
13
+ func TestInitRouter (t * testing.T ) {
14
14
gin .SetMode (gin .ReleaseMode )
15
15
r := gin .New ()
16
16
// Register 中的 basic auth 依赖 viper 配置
@@ -21,7 +21,7 @@ func TestRegisterRoutes(t *testing.T) {
21
21
22
22
services .Init ()
23
23
24
- Register (r )
24
+ InitRouter (r )
25
25
recorder , err := goutils .RequestHTTPHandler (
26
26
r ,
27
27
"GET" ,
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments