wp-go/actions/common/users.go

36 lines
850 B
Go
Raw Normal View History

2022-10-06 13:33:04 +00:00
package common
import (
"context"
2022-10-06 13:33:04 +00:00
"github/fthvgb1/wp-go/logs"
"github/fthvgb1/wp-go/models"
2022-11-05 02:32:57 +00:00
"github/fthvgb1/wp-go/models/wp"
2022-10-06 13:33:04 +00:00
"time"
)
2022-11-17 03:22:29 +00:00
func getUserById(a ...any) (r wp.Users, err error) {
ctx := a[0].(context.Context)
2022-11-17 03:22:29 +00:00
uid := a[1].(uint64)
r, err = models.FindOneById[wp.Users](ctx, uid)
2022-10-06 13:33:04 +00:00
return
}
2022-11-17 03:22:29 +00:00
func GetUserByName(ctx context.Context, username string) (wp.Users, error) {
return usersNameCache.GetCache(ctx, username, time.Second, ctx, username)
}
func getUserByName(a ...any) (r wp.Users, err error) {
u := a[1].(string)
ctx := a[0].(context.Context)
r, err = models.FirstOne[wp.Users](ctx, models.SqlBuilder{{
"user_login", u,
}}, "*", nil)
return
}
func GetUserById(ctx context.Context, uid uint64) wp.Users {
r, err := usersCache.GetCache(ctx, uid, time.Second, ctx, uid)
2022-10-06 13:33:04 +00:00
logs.ErrPrintln(err, "get user", uid)
return r
}