From b8d4017f5d22a9c385f3e8dd1dc869e1e3a89a06 Mon Sep 17 00:00:00 2001 From: "taekyu.kang" Date: Mon, 23 Oct 2023 12:16:52 +0900 Subject: [PATCH] feature. add set token interface on apiClient. --- pkg/api-client/api-client.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/pkg/api-client/api-client.go b/pkg/api-client/api-client.go index 5b8aa675..6e6c4260 100644 --- a/pkg/api-client/api-client.go +++ b/pkg/api-client/api-client.go @@ -17,6 +17,7 @@ type ApiClient interface { Delete(path string, input interface{}) (out interface{}, err error) Put(path string, input interface{}) (out interface{}, err error) Patch(path string, input interface{}) (out interface{}, err error) + SetToken(token string) } type ApiClientImpl struct { @@ -26,7 +27,7 @@ type ApiClientImpl struct { } // New -func New(host string, token string) (ApiClient, error) { +func NewWithToken(host string, token string) (ApiClient, error) { return &ApiClientImpl{ client: &http.Client{ Timeout: 30 * time.Second, @@ -39,6 +40,23 @@ func New(host string, token string) (ApiClient, error) { }, nil } +func New(host string) (ApiClient, error) { + return &ApiClientImpl{ + client: &http.Client{ + Timeout: 30 * time.Second, + Transport: &http.Transport{ + MaxIdleConns: 10, + }, + }, + url: host, + token: "", + }, nil +} + +func (c *ApiClientImpl) SetToken(token string) { + c.token = token +} + func (c *ApiClientImpl) Get(path string) (out interface{}, err error) { req, err := http.NewRequest("GET", fmt.Sprintf("%s/api/1.0/%s", c.url, path), nil) if err != nil {