Total Lines | 32 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | package devto |
||
2 | |||
3 | import "errors" |
||
4 | |||
5 | // Configuration 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 | APIKey string |
||
14 | InsecureOnly bool |
||
15 | } |
||
16 | |||
17 | // NewConfig build a devto configuration instance with the |
||
18 | // required parameters. |
||
19 | // |
||
20 | // It takes a boolean (p) as first parameter to indicate if |
||
21 | // you need access to endpoints which require authentication, |
||
22 | // and a API key as second parameter, if p is set to true and |
||
23 | // you don't provide an API key, it will return an error. |
||
24 | func NewConfig(p bool, k string) (c *Config, err error) { |
||
25 | 1 | if p == true && k == "" { |
|
26 | 1 | return nil, ErrMissingRequiredParameter |
|
27 | } |
||
28 | |||
29 | 1 | return &Config{ |
|
30 | InsecureOnly: !p, |
||
31 | APIKey: k, |
||
32 | }, nil |
||
33 | } |
||
34 |