You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
705 B
Go
46 lines
705 B
Go
/**
|
|
* @Author: jager
|
|
* @Email: lhj168os@gmail.com
|
|
* @File: cache
|
|
* @Date: 2021/12/20 6:39 下午
|
|
* @package: user
|
|
* @Version: v1.0.0
|
|
*
|
|
* @Description:
|
|
*
|
|
*/
|
|
|
|
package user
|
|
|
|
import (
|
|
"github.com/jageros/hawox/attribute"
|
|
"sync"
|
|
)
|
|
|
|
var users sync.Map
|
|
|
|
func LoadAllUserIntoCache() error {
|
|
attrs, err := attribute.LoadAll("user")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, attr := range attrs {
|
|
u := &User{attr: attr}
|
|
users.Store(attr.GetAttrID(), u)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func GetUser(openId string) (*User, error) {
|
|
u, ok := users.Load(openId)
|
|
if ok {
|
|
return u.(*User), nil
|
|
}
|
|
us, err := newUser(openId)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
users.Store(openId, us)
|
|
return us, nil
|
|
}
|