sso.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package sso
  2. import (
  3. "kpt-pasture/config"
  4. operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
  5. "gitee.com/xuyiping_admin/pkg/di"
  6. redisv7 "github.com/go-redis/redis/v7"
  7. )
  8. var Module = di.Provide(NewSSOClient)
  9. type ClientInterface interface {
  10. Auth(userAuth *operationPb.UserAuthData) (string, error)
  11. CacheAuth(token string, res interface{}) error
  12. CacheSetAccount(token string, res interface{}) error
  13. GetAccount(token string) (interface{}, error)
  14. // Permissions(token string) (*Response, error)
  15. // CheckPermission(token, code string) (bool, error)
  16. }
  17. func NewClientLatest(cfg *config.AppConfig) *redisv7.Client {
  18. return initClientLatest(cfg.RedisSetting.CacheRedis.Addr, cfg.RedisSetting.CacheRedis.Requirepass, cfg.RedisSetting.CacheRedis.DB)
  19. }
  20. func initClientLatest(addr, password string, db int, opts ...func(*redisv7.Options)) *redisv7.Client {
  21. option := &redisv7.Options{
  22. Addr: addr,
  23. DB: db,
  24. Password: password,
  25. MaxRetries: 3,
  26. OnConnect: func(cn *redisv7.Conn) error {
  27. return cn.ClientSetName("on_connect").Err()
  28. },
  29. }
  30. for _, opt := range opts {
  31. opt(option)
  32. }
  33. return redisv7.NewClient(option)
  34. }
  35. func NewSSOClient(cfg *config.AppConfig) ClientInterface {
  36. return NewCache(cfg)
  37. }