-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathconfig.go
96 lines (74 loc) · 1.58 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package client
import (
"net/http"
"time"
"github.com/hashicorp/go-retryablehttp"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
type Config struct {
ApiKey string
OpsGenieAPIURL ApiUrl
apiUrl string
ProxyConfiguration *ProxyConfiguration
RequestTimeout time.Duration
HttpClient *http.Client
Backoff retryablehttp.Backoff
RetryPolicy retryablehttp.CheckRetry
RetryCount int
LogLevel logrus.Level
Logger logrus.FieldLogger
}
type ApiUrl string
const (
API_URL ApiUrl = "api.opsgenie.com"
API_URL_EU ApiUrl = "api.eu.opsgenie.com"
API_URL_SANDBOX ApiUrl = "api.sandbox.opsgenie.com"
)
func (conf Config) Validate() error {
if conf.ApiKey == "" {
return errors.New("API key cannot be blank.")
}
if conf.RetryCount < 0 {
return errors.New("Retry count cannot be less than 1.")
}
return nil
}
func Default() *Config {
return &Config{}
}
type ProxyConfiguration struct {
Username string
Password string
Host string
Protocol Protocol
Port int
}
type Protocol string
const (
Http Protocol = "http"
Https Protocol = "https"
Socks5 Protocol = "socks5"
)
func (conf *Config) ConfigureLogLevel(level string) {
var logLevel logrus.Level
switch level {
case "panic":
logLevel = logrus.PanicLevel
case "fatal":
logLevel = logrus.FatalLevel
case "error":
logLevel = logrus.ErrorLevel
case "warn":
logLevel = logrus.WarnLevel
case "info":
logLevel = logrus.InfoLevel
case "debug":
logLevel = logrus.DebugLevel
case "trace":
logLevel = logrus.TraceLevel
default:
logLevel = logrus.InfoLevel
}
conf.LogLevel = logLevel
}