代码拉取完成,页面将自动刷新
package main
import (
"encoding/json"
"net/http"
//"github.com/golang/protobuf/proto"
//"errors"
//"fmt"
"github.com/playnb/mustang/log"
"github.com/playnb/mustang/nosql"
"strconv"
)
type JsonOnlyCount struct {
Count uint32 `json:"Count"`
}
func GetOnlyCountByKey(key string) []byte {
count, err := nosql.Redis.Get(key).Int64()
if err != nil {
log.Error("Ket:%s %s", key, err.Error())
count = 0
}
//log.Trace("%s key-> %d", key, count)
co := &JsonOnlyCount{}
co.Count = uint32(count)
bstr, err := json.Marshal(co)
return (bstr)
}
func SCardOnlyCountByKey(key string) []byte {
count, err := nosql.Redis.SCard(key).Result()
if err != nil {
log.Error("Key:%s %s", key, err.Error())
log.Error(err.Error())
count = 0
}
co := &JsonOnlyCount{}
co.Count = uint32(count)
bstr, err := json.Marshal(co)
return (bstr)
}
func handleCurrentOnline(w http.ResponseWriter, r *http.Request) {
w.Write(GetOnlyCountByKey("ST:CURRENT_ONLINE"))
}
func handleTotalUsers(w http.ResponseWriter, r *http.Request) {
w.Write(SCardOnlyCountByKey("ST:TOTAL_USERS"))
}
func handleTotalView(w http.ResponseWriter, r *http.Request) {
w.Write(SCardOnlyCountByKey("ST:TOTAL_VIEW"))
}
func handlePlayGame(w http.ResponseWriter, r *http.Request) {
w.Write(GetOnlyCountByKey("ST:PLAY_GAME"))
}
func handleViewPage(w http.ResponseWriter, r *http.Request) {
w.Write(GetOnlyCountByKey("ST:VIEW_PAGE"))
}
func handleStartGame(w http.ResponseWriter, r *http.Request) {
w.Write(GetOnlyCountByKey("ST:START_GAME"))
}
func handleTaunterOther(w http.ResponseWriter, r *http.Request) {
w.Write(GetOnlyCountByKey("ST:TAUNTER_OTHER"))
}
func handleShareFirends(w http.ResponseWriter, r *http.Request) {
w.Write(GetOnlyCountByKey("ST:ShareFirends"))
}
func handleShareTimeline(w http.ResponseWriter, r *http.Request) {
w.Write(GetOnlyCountByKey("ST:ShareTimeline"))
}
func handleShareFirendUsers(w http.ResponseWriter, r *http.Request) {
w.Write(SCardOnlyCountByKey("ST:ShareFirendUsers"))
}
func handleShareTimelineUser(w http.ResponseWriter, r *http.Request) {
w.Write(SCardOnlyCountByKey("ST:ShareTimelineUser"))
}
func handleAvgCostTime(w http.ResponseWriter, r *http.Request) {
w.Write(GetOnlyCountByKey("ST:AVG:TIMECOST"))
}
func handleMaxTimeCost(w http.ResponseWriter, r *http.Request) {
w.Write(GetOnlyCountByKey("ST:MaxTimeCost"))
}
func handleBestScore(w http.ResponseWriter, r *http.Request) {
score := make(map[string]int64)
jsonStr := "{"
seperate := ""
for i := 1000; i > 0; i-- {
key := "ST:BEST_SCORE_" + strconv.FormatInt(int64(i), 10)
s := nosql.Redis.SCard(key).Val()
if s > 0 {
score[key] = s
jsonStr = jsonStr + seperate + `"` + key + `":` + strconv.Itoa(int(s))
seperate = `,`
}
}
jsonStr = jsonStr + "}"
/*
b, err := json.Marshal(score)
if err!=nil{
log.Error(err.Error())
}
log.Debug(jsonStr)
*/
w.Write([]byte(jsonStr))
}
func registMonitor(mux *http.ServeMux) {
mux.HandleFunc("/monitor/CurrentOnline", handleCurrentOnline)
mux.HandleFunc("/monitor/TotalUsers", handleTotalUsers)
mux.HandleFunc("/monitor/TotalView", handleTotalView)
mux.HandleFunc("/monitor/PlayGame", handlePlayGame)
mux.HandleFunc("/monitor/ViewPage", handleViewPage)
mux.HandleFunc("/monitor/StartGame", handleStartGame)
mux.HandleFunc("/monitor/BestScore", handleBestScore)
mux.HandleFunc("/monitor/TaunterOther", handleTaunterOther)
mux.HandleFunc("/monitor/ShareFirends", handleShareFirends)
mux.HandleFunc("/monitor/ShareTimeline", handleShareTimeline)
mux.HandleFunc("/monitor/ShareFirendUsers", handleShareFirendUsers)
mux.HandleFunc("/monitor/ShareTimelineUser", handleShareTimelineUser)
mux.HandleFunc("/monitor/AvgCostTime", handleAvgCostTime)
mux.HandleFunc("/monitor/MaxTimeCost", handleMaxTimeCost)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。