コード例 #1
0
ファイル: ajax.go プロジェクト: allenisready/studygolang
// 网站统计信息
// uri: /websites/stat.json
func StatHandler(rw http.ResponseWriter, req *http.Request) {
	articleTotal := service.ArticlesTotal()
	projectTotal := service.ProjectsTotal()
	topicTotal := service.TopicsTotal()
	cmtTotal := service.CommentsTotal(-1)
	resourceTotal := service.ResourcesTotal()
	userTotal := service.CountUsers()

	data := map[string]int{
		"article":  articleTotal,
		"project":  projectTotal,
		"topic":    topicTotal,
		"resource": resourceTotal,
		"comment":  cmtTotal,
		"user":     userTotal,
	}

	buf, err := json.Marshal(data)
	if err != nil {
		logger.Errorln("[StatHandler] json.marshal error:", err)
		fmt.Fprint(rw, `{"ok": 0, "error":"解析json出错"}`)
		return
	}
	fmt.Fprint(rw, `{"ok": 1, "data":`+string(buf)+`}`)
}
コード例 #2
0
ファイル: ajax.go プロジェクト: BillyMC/studygolang
// 网站统计信息
func StatHandler(rw http.ResponseWriter, req *http.Request) {
	topicTotal := service.TopicsTotal()
	replyTotal := service.CommentsTotal(model.TYPE_TOPIC)
	resourceTotal := service.ResourcesTotal()
	userTotal := service.CountUsers()
	fmt.Fprint(rw, `{"errno": 0, "topic":`+strconv.Itoa(topicTotal)+`,"resource":`+strconv.Itoa(resourceTotal)+`,"reply":`+strconv.Itoa(replyTotal)+`,"user":`+strconv.Itoa(userTotal)+`}`)
}