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
|
||||
ormDbLock sync.Mutex
|
||||
ormDbHash map[string]*gorm.DB
|
||||
caHandlersMutex sync.RWMutex
|
||||
caHandlers map[string]GinHandlerFunc
|
||||
caHandlers sync.Map
|
||||
pendingAsyncTask map[string]*q5.ListHead
|
||||
}
|
||||
|
||||
@ -134,7 +133,6 @@ func (this *app) init(userApp UserApp) {
|
||||
go this.goLoopTimer()
|
||||
this.ginEngine = gin.New()
|
||||
this.ginEngine.Use(gin.Recovery())
|
||||
this.caHandlers = make(map[string]GinHandlerFunc)
|
||||
this.userApp.Init()
|
||||
go this.ginEngine.Run(fmt.Sprintf(":%d", this.userApp.GetHttpListenPort()))
|
||||
this.RegisterCaHandle("Ops", "selfChecking", func (c *gin.Context) {
|
||||
@ -146,7 +144,7 @@ func (this *app) init(userApp UserApp) {
|
||||
msg.ErrMsg = ""
|
||||
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", "")
|
||||
handle := this.getCaHandle(handleName)
|
||||
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) {
|
||||
this.caHandlersMutex.Lock()
|
||||
defer this.caHandlersMutex.Unlock()
|
||||
handleName := c + "$" + a
|
||||
this.caHandlers[handleName] = handle
|
||||
this.caHandlers.Store(handleName, handle)
|
||||
}
|
||||
|
||||
func (this *app) getCaHandle(handleName string) GinHandlerFunc {
|
||||
this.caHandlersMutex.Lock()
|
||||
defer this.caHandlersMutex.Unlock()
|
||||
if handle, ok := this.caHandlers[handleName]; ok {
|
||||
return handle
|
||||
if p, ok := this.caHandlers.Load(handleName); ok {
|
||||
return p.(GinHandlerFunc)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user