yxh hace 4 años
padre
commit
1fc93af7c4
Se han modificado 1 ficheros con 16 adiciones y 10 borrados
  1. 16 10
      internal/app/system/service/token.go

+ 16 - 10
internal/app/system/service/token.go

@@ -16,21 +16,27 @@ import (
 	"sync"
 )
 
-var (
+type gft struct {
 	options *model.TokenOptions
 	gT      commonService.IGfToken
-	lock    = &sync.Mutex{}
-)
+	lock    *sync.Mutex
+}
+
+var gftService = &gft{
+	options: nil,
+	gT:      nil,
+	lock:    &sync.Mutex{},
+}
 
 func GfToken(ctx context.Context) commonService.IGfToken {
-	if gT == nil {
-		lock.Lock()
-		defer lock.Unlock()
-		if gT == nil {
-			err := g.Cfg().MustGet(ctx, "gfToken").Struct(&options)
+	if gftService.gT == nil {
+		gftService.lock.Lock()
+		defer gftService.lock.Unlock()
+		if gftService.gT == nil {
+			err := g.Cfg().MustGet(ctx, "gfToken").Struct(&gftService.options)
 			liberr.ErrIsNil(ctx, err)
-			gT = commonService.GfToken(options)
+			gftService.gT = commonService.GfToken(gftService.options)
 		}
 	}
-	return gT
+	return gftService.gT
 }