1
This commit is contained in:
parent
291f7a680e
commit
69df47f48e
@ -15,15 +15,16 @@ type HttpServer struct {
|
|||||||
maxHandleTime int64
|
maxHandleTime int64
|
||||||
|
|
||||||
handlersMutex sync.RWMutex
|
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 {
|
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)
|
http.HandleFunc("/webapp/index.php", this.dispatchRequest)
|
||||||
this.RegisterHandle("Ops", "selfChecking", func (w http.ResponseWriter,r *http.Request) {
|
this.RegisterHandle("Ops", "selfChecking",
|
||||||
w.Write([]byte(`{"errcode":0, "errmsg":"", "healthy":1, "max_rundelay":10}`))
|
func (w* http.ResponseWriter, r *http.Request) {
|
||||||
})
|
(*w).Write([]byte(`{"errcode":0, "errmsg":"", "healthy":1, "max_rundelay":10}`))
|
||||||
|
})
|
||||||
SysLog().Info("HttpServer.Init")
|
SysLog().Info("HttpServer.Init")
|
||||||
if logOutputTime > 0 {
|
if logOutputTime > 0 {
|
||||||
Timer().AddRepeatTimer(
|
Timer().AddRepeatTimer(
|
||||||
@ -61,7 +62,7 @@ func (this *HttpServer) dispatchRequest(w http.ResponseWriter, r *http.Request)
|
|||||||
handle := this.getHandle(handleName)
|
handle := this.getHandle(handleName)
|
||||||
if handle != nil {
|
if handle != nil {
|
||||||
beginTick := q5.GetTickCount()
|
beginTick := q5.GetTickCount()
|
||||||
handle(w, r)
|
handle(&w, r)
|
||||||
endTick := q5.GetTickCount()
|
endTick := q5.GetTickCount()
|
||||||
if oldVal := atomic.LoadInt64(&this.maxHandleTime); beginTick - endTick > oldVal {
|
if oldVal := atomic.LoadInt64(&this.maxHandleTime); beginTick - endTick > oldVal {
|
||||||
atomic.CompareAndSwapInt64(&this.maxHandleTime, oldVal, endTick - beginTick)
|
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()
|
this.handlersMutex.Lock()
|
||||||
defer this.handlersMutex.Unlock()
|
defer this.handlersMutex.Unlock()
|
||||||
handle, _ := this.handlers[handleName]
|
handle, _ := this.handlers[handleName]
|
||||||
return handle
|
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()
|
this.handlersMutex.Lock()
|
||||||
defer this.handlersMutex.Unlock()
|
defer this.handlersMutex.Unlock()
|
||||||
handleName := c + "$" + a
|
handleName := c + "$" + a
|
||||||
|
Loading…
x
Reference in New Issue
Block a user