func admin_index(ctx *goku.HttpContext) goku.ActionResulter { var db *goku.MysqlDB = models.GetDB() defer db.Close() linkCount, err := db.Count("link", "") if err != nil { ctx.ViewData["errorMsg"] = err.Error() return ctx.Render("error", nil) } ctx.ViewData["linkCount"] = linkCount userCount, err := db.Count("user", "") if err != nil { ctx.ViewData["errorMsg"] = err.Error() return ctx.Render("error", nil) } ctx.ViewData["userCount"] = userCount topicCount, err := db.Count("topic", "") if err != nil { ctx.ViewData["errorMsg"] = err.Error() return ctx.Render("error", nil) } ctx.ViewData["topicCount"] = topicCount commentCount, err := db.Count("comment", "") if err != nil { ctx.ViewData["errorMsg"] = err.Error() return ctx.Render("error", nil) } ctx.ViewData["commentCount"] = commentCount return ctx.View(nil) }
func main() { delTime := time.Now() for { handleTime := time.Now() var db *goku.MysqlDB = models.GetDB() //db.Debug = true err := tui_link_for_topic(handleTime, db) if err == nil { err = tui_link_for_home(handleTime, db) } if err == nil { err = tui_link_for_host(handleTime, db) } if err == nil { err = delete_tui_link_for_handle(handleTime, db) } fmt.Println("tui wan") if handleTime.Sub(delTime).Seconds() >= 1800 && err == nil { // 每30分钟删除一次 delTime = handleTime if err == nil { fmt.Println("Del_link_for_home_all") err = models.Del_link_for_home_all(db) } if err == nil { fmt.Println("Del_link_for_topic_all") err = models.Del_link_for_topic_all(db) } if err == nil { fmt.Println("Del_link_for_host_all") err = models.Del_link_for_host_all(db) } } if err != nil { goku.Logger().Errorln(err.Error()) } db.Close() time.Sleep(300 * time.Second) // 每5分钟推给话题/首页 } }
func main() { //ls := utils.LinkSearch{} //ls.SearchLink("名次", 1, 30) //return var db *goku.MysqlDB = models.GetDB() defer db.Close() rows, _ := db.Query("SELECT l.id,l.title,l.context,l.topics,u.Name,l.context_type FROM `link` l INNER JOIN `user` u ON l.user_id=u.id") var linkId int64 var title string var context string var topics string var userName string var contextType int for rows.Next() { rows.Scan(&linkId, &title, &context, &topics, &userName, &contextType) addLinkForSearch(contextType, linkId, title, context, topics, userName) } fmt.Println("执行完成") }