Skip to content

Commit

Permalink
add custom user agent
Browse files Browse the repository at this point in the history
  • Loading branch information
caguiclajmg committed Sep 6, 2022
1 parent 3652109 commit d006062
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"github.com/mitchellh/mapstructure"
)

var CLIENT_VERSION = "0.7.1"

type Response struct {
Success bool `json:"success"`
Error string `json:"error"`
Expand Down Expand Up @@ -197,7 +199,10 @@ func (client *Client) get(path string, params map[string]string, auth bool) (*js
newParams[key] = elem
}

return client.do(http.MethodGet, path, newParams, nil, nil)
headers := map[string]string{}
headers["User-Agent"] = fmt.Sprintf("tensordock-cli/%v", CLIENT_VERSION)

return client.do(http.MethodGet, path, newParams, headers, nil)
}

func (client *Client) post(path string, body map[string]string, auth bool) (*json.RawMessage, error) {
Expand All @@ -212,11 +217,15 @@ func (client *Client) post(path string, body map[string]string, auth bool) (*jso
newBody.Add(key, elem)
}

headers := map[string]string{}
headers["User-Agent"] = fmt.Sprintf("tensordock-cli/%v", CLIENT_VERSION)
headers["Content-Type"] = "application/x-www-form-urlencoded"

return client.do(
http.MethodPost,
path,
nil,
map[string]string{"Content-Type": "application/x-www-form-urlencoded"},
headers,
[]byte(newBody.Encode()),
)
}
Expand Down

0 comments on commit d006062

Please sign in to comment.