Total Lines | 33 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | package devto |
||
2 | |||
3 | import "errors" |
||
4 | |||
5 | //Confugration errors |
||
6 | var ( |
||
7 | ErrMissingRequiredParameter = errors.New("a required parameter is missing") |
||
8 | ) |
||
9 | |||
10 | //Config contains the elements required to initialize a |
||
11 | // devto client. |
||
12 | type Config struct { |
||
13 | BaseHTTPClient httpClient |
||
14 | APIKey string |
||
15 | InsecureOnly bool |
||
16 | } |
||
17 | |||
18 | //NewConfig build a devto configuration instance with the |
||
19 | //required parameters. |
||
20 | // |
||
21 | //It takes a boolean (p) as first parameter to indicate if |
||
22 | //you need access to endpoints which require authentication, |
||
23 | //and a API key as second paramenter, if p is set to true and |
||
24 | //you don't provide an API key, it will return an error. |
||
25 | func NewConfig(p bool, k string) (c *Config, err error) { |
||
26 | if p == true && k == "" { |
||
27 | return nil, ErrMissingRequiredParameter |
||
28 | } |
||
29 | |||
30 | return &Config{ |
||
31 | InsecureOnly: !p, |
||
32 | APIKey: k, |
||
33 | }, nil |
||
34 | } |
||
35 |