2022-10-06 13:33:04 +00:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
2022-11-07 08:04:13 +00:00
|
|
|
"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) {
|
2022-11-07 08:04:13 +00:00
|
|
|
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 {
|
2022-11-07 08:04:13 +00:00
|
|
|
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
|
|
|
|
}
|