Skip to content

Commit

Permalink
Merge pull request #165 from openinfradev/api_client
Browse files Browse the repository at this point in the history
feature. add set token interface on apiClient.
  • Loading branch information
seungkyua authored Oct 23, 2023
2 parents 2130b36 + b8d4017 commit 1580951
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion pkg/api-client/api-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand All @@ -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 {
Expand Down

0 comments on commit 1580951

Please sign in to comment.