Skip to content

Commit

Permalink
Added env variables validation
Browse files Browse the repository at this point in the history
  • Loading branch information
dgil committed Jun 22, 2016
1 parent 9129e3e commit 4f067b7
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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), " "),
Expand Down

0 comments on commit 4f067b7

Please sign in to comment.