Exemplo n.º 1
0
// 网站统计信息
// 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)+`}`)
}
Exemplo n.º 2
0
// 网站统计信息
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)+`}`)
}
Exemplo n.º 3
0
// 会员列表
// URI: /users
func UsersHandler(rw http.ResponseWriter, req *http.Request) {
	// 获取活跃会员
	activeUsers := service.FindActiveUsers(0, 30)
	// 获取最新加入会员
	newUsers := service.FindNewUsers(0, 30)
	// 获取会员总数
	total := service.CountUsers()
	req.Form.Set(filter.CONTENT_TPL_KEY, "/template/user/users.html")
	// 设置模板数据
	filter.SetData(req, map[string]interface{}{"activeUsers": "active", "actives": activeUsers, "news": newUsers, "total": total})
}