Skip to content

Commit

Permalink
Merge pull request #5 from golang-acexy/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
acexy authored Apr 16, 2024
2 parents 8373d5a + 3b0844a commit 8620da7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 7 additions & 2 deletions ginmodule/ginloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type GinModule struct {

// 自定义Module配置
GinModuleConfig *declaration.ModuleConfig
GinInterceptor func(instance interface{})
GinInterceptor func(instance *gin.Engine)

// * 注册业务路由
Routers []Router
Expand All @@ -45,12 +45,17 @@ func (g *GinModule) ModuleConfig() *declaration.ModuleConfig {
UnregisterPriority: 0,
UnregisterAllowAsync: true,
UnregisterMaxWaitSeconds: 30,
LoadInterceptor: g.GinInterceptor,
LoadInterceptor: func(instance interface{}) {
if g.GinInterceptor != nil {
g.GinInterceptor(instance.(*gin.Engine))
}
},
}
}

func (g *GinModule) Register() (interface{}, error) {
var err error

ginEngin := gin.New()
if g.DebugModule {
gin.SetMode(gin.DebugMode)
Expand Down
6 changes: 2 additions & 4 deletions test/ginstarter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ import (
var moduleLoaders []declaration.ModuleLoader

func init() {

interceptor := func(instance interface{}) {
engine := instance.(*gin.Engine)
interceptor := func(instance *gin.Engine) {
// 使用interceptor的形式,获取原始gin实例 注册一个伪探活服务
engine.GET("/ping", func(context *gin.Context) {
instance.GET("/ping", func(context *gin.Context) {
context.String(http.StatusOK, "alive")
})
}
Expand Down

0 comments on commit 8620da7

Please sign in to comment.