-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.go
More file actions
43 lines (39 loc) · 1.31 KB
/
client.go
File metadata and controls
43 lines (39 loc) · 1.31 KB
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
package sonarapi
import (
"net/http"
"net/url"
)
type Client struct {
baseURL *url.URL
username, password, token, url string
authType authType
httpClient *http.Client
Hotspots *HotspotsService
Measures *MeasuresService
ProjectBranches *ProjectBranchesService
Projects *ProjectsService
System *SystemService
UserTokens *UserTokensService
Webhooks *WebhooksService
}
func NewClient(endpoint, username, password string) (*Client, error) {
c := &Client{username: username, password: password, authType: basicAuth, httpClient: http.DefaultClient}
if endpoint == "" {
endpoint = defaultBaseURL
}
c.SetBaseURL(endpoint)
c.Hotspots = &HotspotsService{client: c}
c.Measures = &MeasuresService{client: c}
c.ProjectBranches = &ProjectBranchesService{client: c}
c.Projects = &ProjectsService{client: c}
c.System = &SystemService{client: c}
c.UserTokens = &UserTokensService{client: c}
c.Webhooks = &WebhooksService{client: c}
return c, nil
}
func NewClientByToken(endpoint, token string) (*Client, error) {
c, err := NewClient(endpoint, "", "")
c.token = token
c.authType = privateToken
return c, err
}