Completed
Push — master ( a4e2ef...9b8a94 )
by Victor Hugo
25s queued 11s
created

devto/config.go   A

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 14
dl 0
loc 33
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A devto.NewConfig 0 9 3
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