From 4f067b7af6edcbd56b28ac96f2e11eb87c9efb5b Mon Sep 17 00:00:00 2001 From: Gil Casadevall Date: Wed, 22 Jun 2016 12:54:34 +0200 Subject: [PATCH] Added env variables validation --- main.go | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 0fecff2..fdc9417 100644 --- a/main.go +++ b/main.go @@ -1,8 +1,11 @@ package main import ( - "github.com/go-chat-bot/bot/slack" + "errors" + "fmt" "os" + + "github.com/go-chat-bot/bot/slack" ) const ( @@ -16,7 +19,30 @@ var ( kb *Kubebot ) +func validateEnvParams() error { + if os.Getenv(slackTokenLabel) == "" { + return errors.New("slackTokenLabel env variable not defined") + } + if os.Getenv(slackChannelsLabel) == "" { + return errors.New("slackChannelsLabel env variable not defined") + } + if os.Getenv(slackAdminsLabel) == "" { + return errors.New("slackAdminsLabel env variable not defined") + } + if os.Getenv(slackCommandsLabel) == "" { + return errors.New("slackCommandsLabel env variable not defined") + } + + return nil +} + func main() { + + if err := validateEnvParams(); err != nil { + fmt.Printf("Kubebot cannot run. Error: %s\n", err.Error()) + return + } + kb = &Kubebot{ token: os.Getenv(slackTokenLabel), admins: stringToMap(os.Getenv(slackAdminsLabel), " "),