From 8e001408d8e37dab5fb9e961a6cd269f0c049603 Mon Sep 17 00:00:00 2001 From: Michael Kaye <1917473+michaelkaye@users.noreply.github.com> Date: Mon, 31 Jan 2022 16:24:25 +0000 Subject: [PATCH] Reduce cyclometric complexity --- main.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index d914a4e..0713805 100644 --- a/main.go +++ b/main.go @@ -135,15 +135,8 @@ func main() { if len(cfg.EmailAddresses) > 0 && cfg.SMTPServer == "" { log.Fatal("Email address(es) specified but no smtp_server configured. Wrong configuration, aborting...") } - var genericWebhookClient *http.Client - if cfg.GenericWebhookURL == "" { - 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, - } - } + + genericWebhookClient := configureGenericWebhookClient(cfg) apiPrefix := cfg.APIPrefix if apiPrefix == "" { @@ -187,6 +180,17 @@ func main() { 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) { contents, err := ioutil.ReadFile(configPath) if err != nil {