Files
zhub/monitor/monitor.go
lxy 15a73136cc 修改:1.日志记录连接编号 2.查看服务信息修改
git-svn-id: svn://47.119.165.148/zhub@124 e63fbceb-bcc3-4977-ac22-735b83d8d0f4
2021-08-12 03:31:03 +00:00

49 lines
944 B
Go

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) {
info := zsub.Info()
renderJson(w, info)
}
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)
}