token.go 755 B

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. * @desc:后台token处理
  3. * @company:云南奇讯科技有限公司
  4. * @Author: yixiaohu
  5. * @Date: 2022/3/8 17:10
  6. */
  7. package service
  8. import (
  9. "context"
  10. "github.com/gogf/gf/v2/frame/g"
  11. "github.com/tiger1103/gfast/v3/internal/app/common/model"
  12. commonService "github.com/tiger1103/gfast/v3/internal/app/common/service"
  13. "github.com/tiger1103/gfast/v3/library/liberr"
  14. "sync"
  15. )
  16. var (
  17. options *model.TokenOptions
  18. gT commonService.IGfToken
  19. lock = &sync.Mutex{}
  20. )
  21. func GfToken(ctx context.Context) commonService.IGfToken {
  22. if gT == nil {
  23. lock.Lock()
  24. defer lock.Unlock()
  25. if gT == nil {
  26. err := g.Cfg().MustGet(ctx, "gfToken").Struct(&options)
  27. liberr.ErrIsNil(ctx, err)
  28. gT = commonService.GfToken(options)
  29. }
  30. }
  31. return gT
  32. }