优化代码

This commit is contained in:
刘祥超
2021-12-14 10:01:21 +08:00
parent e6ac085025
commit 014f433191
3 changed files with 21 additions and 11 deletions

View File

@@ -95,17 +95,12 @@ func main() {
if err != nil { if err != nil {
fmt.Println("[ERROR]" + err.Error()) fmt.Println("[ERROR]" + err.Error())
} else { } else {
instances, ok := reply.Params["result"] instancesJSON, err := json.MarshalIndent(reply.Params, "", " ")
if ok {
instancesJSON, err := json.MarshalIndent(instances, "", " ")
if err != nil { if err != nil {
fmt.Println("[ERROR]" + err.Error()) fmt.Println("[ERROR]" + err.Error())
} else { } else {
fmt.Println(string(instancesJSON)) fmt.Println(string(instancesJSON))
} }
} else {
fmt.Println("no instances yet.")
}
} }
}) })
app.On("conns", func() { app.On("conns", func() {

View File

@@ -88,3 +88,15 @@ func (this *HTTPRateWriter) Hijack() (conn net.Conn, buf *bufio.ReadWriter, err
} }
return return
} }
// Flush Flush
func (this *HTTPRateWriter) Flush() {
if this.parentWriter == nil {
return
}
flusher, ok := this.parentWriter.(http.Flusher)
if ok {
flusher.Flush()
return
}
}

View File

@@ -170,9 +170,11 @@ func (this *Node) Start() {
}) })
// 统计 // 统计
go stats.SharedTrafficStatManager.Start(func() *nodeconfigs.NodeConfig { goman.New(func() {
stats.SharedTrafficStatManager.Start(func() *nodeconfigs.NodeConfig {
return sharedNodeConfig return sharedNodeConfig
}) })
})
goman.New(func() { goman.New(func() {
stats.SharedHTTPRequestStatManager.Start() stats.SharedHTTPRequestStatManager.Start()
}) })
@@ -618,6 +620,7 @@ func (this *Node) listenSock() error {
_ = cmd.Reply(&gosock.Command{ _ = cmd.Reply(&gosock.Command{
Params: map[string]interface{}{ Params: map[string]interface{}{
"total": runtime.NumGoroutine(),
"result": result, "result": result,
}, },
}) })