本文整理匯總了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
}