12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- package sso
- import (
- "kpt-pasture/config"
- operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
- "gitee.com/xuyiping_admin/pkg/di"
- redisv7 "github.com/go-redis/redis/v7"
- )
- var Module = di.Provide(NewSSOClient)
- type ClientInterface interface {
- Auth(userAuth *operationPb.UserAuthData) (string, error)
- CacheAuth(token string, res interface{}) error
- CacheSetAccount(token string, res interface{}) error
- GetAccount(token string) (interface{}, error)
- // Permissions(token string) (*Response, error)
- // CheckPermission(token, code string) (bool, error)
- }
- func NewClientLatest(cfg *config.AppConfig) *redisv7.Client {
- return initClientLatest(cfg.RedisSetting.CacheRedis.Addr, cfg.RedisSetting.CacheRedis.Requirepass, cfg.RedisSetting.CacheRedis.DB)
- }
- func initClientLatest(addr, password string, db int, opts ...func(*redisv7.Options)) *redisv7.Client {
- option := &redisv7.Options{
- Addr: addr,
- DB: db,
- Password: password,
- MaxRetries: 3,
- OnConnect: func(cn *redisv7.Conn) error {
- return cn.ClientSetName("on_connect").Err()
- },
- }
- for _, opt := range opts {
- opt(option)
- }
- return redisv7.NewClient(option)
- }
- func NewSSOClient(cfg *config.AppConfig) ClientInterface {
- return NewCache(cfg)
- }
|