Reduce cyclometric complexity

This commit is contained in:
Michael Kaye 2022-01-31 16:24:25 +00:00
parent d8a5acd2e2
commit 8e001408d8

22
main.go
View file

@ -135,15 +135,8 @@ func main() {
if len(cfg.EmailAddresses) > 0 && cfg.SMTPServer == "" { if len(cfg.EmailAddresses) > 0 && cfg.SMTPServer == "" {
log.Fatal("Email address(es) specified but no smtp_server configured. Wrong configuration, aborting...") log.Fatal("Email address(es) specified but no smtp_server configured. Wrong configuration, aborting...")
} }
var genericWebhookClient *http.Client
if cfg.GenericWebhookURL == "" { genericWebhookClient := configureGenericWebhookClient(cfg)
fmt.Println("No generic_webhook_url configured.")
} else {
fmt.Println("Will forward metadata of all requests to ", cfg.GenericWebhookURL)
genericWebhookClient = &http.Client{
Timeout: time.Second * 300,
}
}
apiPrefix := cfg.APIPrefix apiPrefix := cfg.APIPrefix
if apiPrefix == "" { if apiPrefix == "" {
@ -187,6 +180,17 @@ func main() {
log.Fatal(http.ListenAndServe(*bindAddr, nil)) log.Fatal(http.ListenAndServe(*bindAddr, nil))
} }
func configureGenericWebhookClient(cfg *config) (*http.Client) {
if cfg.GenericWebhookURL == "" {
fmt.Println("No generic_webhook_url configured.")
return nil
}
fmt.Println("Will forward metadata of all requests to ", cfg.GenericWebhookURL)
return &http.Client{
Timeout: time.Second * 300,
}
}
func loadConfig(configPath string) (*config, error) { func loadConfig(configPath string) (*config, error) {
contents, err := ioutil.ReadFile(configPath) contents, err := ioutil.ReadFile(configPath)
if err != nil { if err != nil {