diff --git a/gitea/gitea.go b/gitea/gitea.go index a5509b2..d90a6eb 100644 --- a/gitea/gitea.go +++ b/gitea/gitea.go @@ -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 }