1
This commit is contained in:
parent
0ff5019590
commit
effa2d3257
16
app.go
16
app.go
@ -83,8 +83,7 @@ type app struct {
|
|||||||
ginEngine *gin.Engine
|
ginEngine *gin.Engine
|
||||||
ormDbLock sync.Mutex
|
ormDbLock sync.Mutex
|
||||||
ormDbHash map[string]*gorm.DB
|
ormDbHash map[string]*gorm.DB
|
||||||
caHandlersMutex sync.RWMutex
|
caHandlers sync.Map
|
||||||
caHandlers map[string]GinHandlerFunc
|
|
||||||
pendingAsyncTask map[string]*q5.ListHead
|
pendingAsyncTask map[string]*q5.ListHead
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,7 +133,6 @@ func (this *app) init(userApp UserApp) {
|
|||||||
go this.goLoopTimer()
|
go this.goLoopTimer()
|
||||||
this.ginEngine = gin.New()
|
this.ginEngine = gin.New()
|
||||||
this.ginEngine.Use(gin.Recovery())
|
this.ginEngine.Use(gin.Recovery())
|
||||||
this.caHandlers = make(map[string]GinHandlerFunc)
|
|
||||||
this.userApp.Init()
|
this.userApp.Init()
|
||||||
go this.ginEngine.Run(fmt.Sprintf(":%d", this.userApp.GetHttpListenPort()))
|
go this.ginEngine.Run(fmt.Sprintf(":%d", this.userApp.GetHttpListenPort()))
|
||||||
this.RegisterCaHandle("Ops", "selfChecking", func (c *gin.Context) {
|
this.RegisterCaHandle("Ops", "selfChecking", func (c *gin.Context) {
|
||||||
@ -146,7 +144,7 @@ func (this *app) init(userApp UserApp) {
|
|||||||
msg.ErrMsg = ""
|
msg.ErrMsg = ""
|
||||||
c.JSON(http.StatusOK, msg)
|
c.JSON(http.StatusOK, msg)
|
||||||
})
|
})
|
||||||
this.ginEngine.GET("/webapp/index.php", func (c *gin.Context) {
|
this.ginEngine.Any("/webapp/index.php", func (c *gin.Context) {
|
||||||
handleName := c.DefaultQuery("c", "") + "$" + c.DefaultQuery("a", "")
|
handleName := c.DefaultQuery("c", "") + "$" + c.DefaultQuery("a", "")
|
||||||
handle := this.getCaHandle(handleName)
|
handle := this.getCaHandle(handleName)
|
||||||
if handle == nil {
|
if handle == nil {
|
||||||
@ -388,17 +386,13 @@ func (this *app) GetOrmDb(name string) *gorm.DB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *app) RegisterCaHandle(c string, a string, handle GinHandlerFunc) {
|
func (this *app) RegisterCaHandle(c string, a string, handle GinHandlerFunc) {
|
||||||
this.caHandlersMutex.Lock()
|
|
||||||
defer this.caHandlersMutex.Unlock()
|
|
||||||
handleName := c + "$" + a
|
handleName := c + "$" + a
|
||||||
this.caHandlers[handleName] = handle
|
this.caHandlers.Store(handleName, handle)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *app) getCaHandle(handleName string) GinHandlerFunc {
|
func (this *app) getCaHandle(handleName string) GinHandlerFunc {
|
||||||
this.caHandlersMutex.Lock()
|
if p, ok := this.caHandlers.Load(handleName); ok {
|
||||||
defer this.caHandlersMutex.Unlock()
|
return p.(GinHandlerFunc)
|
||||||
if handle, ok := this.caHandlers[handleName]; ok {
|
|
||||||
return handle
|
|
||||||
} else {
|
} else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user