forked from ConvertAPI/convertapi-library-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.go
42 lines (37 loc) · 830 Bytes
/
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
package convertapi
import (
"encoding/json"
"fmt"
"github.com/ConvertAPI/convertapi-go/config"
"github.com/ConvertAPI/convertapi-go/lib"
"net/url"
)
type User struct {
Active bool
ApiKey int
Email string
FullName string
SecondsLeft int
Secret string
Status string
}
func UserInfo(conf *config.Config) (user *User, err error) {
if conf == nil {
conf = config.Default
}
query := url.Values{}
query.Add("secret", conf.Secret)
path := fmt.Sprintf("/user?%s", query.Encode())
pathURL, err := url.Parse(path)
if err != nil {
return
}
userURL := conf.BaseURL.ResolveReference(pathURL)
resp, err := lib.RespExtractErr(conf.HttpClient.Get(userURL.String()))
if err == nil {
defer resp.Body.Close()
user = &User{}
err = json.NewDecoder(resp.Body).Decode(user)
}
return
}