Exemple #1
0
// 活跃会员
// uri: /users/active.json
func ActiveUserHandler(rw http.ResponseWriter, req *http.Request) {
	activeUsers := service.FindActiveUsers(0, 9)
	buf, err := json.Marshal(activeUsers)
	if err != nil {
		logger.Errorln("[ActiveUserHandler] json.marshal error:", err)
		fmt.Fprint(rw, `{"ok": 0, "error":"解析json出错"}`)
		return
	}
	fmt.Fprint(rw, `{"ok": 1, "data":`+string(buf)+`}`)
}
Exemple #2
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})
}
Exemple #3
0
// 首页
func IndexHandler(rw http.ResponseWriter, req *http.Request) {
	nodes := genNodes()
	// 获取最新帖子
	newTopics, _ := service.FindTopics(1, 10, "", "ctime DESC")
	// 获取热门帖子
	//hotTopics := service.FindHotTopics()
	// 获得最新博文
	articles := service.FindNewBlogs()
	// 获得最新资源
	resources := service.FindRecentResources()
	// 活跃会员
	activeUsers := service.FindActiveUsers(0, 9)
	// 设置内容模板
	req.Form.Set(filter.CONTENT_TPL_KEY, "/template/index.html")
	// 设置模板数据
	filter.SetData(req, map[string]interface{}{"news": newTopics, "resources": resources, "articles": articles, "actives": activeUsers, "nodes": nodes})
}