...
1 package client
2
3 import (
4 "fmt"
5 "net/http"
6 "net/url"
7 "time"
8
9 "github.com/shurcooL/graphql"
10 )
11
12
13 type Option = func(c *EdgeClient)
14
15
16 func WithGraphqlClient(cl *graphql.Client) Option {
17 return func(c *EdgeClient) {
18 c.Client = cl
19 }
20 }
21
22
23
24
25
26
27
28
29
30
31 func WithHTTPClient(cl *http.Client) Option {
32 return func(c *EdgeClient) {
33 c.HTTPClient = cl
34 }
35 }
36
37
38 func WithUserAgent(userAgent string) Option {
39 return func(c *EdgeClient) {
40 c.userAgent = userAgent
41 }
42 }
43
44
45 func WithVersion(version string) Option {
46 return func(c *EdgeClient) {
47 c.version = version
48 }
49 }
50
51
52
53 func WithBaseURL(apiURL string) Option {
54 return func(c *EdgeClient) {
55 baseURL, err := url.Parse(apiURL)
56 if err != nil {
57 panic(err)
58 }
59 c.BaseURL = baseURL
60 }
61 }
62
63
64
65 func WithTotp(token string) Option {
66 return func(c *EdgeClient) {
67 c.totpToken = token
68 c.headers[authorizationHeader] = fmt.Sprintf("%s %s", totpToken, token)
69 }
70 }
71
72
73
74 func WithBearerToken(token string) Option {
75 return func(c *EdgeClient) {
76 c.bearerToken = token
77 c.headers[authorizationHeader] = fmt.Sprintf("%s %s", bearerToken, token)
78 }
79 }
80
81
82
83 func WithCredentials(username, password, organization string) Option {
84 return func(c *EdgeClient) {
85 c.loginCredentials = &LoginRequest{
86 Username: username,
87 Password: password,
88 Organization: organization,
89 }
90 }
91 }
92
93
94 func WithTimeout(timeout time.Duration) Option {
95 return func(c *EdgeClient) {
96 c.timeout = timeout
97 }
98 }
99
View as plain text