From eadd54d13f47954190bea93aaff39d881103cf72 Mon Sep 17 00:00:00 2001 From: zhuxianglong <56494565@qq.com> Date: Thu, 16 Jan 2025 00:21:52 +0800 Subject: [PATCH] no message --- sdk/sign.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) 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