diff --git a/sdk/sign.go b/sdk/sign.go index 31863aa..5591071 100644 --- a/sdk/sign.go +++ b/sdk/sign.go @@ -6,6 +6,7 @@ import ( "encoding/json" "sort" "strings" + "sync" ) // Order represents an order object used for signing parameters @@ -35,11 +36,18 @@ type SDK struct { SecretKey string } -// New initializes a new SDK with the given configuration +// Singleton instance and mutex for thread safety +var instance *SDK +var once2 sync.Once + +// New initializes a new SDK with the given configuration, but ensures that only one instance exists. func New(secretKey string) *SDK { - return &SDK{ - SecretKey: secretKey, - } + once2.Do(func() { + instance = &SDK{ + SecretKey: secretKey, + } + }) + return instance } // Md5String generates MD5 hash of a given string