From ec5c0495c9a19fd24d232fa76ab1c6abb20b6e32 Mon Sep 17 00:00:00 2001 From: Minh Doan Date: Tue, 8 Jan 2019 15:40:45 -0800 Subject: [PATCH] refactor singleton --- internal/utils/singleton.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/utils/singleton.go b/internal/utils/singleton.go index 55e44193e..c67da712f 100644 --- a/internal/utils/singleton.go +++ b/internal/utils/singleton.go @@ -14,19 +14,19 @@ type UniqueValidatorID struct { uniqueID uint32 } -var instance *UniqueValidatorID +var validatorIDInstance *UniqueValidatorID var logInstance log.Logger -var once sync.Once +var onceForUniqueValidatorID sync.Once var onceForLog sync.Once // GetUniqueValidatorIDInstance returns a singleton instance func GetUniqueValidatorIDInstance() *UniqueValidatorID { - once.Do(func() { - instance = &UniqueValidatorID{ + onceForUniqueValidatorID.Do(func() { + validatorIDInstance = &UniqueValidatorID{ uniqueID: 0, } }) - return instance + return validatorIDInstance } // GetUniqueID returns a unique ID and increment the internal variable