本文整理匯總了Golang中github.com/ginuerzh/sports/models.RedisLogger類的典型用法代碼示例。如果您正苦於以下問題:Golang RedisLogger類的具體用法?Golang RedisLogger怎麽用?Golang RedisLogger使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了RedisLogger類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: loginHandlerV2
func loginHandlerV2(request *http.Request, resp http.ResponseWriter,
redis *models.RedisLogger, form loginFormV2) {
user := &models.Account{}
if exists, _ := models.CheckUserExists(form.Id, form.Type); !exists {
writeResponse(request.RequestURI, resp,
nil, errors.NewError(errors.AuthError, "該用戶還未注冊"))
return
}
user.FindPass(form.Id, form.Type, Md5(form.Password))
if len(user.Id) == 0 {
writeResponse(request.RequestURI, resp,
nil, errors.NewError(errors.AuthError))
return
}
if user.TimeLimit < 0 {
writeResponse(request.RequestURI, resp,
nil, errors.NewError(errors.AuthError, "賬戶已禁用"))
return
}
token := Uuid() + "-" + strconv.FormatInt(time.Now().AddDate(0, 0, 30).Unix(), 10)
redis.SetOnlineUser(token, user.Id)
data := map[string]interface{}{
"access_token": token,
"userid": user.Id,
//"last_login_time": user.LastLogin.Unix(),
}
writeResponse(request.RequestURI, resp, data, nil)
}
示例2: userInfoHandler
func userInfoHandler(request *http.Request, resp http.ResponseWriter,
redis *models.RedisLogger, p Parameter) {
user := &models.Account{}
form := p.(getInfoForm)
if find, err := user.FindByUserid(form.Userid); !find {
if err == nil {
err = errors.NewError(errors.NotExistsError)
}
writeResponse(request.RequestURI, resp, nil, err)
return
}
info := convertUser(user, redis)
//info.Pet = userPet(info.Props.Level)
info.ScoreRank, _ = user.PropIndex("score", user.Props.Score)
if uid := redis.OnlineUser(p.TokenId()); len(uid) > 0 {
relation := redis.Relationship(uid, user.Id)
switch relation {
case models.RelFriend:
info.Relation = "FRIENDS"
case models.RelFollowing:
info.Relation = "ATTENTION"
case models.RelFollower:
info.Relation = "FANS"
case models.RelBlacklist:
info.Relation = "DEFRIEND"
}
}
writeResponse(request.RequestURI, resp, info, nil)
}
示例3: setGroupHandler
func setGroupHandler(request *http.Request, resp http.ResponseWriter,
redis *models.RedisLogger, user *models.Account, p Parameter) {
form := p.(setGroupForm)
group := &models.Group{
Gid: form.Id,
Name: form.Name,
Profile: form.Profile,
Desc: form.Desc,
Creator: user.Id,
Time: time.Now(),
}
if form.Address.String() != "" {
group.Addr = &form.Address
loc := models.Addr2Loc(form.Address)
group.Loc = &loc
}
var err error
if len(form.Id) == 0 {
err = group.Save()
if err == nil {
redis.JoinGroup(user.Id, group.Gid, true)
}
} else {
err = group.Update()
}
writeResponse(request.RequestURI, resp, map[string]string{"group_id": group.Gid}, err)
}
示例4: regHandlerV2
func regHandlerV2(request *http.Request, resp http.ResponseWriter,
redis *models.RedisLogger, form regFormV2) {
exists, err := models.CheckUserExists(form.Id, form.Type)
if err != nil {
writeResponse(request.RequestURI, resp,
nil, errors.NewError(errors.DbError))
return
}
if exists {
writeResponse(request.RequestURI, resp,
nil, errors.NewError(errors.UserExistError))
return
}
dbw, err := getNewWallet()
if err != nil {
writeResponse(request.RequestURI, resp,
nil, errors.NewError(errors.DbError, "創建錢包失敗"))
return
}
user := &models.Account{
Role: form.Type,
Password: Md5(form.Password),
Nickname: form.Nickname,
Profile: form.Profile,
Gender: form.Gender,
Birth: form.Birthday,
Wallet: *dbw,
RegTime: time.Now(),
}
switch form.Type {
case models.AccountPhone:
user.Phone = form.Id
case models.AccountWeibo:
user.Weibo = form.Id
case models.AccountEmail:
fallthrough
default:
user.Email = form.Id
}
if err := user.Save(); err != nil {
writeResponse(request.RequestURI, resp, nil, err)
return
}
token := Uuid() + "-" + strconv.FormatInt(time.Now().AddDate(0, 0, 30).Unix(), 10)
data := map[string]string{"access_token": token, "userid": user.Id}
writeResponse(request.RequestURI, resp, data, nil)
redis.LogRegister(user.Id, form.Type)
redis.SetOnlineUser(token, user.Id)
// ws push
//regNotice(user.Id, redis)
}
示例5: checkTokenHandler
func checkTokenHandler(c martini.Context, p Parameter, redis *models.RedisLogger, r *http.Request, w http.ResponseWriter) {
uid := redis.OnlineUser(p.TokenId())
if len(uid) == 0 {
writeResponse(r.RequestURI, w, nil, errors.NewError(errors.AccessError))
}
fmt.Println("===", p.TokenId(), uid)
c.Map(&models.Account{Id: uid})
}
示例6: blacklistHandler
func blacklistHandler(request *http.Request, resp http.ResponseWriter,
redis *models.RedisLogger, user *models.Account, p Parameter) {
form := p.(relationshipForm)
redis.SetRelationship(user.Id, form.Userids, models.RelBlacklist, form.Blacklist)
writeResponse(request.RequestURI, resp, map[string]interface{}{"ExpEffect": Awards{}}, nil)
}
示例7: getUserId
/*
func (this loginForm) getUserId() string {
return this.Userid
}
*/
func weiboLogin(uid, password string, redis *models.RedisLogger) (bool, *models.Account, error) {
user := &models.Account{}
exists, err := user.FindByWeibo(strings.ToLower(uid))
if err != nil {
return false, nil, err
}
p := Md5(password)
registered := user.RegTime.Unix() > 0
if registered {
if user.Password != p {
user.SetPassword(p)
}
return false, user, nil
}
weiboUser, err := GetWeiboUserInfo(uid, password)
if err != nil {
return false, nil, err
}
user.Nickname = weiboUser.ScreenName
if find, _ := user.Exists("nickname"); find {
user.Nickname = "wb_" + user.Nickname
}
user.Password = p
if !strings.HasPrefix(weiboUser.Gender, "f") {
user.Gender = "male"
} else {
user.Gender = "female"
}
user.Weibo = uid
user.Url = weiboUser.Url
user.Profile = weiboUser.Avatar
//user.Addr = &models.Address{Desc: weiboUser.Location}
user.About = weiboUser.Description
user.Role = models.AccountWeibo
user.RegTime = time.Now()
dbw, err := getNewWallet()
if err != nil {
return true, nil, err
}
user.Wallet = *dbw
if !exists {
if err := user.Save(); err != nil {
return true, nil, err
}
}
redis.LogRegister(user.Id, user.Role)
// ws push
regNotice(user.Id, redis)
return true, user, nil
}
示例8: userAuthRequestHandler
func userAuthRequestHandler(r *http.Request, w http.ResponseWriter,
redis *models.RedisLogger, user *models.Account, p Parameter) {
form := p.(authRequestForm)
err := user.SetAuthInfo(form.Type, form.Images, form.Desc)
redis.AddAuthCoach(user.Id)
writeResponse(r.RequestURI, w, nil, err)
}
示例9: logoutHandler
func logoutHandler(request *http.Request, resp http.ResponseWriter,
redis *models.RedisLogger, user *models.Account, p Parameter) {
redis.DelOnlineUser(p.TokenId())
if len(user.Devs) > 0 {
user.RmDevice(user.Devs[0])
}
writeResponse(request.RequestURI, resp, nil, nil)
}
示例10: checkToken
func checkToken(r *models.RedisLogger, t string) (valid bool, err error) {
uid := r.OnlineUser(t)
if len(uid) == 0 {
err = errors.NewError(errors.AccessError)
valid = false
return
}
valid = true
return
}
示例11: friendCountHandler
func friendCountHandler(request *http.Request, resp http.ResponseWriter,
redis *models.RedisLogger, user *models.Account) {
follows, followers, friends, blacklist := redis.FriendCount(user.Id)
respData := map[string]int{
"friend_count": friends,
"attention_count": follows,
"fans_count": followers,
"defriend_count": blacklist,
}
writeResponse(request.RequestURI, resp, respData, nil)
}
示例12: getQiniuTokenHandler
func getQiniuTokenHandler(r *http.Request, w http.ResponseWriter,
redis *models.RedisLogger) {
token := redis.GetQiniuUpToken()
//log.Println(token)
if len(token) == 0 {
token = uptoken("test")
redis.SetQiniuUpToken(token)
}
writeResponse(r.RequestURI, w, map[string]string{"token": token}, nil)
}
示例13: articleNewsHandler
func articleNewsHandler(r *http.Request, w http.ResponseWriter,
redis *models.RedisLogger, user *models.Account, p Parameter) {
form := p.(articleNewsForm)
followings := redis.Friends(models.RelFollowing, user.Id)
//followings = append(followings, user.Id) // self included
//fmt.Println(followings)
count, err := models.NewArticles(followings, form.Id)
writeResponse(r.RequestURI, w, bson.M{"count": count}, err)
}
示例14: retentionHandler
func retentionHandler(w http.ResponseWriter, redis *models.RedisLogger, form retentionForm) {
if ok, err := checkToken(redis, form.Token); !ok {
writeResponse(w, err)
return
}
date := time.Now()
if form.Date > 0 {
date = time.Unix(form.Date, 0)
}
r := redis.Retention(date)
writeResponse(w, map[string]interface{}{"retention": r})
}
示例15: taskReferralsHandler
func taskReferralsHandler(r *http.Request, w http.ResponseWriter,
redis *models.RedisLogger, user *models.Account) {
if user.Taskid > len(models.NewTasks) {
writeResponse(r.RequestURI, w, nil, errors.NewError(errors.AccessError))
return
}
task := models.NewTasks[user.Taskid]
excludes := redis.TaskSharers()
friends := redis.Friends(models.RelFriend, user.Id)
excludes = append(excludes, user.Id)
excludes = append(excludes, friends...)
users, _ := user.TaskReferrals(task.Type, excludes)
var referrals []*referral
for i, _ := range users {
ref := &referral{
Userid: users[i].Id,
Nickname: users[i].Nickname,
Profile: users[i].Profile,
Gender: users[i].Gender,
Images: users[i].Photos,
Birthday: users[i].Birth,
Lastlog: users[i].LastLogin.Unix(),
Location: users[i].Loc,
}
if users[i].Ratios.RunRecv > 0 {
ref.RunRatio = float32(users[i].Ratios.RunAccept) / float32(users[i].Ratios.RunRecv)
}
if users[i].Ratios.PostRecv > 0 {
ref.PostRatio = float32(users[i].Ratios.PostAccept) / float32(users[i].Ratios.PostRecv)
}
if users[i].Ratios.PKRecv > 0 {
ref.PkRatio = float32(users[i].Ratios.PKAccept) / float32(users[i].Ratios.PKRecv)
}
if task.Type == models.TaskRunning || task.Type == models.TaskGame {
rec, _ := users[i].LastRecord("run")
ref.LastId = rec.Id.Hex()
ref.LastTime = rec.PubTime.Unix()
} else if task.Type == models.TaskPost {
article := users[i].LatestArticle()
ref.LastId = article.Id.Hex()
ref.LastTime = article.PubTime.Unix()
}
referrals = append(referrals, ref)
}
respData := map[string]interface{}{"referrals": referrals}
writeResponse(r.RequestURI, w, respData, nil)
}