Test Setup Failed
Pull Request — master (#1)
by Victor Hugo
01:18
created

devto.NewConfig   A

Complexity

Conditions 3

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
dl 0
loc 9
rs 10
c 0
b 0
f 0
nop 2
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