修改:简化工程包结构
git-svn-id: svn://47.119.165.148/zhub@132 e63fbceb-bcc3-4977-ac22-735b83d8d0f4
This commit is contained in:
61
zsub/monitor.go
Normal file
61
zsub/monitor.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package zsub
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
)
|
||||
|
||||
func init() {
|
||||
// 1.日志文件 定期分割归档
|
||||
|
||||
}
|
||||
|
||||
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.HandleFunc("/topic/publish", publish)
|
||||
|
||||
http.ListenAndServe(":1217", nil)
|
||||
}
|
||||
|
||||
func publish(w http.ResponseWriter, r *http.Request) {
|
||||
topic := r.FormValue("topic")
|
||||
value := r.FormValue("value")
|
||||
zsub.Publish(topic, value)
|
||||
renderJson(w, "+ok")
|
||||
}
|
||||
|
||||
// retimer 重载定时调度
|
||||
func retimer(w http.ResponseWriter, r *http.Request) {
|
||||
zsub.ReloadTimer()
|
||||
renderJson(w, "+reload timer ok")
|
||||
}
|
||||
|
||||
func cleanup(w http.ResponseWriter, r *http.Request) {
|
||||
zsub.Clearup()
|
||||
renderJson(w, "+OK")
|
||||
}
|
||||
|
||||
func info(w http.ResponseWriter, r *http.Request) {
|
||||
info := 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)
|
||||
}
|
||||
Reference in New Issue
Block a user