From 466fa48adb3cc55eb7b0dae35e0bab650a0d076e Mon Sep 17 00:00:00 2001
From: Eric <xplzv@126.com>
Date: Wed, 24 Apr 2019 15:52:07 +0800
Subject: [PATCH] add authclient for needauth request

---
 pkg/sdk/client.go     | 46 +++++++++++++++++++++----------------------
 pkg/service/assets.go |  2 +-
 pkg/service/init.go   |  5 +++++
 3 files changed, 28 insertions(+), 25 deletions(-)
 create mode 100644 pkg/service/init.go

diff --git a/pkg/sdk/client.go b/pkg/sdk/client.go
index 17f2852..7c41ed1 100644
--- a/pkg/sdk/client.go
+++ b/pkg/sdk/client.go
@@ -51,37 +51,35 @@ func (c *WrapperClient) Get(url string, res interface{}, needAuth bool) error {
 }
 
 func (c *WrapperClient) Post(url string, data interface{}, res interface{}, needAuth bool) error {
-	//if needAuth {
-	//	c.Http.SetAuth(c.Auth.Sign())
-	//} else {
-	//	c.Http.SetAuth("")
-	//}
-	return c.Http.Post(url, data, res)
+	if needAuth {
+		return c.AuthClient.Post(url, data, res)
+	} else {
+		return c.Http.Post(url, data, res)
+	}
 }
 
 func (c *WrapperClient) Delete(url string, res interface{}, needAuth bool) error {
-	//if needAuth {
-	//	c.Http.SetAuth(c.Auth.Sign())
-	//} else {
-	//	c.Http.SetAuth("")
-	//}
-	return c.Http.Delete(url, res)
+	if needAuth {
+		return c.AuthClient.Delete(url, res)
+	} else {
+		return c.Http.Delete(url, res)
+	}
 }
 
 func (c *WrapperClient) Put(url string, data interface{}, res interface{}, needAuth bool) error {
-	//if needAuth {
-	//	c.Http.SetAuth(c.Auth.Sign())
-	//} else {
-	//	c.Http.SetAuth("")
-	//}
-	return c.Http.Put(url, data, res)
+	if needAuth {
+		return c.AuthClient.Put(url, data, res)
+	} else {
+		return c.Http.Put(url, data, res)
+	}
+
 }
 
 func (c *WrapperClient) Patch(url string, data interface{}, res interface{}, needAuth bool) error {
-	//if needAuth {
-	//	c.Http.SetAuth(c.Auth.Sign())
-	//} else {
-	//	c.Http.SetAuth("")
-	//}
-	return c.Http.Patch(url, data, res)
+	if needAuth {
+		return c.AuthClient.Patch(url, data, res)
+	} else {
+		return c.Http.Patch(url, data, res)
+	}
+
 }
diff --git a/pkg/service/assets.go b/pkg/service/assets.go
index 52508ba..5ff5503 100644
--- a/pkg/service/assets.go
+++ b/pkg/service/assets.go
@@ -13,7 +13,7 @@ func GetSystemUserAssetAuthInfo(systemUserID, assetID string) (info sdk.SystemUs
 func GetSystemUserAuthInfo(systemUserID string) (info sdk.SystemUserAuthInfo) {
 	Url := fmt.Sprintf(sdk.SystemUserAuthInfoURL, systemUserID)
 
-	err := Client.Get(Url, &info, true)
+	err := client.Get(Url, &info, true)
 	if err != nil {
 		logger.Error("Get system user auth info failed")
 	}
diff --git a/pkg/service/init.go b/pkg/service/init.go
new file mode 100644
index 0000000..034a871
--- /dev/null
+++ b/pkg/service/init.go
@@ -0,0 +1,5 @@
+package service
+
+import "cocogo/pkg/sdk"
+
+var client = sdk.WrapperClient{}
-- 
2.18.0