Skip to content

Commit ad9bcd6

Browse files
DrMegavolttechknowlogick
authored andcommitted
Add method to set Sudo header (go-gitea#144)
1 parent 600c19a commit ad9bcd6

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Diff for: gitea/gitea.go

+9
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func Version() string {
2323
type Client struct {
2424
url string
2525
accessToken string
26+
sudo string
2627
client *http.Client
2728
}
2829

@@ -40,12 +41,20 @@ func (c *Client) SetHTTPClient(client *http.Client) {
4041
c.client = client
4142
}
4243

44+
// SetSudo sets username to impersonate.
45+
func (c *Client) SetSudo(sudo string) {
46+
c.sudo = sudo
47+
}
48+
4349
func (c *Client) doRequest(method, path string, header http.Header, body io.Reader) (*http.Response, error) {
4450
req, err := http.NewRequest(method, c.url+"/api/v1"+path, body)
4551
if err != nil {
4652
return nil, err
4753
}
4854
req.Header.Set("Authorization", "token "+c.accessToken)
55+
if c.sudo != "" {
56+
req.Header.Set("Sudo", c.sudo)
57+
}
4958
for k, v := range header {
5059
req.Header[k] = v
5160
}

0 commit comments

Comments
 (0)