From 69df47f48e1da3bf0a0842469ad9a3f41586041f Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 30 Oct 2020 13:56:08 +0800 Subject: [PATCH] 1 --- httpserver.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/httpserver.go b/httpserver.go index 8b87cad..db3d987 100644 --- a/httpserver.go +++ b/httpserver.go @@ -15,15 +15,16 @@ type HttpServer struct { maxHandleTime int64 handlersMutex sync.RWMutex - handlers map[string]func(http.ResponseWriter, *http.Request) + handlers map[string]func(*http.ResponseWriter, *http.Request) } func (this *HttpServer) Init(serviceName string, logOutputTime int32) *HttpServer { - this.handlers = make(map[string]func(http.ResponseWriter, *http.Request)) + this.handlers = make(map[string]func(*http.ResponseWriter, *http.Request)) http.HandleFunc("/webapp/index.php", this.dispatchRequest) - this.RegisterHandle("Ops", "selfChecking", func (w http.ResponseWriter,r *http.Request) { - w.Write([]byte(`{"errcode":0, "errmsg":"", "healthy":1, "max_rundelay":10}`)) - }) + this.RegisterHandle("Ops", "selfChecking", + func (w* http.ResponseWriter, r *http.Request) { + (*w).Write([]byte(`{"errcode":0, "errmsg":"", "healthy":1, "max_rundelay":10}`)) + }) SysLog().Info("HttpServer.Init") if logOutputTime > 0 { Timer().AddRepeatTimer( @@ -61,7 +62,7 @@ func (this *HttpServer) dispatchRequest(w http.ResponseWriter, r *http.Request) handle := this.getHandle(handleName) if handle != nil { beginTick := q5.GetTickCount() - handle(w, r) + handle(&w, r) endTick := q5.GetTickCount() if oldVal := atomic.LoadInt64(&this.maxHandleTime); beginTick - endTick > oldVal { atomic.CompareAndSwapInt64(&this.maxHandleTime, oldVal, endTick - beginTick) @@ -73,14 +74,15 @@ func (this *HttpServer) dispatchRequest(w http.ResponseWriter, r *http.Request) } } -func (this *HttpServer) getHandle(handleName string) (func(http.ResponseWriter, *http.Request)) { +func (this *HttpServer) getHandle(handleName string) (func(*http.ResponseWriter, *http.Request)) { this.handlersMutex.Lock() defer this.handlersMutex.Unlock() handle, _ := this.handlers[handleName] return handle } -func (this *HttpServer) RegisterHandle(c string, a string, handle func(http.ResponseWriter, *http.Request)) { +func (this *HttpServer) RegisterHandle(c string, a string, + handle func(*http.ResponseWriter, *http.Request)) { this.handlersMutex.Lock() defer this.handlersMutex.Unlock() handleName := c + "$" + a