forked from Skarlso/confluence-go-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.go
47 lines (41 loc) · 1.09 KB
/
user.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
package goconfluence
import (
"net/url"
"strings"
)
// getContentEndpoint creates the correct api endpoint by given id
func (a *API) getUserEndpoint(id string) (*url.URL, error) {
return url.ParseRequestURI(a.endPoint.String() + "/user/" + id)
}
// CurrentUser return current user information
func (a *API) CurrentUser() (*User, error) {
ep, err := a.getUserEndpoint("current")
if err != nil {
return nil, err
}
return a.SendUserRequest(ep, "GET")
}
// AnonymousUser return user information for anonymous user
func (a *API) AnonymousUser() (*User, error) {
ep, err := a.getUserEndpoint("anonymous")
if err != nil {
return nil, err
}
return a.SendUserRequest(ep, "GET")
}
// User returns user data for defined query
// query can be accountID or username
func (a *API) User(query string) (*User, error) {
ep, err := a.getUserEndpoint("")
if err != nil {
return nil, err
}
data := url.Values{}
if strings.Contains(query, ":") {
data.Set("accountId", strings.Split(query, ":")[1])
} else {
data.Set("username", query)
}
ep.RawQuery = data.Encode()
return a.SendUserRequest(ep, "GET")
}