本文整理汇总了Golang中github.com/QLeelulu/goku.MysqlDB.GetStruct方法的典型用法代码示例。如果您正苦于以下问题:Golang MysqlDB.GetStruct方法的具体用法?Golang MysqlDB.GetStruct怎么用?Golang MysqlDB.GetStruct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/QLeelulu/goku.MysqlDB
的用法示例。
在下文中一共展示了MysqlDB.GetStruct方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: User_GetByTicket
func User_GetByTicket(ticket string) (*User, error) {
redisClient := GetRedis()
defer redisClient.Quit()
id, err := redisClient.Get(ticket)
if err != nil {
return nil, err
}
if id.String() == "" {
return nil, nil
}
var db *goku.MysqlDB = GetDB()
defer db.Close()
var user *User = new(User)
err = db.GetStruct(user, "id=?", id.String())
if err != nil {
fmt.Printf("err: %v\n", err)
return nil, err
}
if user.Id > 0 {
return user, nil
}
return nil, nil
}
示例2: GetTodo
func GetTodo(id int) (Todo, error) {
var db *goku.MysqlDB = GetDB()
defer db.Close()
var todo Todo = Todo{}
err := db.GetStruct(&todo, "id=?", id)
return todo, err
}
示例3: 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
}
示例4: User_GetById
func User_GetById(id int64) *User {
var db *goku.MysqlDB = GetDB()
defer db.Close()
u := new(User)
err := db.GetStruct(u, "id=?", id)
if err != nil {
goku.Logger().Errorln(err.Error())
}
if u.Id > 0 {
return u
}
return nil
}
示例5: Topic_GetById
func Topic_GetById(id int64) (*Topic, error) {
var db *goku.MysqlDB = GetDB()
defer db.Close()
t := new(Topic)
err := db.GetStruct(t, "`id`=?", id)
if err != nil || t.Id == 0 {
if err != nil {
goku.Logger().Errorln(err.Error())
}
t = nil
}
return t, err
}
示例6: Topic_GetByName
func Topic_GetByName(name string) (*Topic, error) {
var db *goku.MysqlDB = GetDB()
defer db.Close()
t := new(Topic)
err := db.GetStruct(t, "`name`=?", strings.ToLower(name))
if err != nil || t.Id == 0 {
if err != nil {
goku.Logger().Errorln(err.Error())
}
t = nil
}
return t, err
}
示例7: Comment_GetById
func Comment_GetById(id int64) (*Comment, error) {
var db *goku.MysqlDB = GetDB()
defer db.Close()
c := new(Comment)
err := db.GetStruct(c, "id=?", id)
if err != nil {
goku.Logger().Errorln(err.Error())
return nil, err
}
if c.Id > 0 {
return c, nil
}
return nil, nil
}
示例8: Link_GetById
func Link_GetById(id int64) (*Link, error) {
var db *goku.MysqlDB = GetDB()
defer db.Close()
l := new(Link)
err := db.GetStruct(l, "id=?", id)
if err != nil {
goku.Logger().Errorln(err.Error())
return nil, err
}
if l.Id > 0 {
return l, nil
}
return nil, nil
}
示例9: User_GetByName
func User_GetByName(name string) (*User, error) {
var db *goku.MysqlDB = GetDB()
defer db.Close()
u := new(User)
err := db.GetStruct(u, "name_lower=?", strings.ToLower(name))
if err != nil {
goku.Logger().Errorln(err.Error())
return nil, err
}
if u.Id > 0 {
return u, nil
}
return nil, nil
}
示例10: Link_GetByUrl
// url不区分大小写
func Link_GetByUrl(url string) (*Link, error) {
var db *goku.MysqlDB = GetDB()
defer db.Close()
l := new(Link)
urlMd5 := utils.MD5_16(strings.ToLower(url))
err := db.GetStruct(l, "context_md5=? and `status`<>2 order by comment_count desc", urlMd5)
if err != nil {
goku.Logger().Errorln(err.Error())
return nil, err
}
if l.Id > 0 {
return l, nil
}
return nil, nil
}
示例11: VerifyInviteKey
//验证邀请码
func VerifyInviteKey(key string) *RegisterInvite {
if !golink.Invite_Enabled {
return new(RegisterInvite)
}
if len(key) != golink.Genetic_Key_Len {
return nil
}
var db *goku.MysqlDB = GetDB()
defer db.Close()
ri := new(RegisterInvite)
err := db.GetStruct(ri, "`Guid`=? AND `expired_date`>=? AND `is_register`=0", key, time.Now())
if err != nil {
goku.Logger().Errorln(err.Error())
return nil
}
if len(ri.Guid) > 0 {
return ri
}
return nil
}