initialize.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * @Author: lwnmengjing
  3. * @Date: 2021/6/10 3:39 下午
  4. * @Last Modified by: lwnmengjing
  5. * @Last Modified time: 2021/6/10 3:39 下午
  6. */
  7. package storage
  8. import (
  9. "log"
  10. "github.com/go-admin-team/go-admin-core/sdk"
  11. "github.com/go-admin-team/go-admin-core/sdk/config"
  12. "github.com/go-admin-team/go-admin-core/sdk/pkg/captcha"
  13. )
  14. // Setup 配置storage组件
  15. func Setup() {
  16. //4. 设置缓存
  17. cacheAdapter, err := config.CacheConfig.Setup()
  18. if err != nil {
  19. log.Fatalf("cache setup error, %s\n", err.Error())
  20. }
  21. sdk.Runtime.SetCacheAdapter(cacheAdapter)
  22. //5. 设置验证码store
  23. captcha.SetStore(captcha.NewCacheStore(cacheAdapter, 600))
  24. //6. 设置队列
  25. if !config.QueueConfig.Empty() {
  26. if q := sdk.Runtime.GetQueueAdapter(); q != nil {
  27. q.Shutdown()
  28. }
  29. queueAdapter, err := config.QueueConfig.Setup()
  30. if err != nil {
  31. log.Fatalf("queue setup error, %s\n", err.Error())
  32. }
  33. sdk.Runtime.SetQueueAdapter(queueAdapter)
  34. defer func() {
  35. go queueAdapter.Run()
  36. }()
  37. }
  38. //7. 设置分布式锁
  39. if !config.LockerConfig.Empty() {
  40. lockerAdapter, err := config.LockerConfig.Setup()
  41. if err != nil {
  42. log.Fatalf("locker setup error, %s\n", err.Error())
  43. }
  44. sdk.Runtime.SetLockerAdapter(lockerAdapter)
  45. }
  46. }