-
Notifications
You must be signed in to change notification settings - Fork 0
/
gerrit.go
56 lines (44 loc) · 1.25 KB
/
gerrit.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package gerrit
import (
"net/http"
"time"
)
type Gerrit struct {
Requester *Requester
Access *AccessService
Projects *ProjectService
Changes *ChangeService
Accounts *AccountsService
Groups *GroupsService
Config *ConfigService
}
func NewClient(gerritURL string, httpClient *http.Client) (*Gerrit, error) {
if httpClient == nil {
httpClient = &http.Client{
Timeout: 15 * time.Second, // 设置超时时间
}
}
r := &Requester{client: httpClient}
if baseURL, err := SetBaseURL(gerritURL); err != nil {
return nil, err
} else {
r.baseURL = baseURL
}
gerrit := &Gerrit{Requester: r}
gerrit.Access = &AccessService{gerrit: gerrit}
gerrit.Projects = &ProjectService{gerrit: gerrit}
gerrit.Changes = &ChangeService{gerrit: gerrit}
gerrit.Accounts = &AccountsService{gerrit: gerrit}
gerrit.Groups = &GroupsService{gerrit: gerrit}
gerrit.Config = &ConfigService{gerrit: gerrit}
return gerrit, nil
}
func (g *Gerrit) SetBasicAuth(username, password string) {
g.Requester.SetAuth("basic", username, password)
}
func (g *Gerrit) SetDigestAuth(username, password string) {
g.Requester.SetAuth("digest", username, password)
}
func (g *Gerrit) SetCookieAuth(username, password string) {
g.Requester.SetAuth("cookie", username, password)
}