From 1fc93af7c402c1a8be33c1166c0f56204ed44286 Mon Sep 17 00:00:00 2001 From: yxh Date: Tue, 8 Mar 2022 23:03:17 +0800 Subject: [PATCH] 20220308 --- internal/app/system/service/token.go | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/internal/app/system/service/token.go b/internal/app/system/service/token.go index 21c74cb..5fe06d4 100644 --- a/internal/app/system/service/token.go +++ b/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 }