淇敼锛?. 鏂板浜嗛攣鏈哄埗浠ラ槻姝㈠苟鍙戣闂啿绐侊紱2. 淇敼浜嗕竴浜涘彉閲忓悕浠ユ彁楂樹唬鐮佸彲璇绘€э紱 3. 淇浜嗕竴涓彲鑳藉鑷寸紦鍐插尯婧㈠嚭鐨?bug锛屽皢缂撳啿鍖哄ぇ灏忚缃负 4096锛?. 瀵逛唬鐮佽繘琛屼簡涓€浜涘叾浠栫殑灏忔敼杩涘拰浼樺寲銆?
git-svn-id: svn://47.119.165.148/zhub@121 e63fbceb-bcc3-4977-ac22-735b83d8d0f4
This commit is contained in:
48
monitor/monitor.go
Normal file
48
monitor/monitor.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package monitor
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"zhub/zsub"
|
||||
)
|
||||
|
||||
func StartHttp() {
|
||||
dir, _ := os.Getwd()
|
||||
webDir := path.Join(dir, "/public")
|
||||
|
||||
http.Handle("/", http.FileServer(http.Dir(webDir)))
|
||||
http.HandleFunc("/info", info)
|
||||
http.HandleFunc("/cleanup", cleanup)
|
||||
http.HandleFunc("/retimer", retimer)
|
||||
|
||||
http.ListenAndServe(":1217", nil)
|
||||
}
|
||||
|
||||
func retimer(w http.ResponseWriter, r *http.Request) {
|
||||
zsub.ZSubx().ReloadTimer()
|
||||
renderJson(w, "+reload timer ok")
|
||||
}
|
||||
|
||||
func cleanup(w http.ResponseWriter, r *http.Request) {
|
||||
zsub.ZSubx().Clearup()
|
||||
renderJson(w, "+OK")
|
||||
}
|
||||
|
||||
func info(w http.ResponseWriter, r *http.Request) {
|
||||
topics := zsub.Info()
|
||||
renderJson(w, topics)
|
||||
}
|
||||
|
||||
func renderJson(w http.ResponseWriter, d interface{}) {
|
||||
var bytes []byte
|
||||
|
||||
if str, ok := d.(string); ok {
|
||||
bytes = []byte(str)
|
||||
} else {
|
||||
bytes, _ = json.Marshal(d)
|
||||
w.Header().Set("content-type", "application/json; charset=utf-8;")
|
||||
}
|
||||
w.Write(bytes)
|
||||
}
|
||||
Reference in New Issue
Block a user