本文整理汇总了Golang中github.com/QLeelulu/goku.Logger函数的典型用法代码示例。如果您正苦于以下问题:Golang Logger函数的具体用法?Golang Logger怎么用?Golang Logger使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Logger函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: FavoriteLink_ByUser
// 获取由用户收藏的link
// @page: 从1开始
func FavoriteLink_ByUser(userId int64, page, pagesize int) []Link {
var db *goku.MysqlDB = GetDB()
defer db.Close()
page, pagesize = utils.PageCheck(page, pagesize)
qi := goku.SqlQueryInfo{}
qi.Fields = "l.id, l.user_id, l.title, l.context, l.topics, l.vote_up, l.vote_down, l.view_count, l.comment_count, l.create_time"
qi.Join = " ufl INNER JOIN `link` l ON ufl.link_id=l.id"
qi.Where = "ufl.user_id=?"
qi.Params = []interface{}{userId}
qi.Limit = pagesize
qi.Offset = pagesize * page
qi.Order = "ufl.create_time desc"
rows, err := db.Select("user_favorite_link", qi)
if err != nil {
goku.Logger().Errorln(err.Error())
return nil
}
links := make([]Link, 0)
for rows.Next() {
link := Link{}
err = rows.Scan(&link.Id, &link.UserId, &link.Title, &link.Context, &link.Topics,
&link.VoteUp, &link.VoteDown, &link.ViewCount, &link.CommentCount, &link.CreateTime)
if err != nil {
goku.Logger().Errorln(err.Error())
return nil
}
links = append(links, link)
}
return links
}
示例2: User_UnFollow
// userId 取消关注 followId
func User_UnFollow(userId, followId int64) (bool, error) {
if userId < 1 || followId < 1 {
return false, errors.New("参数错误")
}
if userId == followId {
return false, errors.New("不能取消关注自己")
}
var db *goku.MysqlDB = GetDB()
defer db.Close()
r, err := db.Delete("user_follow", "`user_id`=? AND `follow_id`=?", userId, followId)
if err != nil {
goku.Logger().Errorln(err.Error())
return false, err
}
var afrow int64
afrow, err = r.RowsAffected()
if err != nil {
goku.Logger().Errorln(err.Error())
return false, err
}
if afrow > 0 {
LinkForUser_UnFollowUser(userId, followId)
// 更新粉丝数
User_IncCount(db, userId, "friend_count", -1)
// 更新关注数
User_IncCount(db, followId, "follower_count", -1)
return true, nil
}
return false, nil
}
示例3: NewestLinkUnread_Friends
// 关注好友的最新链接的未读数
func NewestLinkUnread_Friends(userId, lastReadLinkId int64) (int64, error) {
if userId < 1 {
return 0, nil
}
var db *goku.MysqlDB = GetDB()
defer db.Close()
qi := goku.SqlQueryInfo{}
qi.Where = "`user_id`=? and `link_id`>?"
qi.Params = []interface{}{userId, lastReadLinkId}
qi.Fields = "count(*)"
tableName := LinkForUser_TableName(userId)
rows, err := db.Select(tableName, qi)
var unreadCount int64
if err != nil {
goku.Logger().Errorln(err.Error())
return 0, err
}
if rows.Next() {
err = rows.Scan(&unreadCount)
if err != nil {
goku.Logger().Errorln(err.Error())
return 0, err
}
}
return unreadCount, nil
}
示例4: setCookieForOtherPlatformUser
//为别的平台用户写cookie
func setCookieForOtherPlatformUser(userId int64, email string, seconds int, ctx *goku.HttpContext) {
//注册成功,写cookie
now := time.Now()
h := md5.New()
h.Write([]byte(fmt.Sprintf("%v-%v", email, now.Unix())))
ticket := fmt.Sprintf("%x_%v", h.Sum(nil), now.Unix())
expires := now.Add(time.Duration(seconds) * time.Second)
redisClient := models.GetRedis()
defer redisClient.Quit()
err := redisClient.Set(ticket, userId)
if err != nil {
goku.Logger().Errorln(err.Error())
} else {
_, err = redisClient.Expireat(ticket, expires.Unix())
if err != nil {
goku.Logger().Errorln(err.Error())
}
c := &http.Cookie{
Name: "_glut",
Value: ticket,
Expires: expires,
Path: "/",
HttpOnly: true,
}
ctx.SetCookie(c)
}
}
示例5: User_GetList
// 获取用户列表.
// @page: 从1开始的页数
// @return: users, total-count, err
func User_GetList(page, pagesize int, order string) ([]User, int64, error) {
var db *goku.MysqlDB = GetDB()
defer db.Close()
page, pagesize = utils.PageCheck(page, pagesize)
qi := goku.SqlQueryInfo{}
qi.Limit = pagesize
qi.Offset = pagesize * page
if order == "" {
qi.Order = "id desc"
} else {
qi.Order = order
}
var users []User
err := db.GetStructs(&users, qi)
if err != nil {
goku.Logger().Errorln(err.Error())
return nil, 0, err
}
total, err := db.Count("user", "")
if err != nil {
goku.Logger().Errorln(err.Error())
}
return users, total, nil
}
示例6: Comment_GetByPage
// @page: 从1开始
// @return: comments, total-count, err
func Comment_GetByPage(page, pagesize int, order string) ([]Comment, int64, error) {
var db *goku.MysqlDB = GetDB()
defer db.Close()
page, pagesize = utils.PageCheck(page, pagesize)
qi := goku.SqlQueryInfo{}
qi.Limit = pagesize
qi.Offset = page * pagesize
if order == "" {
qi.Order = "id desc"
} else {
qi.Order = order
}
var comments []Comment
err := db.GetStructs(&comments, qi)
if err != nil {
goku.Logger().Errorln(err.Error())
return nil, 0, err
}
total, err := db.Count("comment", "")
if err != nil {
goku.Logger().Errorln(err.Error())
}
return comments, total, nil
}
示例7: Topic_GetFollowers
// 获取关注topicId的用户列表
func Topic_GetFollowers(topicId int64, page, pagesize int) ([]User, error) {
var db *goku.MysqlDB = GetDB()
defer db.Close()
page, pagesize = utils.PageCheck(page, pagesize)
qi := goku.SqlQueryInfo{}
qi.Fields = "u.id, u.name, u.email, u.user_pic"
qi.Join = " tf INNER JOIN `user` u ON tf.user_id=u.id"
qi.Where = "tf.topic_id=?"
qi.Params = []interface{}{topicId}
qi.Limit = pagesize
qi.Offset = pagesize * page
qi.Order = "u.id desc"
rows, err := db.Select("topic_follow", qi)
if err != nil {
goku.Logger().Errorln(err.Error())
return nil, err
}
defer rows.Close()
users := make([]User, 0)
for rows.Next() {
user := User{}
err = rows.Scan(&user.Id, &user.Name, &user.Email, &user.UserPic)
if err != nil {
goku.Logger().Errorln(err.Error())
return nil, err
}
users = append(users, user)
}
return users, nil
}
示例8: Topic_SearchByName
func Topic_SearchByName(name string) ([]Topic, error) {
var db *goku.MysqlDB = GetDB()
// db.Debug = true
defer db.Close()
qi := goku.SqlQueryInfo{}
qi.Fields = "`id`,`name`,`name_lower`,`description`,`pic`,`click_count`,`follower_count`,`link_count`"
qi.Where = "name_lower LIKE ?" //"name_lower LIKE '%" + strings.ToLower(name) + "%'"
qi.Params = []interface{}{strings.ToLower(name) + "%"} //"%" +
qi.Limit = 10
qi.Offset = 0
qi.Order = "link_count DESC"
rows, err := db.Select("topic", qi)
topics := make([]Topic, 0)
if err != nil {
goku.Logger().Errorln(err.Error())
return topics, err
}
for rows.Next() {
topic := Topic{}
err = rows.Scan(&topic.Id, &topic.Name, &topic.NameLower, &topic.Description, &topic.Pic, &topic.ClickCount, &topic.FollowerCount, &topic.LinkCount)
if err != nil {
goku.Logger().Errorln(err.Error())
return topics, err
}
topics = append(topics, topic)
}
return topics, nil
}
示例9: linkForUser_AddWithDb
// 减少DB操作
// @t: 推送类型, 1:关注的用户, 2:关注的话题
func linkForUser_AddWithDb(db *goku.MysqlDB, userId, linkId int64, t int) error {
m := map[string]interface{}{
"user_id": userId,
"link_id": linkId,
"create_time": time.Now(),
}
if t == 1 {
m["user_count"] = 1
} else {
m["topic_count"] = 1
}
_, err := db.Insert(LinkForUser_TableName(userId), m)
if err != nil {
if strings.Index(err.Error(), "Duplicate entry") > -1 {
m := map[string]interface{}{}
if t == 1 {
m["user_count"] = 1
} else {
m["topic_count"] = 1
}
_, err = db.Update(LinkForUser_TableName(userId), m, "user_id=? and link_id=?", userId, linkId)
if err != nil {
goku.Logger().Errorln(err.Error())
}
} else {
goku.Logger().Errorln(err.Error())
}
}
return err
}
示例10: Topic_UnFollow
// 用户userId 取消关注 话题topicId
func Topic_UnFollow(userId, topicId int64) (bool, error) {
if userId < 1 || topicId < 1 {
return false, errors.New("参数错误")
}
var db *goku.MysqlDB = GetDB()
defer db.Close()
r, err := db.Delete("topic_follow", "`user_id`=? AND `topic_id`=?", userId, topicId)
if err != nil {
goku.Logger().Errorln(err.Error())
return false, err
}
var afrow int64
afrow, err = r.RowsAffected()
if err != nil {
goku.Logger().Errorln(err.Error())
return false, err
}
if afrow > 0 {
// 取消关注话题成功,将话题的链接从用户的推送列表中移除
LinkForUser_UnFollowTopic(userId, topicId)
// 更新用户关注话题的数量
User_IncCount(db, userId, "ftopic_count", -1)
// 更新话题的关注用户数
Topic_IncCount(db, topicId, "follower_count", -1)
return true, nil
}
return false, nil
}
示例11: User_CheckRelationship
// 检查 mUserId 与 sUserId 的关系,
// return:
// @isFollower: sUserId是否关注mUserId
// @isFollowed: mUserId是否关注sUserId
// @isFriend: 是否互相关注
func User_CheckRelationship(mUserId, sUserId int64) (isFollower, isFollowed, isFriend bool) {
var db *goku.MysqlDB = GetDB()
defer db.Close()
rows, err := db.Query("select * from `user_follow` where `user_id`=? and `follow_id`=? limit 1",
mUserId, sUserId)
if err != nil {
goku.Logger().Errorln(err.Error())
return
}
defer rows.Close()
if rows.Next() {
isFollowed = true
}
rows1, err1 := db.Query("select * from `user_follow` where `user_id`=? and `follow_id`=? limit 1",
sUserId, mUserId)
if err1 != nil {
goku.Logger().Errorln(err1.Error())
return
}
defer rows1.Close()
if rows1.Next() {
isFollower = true
}
if isFollowed && isFollower {
isFriend = true
}
return
}
示例12: User_SearchByName
//模糊搜索用户
func User_SearchByName(name string, ctx *goku.HttpContext) ([]*VUser, error) {
var db *goku.MysqlDB = GetDB()
defer db.Close()
qi := goku.SqlQueryInfo{}
qi.Fields = "`id`,`name`,`email`,`description`,`user_pic`,`friend_count`,`topic_count`,`ftopic_count`,`status`,`follower_count`,`link_count`,`create_time`"
qi.Where = "name_lower LIKE ?"
qi.Params = []interface{}{strings.ToLower(name) + "%"}
qi.Limit = 10
qi.Offset = 0
qi.Order = "link_count DESC"
rows, err := db.Select("user", qi)
if err != nil {
goku.Logger().Errorln(err.Error())
return nil, err
}
users := make([]User, 0)
for rows.Next() {
user := User{}
err = rows.Scan(&user.Id, &user.Name, &user.Email, &user.Description, &user.UserPic, &user.FriendCount, &user.TopicCount, &user.FtopicCount, &user.Status, &user.FollowerCount, &user.LinkCount, &user.CreateTime)
if err != nil {
goku.Logger().Errorln(err.Error())
return nil, err
}
users = append(users, user)
}
return User_ToVUsers(users, ctx), nil
}
示例13: User_GetFollowTopics
// 获取用户关注的话题列表
func User_GetFollowTopics(userId int64, page, pagesize int) ([]Topic, error) {
var db *goku.MysqlDB = GetDB()
defer db.Close()
page, pagesize = utils.PageCheck(page, pagesize)
qi := goku.SqlQueryInfo{}
qi.Fields = "t.id, t.name, t.description, t.pic"
qi.Join = " tf INNER JOIN `topic` t ON tf.topic_id=t.id"
qi.Where = "tf.user_id=?"
qi.Params = []interface{}{userId}
qi.Limit = pagesize
qi.Offset = pagesize * page
qi.Order = "t.id desc"
rows, err := db.Select("topic_follow", qi)
if err != nil {
goku.Logger().Errorln(err.Error())
return nil, err
}
defer rows.Close()
topics := make([]Topic, 0)
for rows.Next() {
topic := Topic{}
err = rows.Scan(&topic.Id, &topic.Name, &topic.Description, &topic.Pic)
if err != nil {
goku.Logger().Errorln(err.Error())
return nil, err
}
topics = append(topics, topic)
}
return topics, nil
}
示例14: saveLink
func (self *BaseCrawler) saveLink(url, title string) (err error) {
defer func() {
if err != nil {
if strings.Index(err.Error(), "Url已经提交过") > -1 {
goku.Logger().Logln("Crawler saveLink:", err.Error(), url, title)
} else {
goku.Logger().Errorln("Crawler saveLink error:", err.Error(), url, title)
}
}
}()
idCount := len(self.UserIds)
if idCount < 1 {
err = errors.New("no user ids")
return
}
userId := self.UserIds[rand.Int63n(int64(idCount))]
user := models.User_GetById(userId)
if user == nil || user.Id < 1 {
err = errors.New("no selected user")
return
}
if strings.Index(url, "news.dbanotes.net") > 0 {
return nil
}
// 移除多余的字符
if strings.LastIndex(title, ")") == len(title)-1 && strings.Index(title, " (") > 0 {
title = title[0:strings.LastIndex(title, " (")]
}
topics := []string{}
ltitle := strings.ToLower(title)
for i := 0; i < lenTopTopics; i++ {
if strings.Index(ltitle, topTopics[i].NameLower) > -1 {
if len(topTopics[i].Name) > 1 {
topics = append(topics, topTopics[i].Name)
}
}
}
m := map[string]string{
"title": title,
"context": url,
"topics": strings.Join(topics, ","),
}
f := forms.CreateLinkSubmitForm()
f.FillByMap(m)
success, linkId, errMsg, _ := models.Link_SaveForm(f, user.Id, false)
if success {
go controllers.AddLinkForSearch(0, f.CleanValues(), linkId, user.Name) //contextType:0: url, 1:文本 TODO:
} else {
err = errors.New(strings.Join(errMsg, ", "))
return
}
return nil
}
示例15: Topic_SaveTopics
// 保持topic到数据库,同时建立topic与link的关系表
// 如果topic已经存在,则直接建立与link的关联
// 全部成功则返回true
func Topic_SaveTopics(topics string, linkId int64) bool {
if topics == "" {
return true
}
var db *goku.MysqlDB = GetDB()
defer db.Close()
success := true
topicList := strings.Split(topics, ",")
for _, topic := range topicList {
topicLower := strings.ToLower(topic)
t := new(Topic)
err := db.GetStruct(t, "`name_lower`=?", topic)
if err != nil {
goku.Logger().Logln(topic)
goku.Logger().Errorln(err.Error())
success = false
continue
}
if t.Id < 1 {
t.Name = topic
t.NameLower = topicLower
_, err = db.InsertStruct(t)
if err != nil {
goku.Logger().Errorln(err.Error())
success = false
continue
}
}
if t.Id > 0 && linkId > 0 {
_, err = db.Insert("topic_link", map[string]interface{}{"topic_id": t.Id, "link_id": linkId})
if err != nil {
goku.Logger().Errorln(err.Error())
success = false
} else {
// 成功,更新话题的链接数量统计
Topic_IncCount(db, t.Id, "link_count", 1)
redisClient := GetRedis()
defer redisClient.Quit()
// 加入推送队列
// 格式: pushtype,topicid,linkid,timestamp
qv := fmt.Sprintf("%v,%v,%v,%v", LinkForUser_ByTopic, t.Id, linkId, time.Now().Unix())
_, err = redisClient.Lpush(golink.KEY_LIST_PUSH_TO_USER, qv)
if err != nil {
goku.Logger().Errorln(err.Error())
}
}
}
}
return success
}