Add method to set Sudo header (#144)
This commit is contained in:
parent
600c19aa03
commit
ad9bcd6a96
1 changed files with 9 additions and 0 deletions
|
@ -23,6 +23,7 @@ func Version() string {
|
|||
type Client struct {
|
||||
url string
|
||||
accessToken string
|
||||
sudo string
|
||||
client *http.Client
|
||||
}
|
||||
|
||||
|
@ -40,12 +41,20 @@ func (c *Client) SetHTTPClient(client *http.Client) {
|
|||
c.client = client
|
||||
}
|
||||
|
||||
// SetSudo sets username to impersonate.
|
||||
func (c *Client) SetSudo(sudo string) {
|
||||
c.sudo = sudo
|
||||
}
|
||||
|
||||
func (c *Client) doRequest(method, path string, header http.Header, body io.Reader) (*http.Response, error) {
|
||||
req, err := http.NewRequest(method, c.url+"/api/v1"+path, body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("Authorization", "token "+c.accessToken)
|
||||
if c.sudo != "" {
|
||||
req.Header.Set("Sudo", c.sudo)
|
||||
}
|
||||
for k, v := range header {
|
||||
req.Header[k] = v
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue