From effa2d325725bb8ece314b155b0617af8d7ac714 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sun, 26 May 2024 13:01:28 +0800 Subject: [PATCH] 1 --- app.go | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/app.go b/app.go index 3610a41..ed1ad9a 100644 --- a/app.go +++ b/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 }