devto.NewConfig   A
last analyzed

Complexity

Conditions 3

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3

Importance

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