Added config validation
parent
b3fa772152
commit
dad080aa50
35
main.go
35
main.go
|
@ -404,6 +404,14 @@ func sendMail(cfg *Config, recipients []string, subject, html string) ([]Postmar
|
|||
return results, nil
|
||||
}
|
||||
|
||||
func ComplainEmpty(val string, complaint string) bool {
|
||||
if val == "" {
|
||||
fmt.Println(complaint)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func main() {
|
||||
/* Read in credentials into Config struct */
|
||||
/* *** */
|
||||
|
@ -422,6 +430,31 @@ func main() {
|
|||
os.Exit(1)
|
||||
}
|
||||
|
||||
if config.BatchSize == 0 {
|
||||
config.BatchSize = 500
|
||||
}
|
||||
|
||||
validConfig := true
|
||||
|
||||
validConfig = ComplainEmpty(config.TestEmail, "* Test email address is missing in config") && validConfig
|
||||
validConfig = ComplainEmpty(config.HMC.ApiUrl, "* HMC API url is missing in config") && validConfig
|
||||
validConfig = ComplainEmpty(config.HMC.SharedSecret, "* HMC Shared secret is missing in config") && validConfig
|
||||
validConfig = ComplainEmpty(config.HMC.City, "* HMC City is missing in config") && validConfig
|
||||
validConfig = ComplainEmpty(config.Postmark.ServerToken, "* Postmark server token is missing in config") && validConfig
|
||||
validConfig = ComplainEmpty(config.Postmark.ApiUrl, "* Postmark API url is missing in config") && validConfig
|
||||
if config.Postmark.TemplateId == 0 {
|
||||
fmt.Println("* Postmark template ID is missing in config")
|
||||
validConfig = false
|
||||
}
|
||||
validConfig = ComplainEmpty(config.Postmark.SenderName, "* Sender name is missing in config") && validConfig
|
||||
validConfig = ComplainEmpty(config.Postmark.SenderEmail, "* Sender email is missing in config") && validConfig
|
||||
validConfig = ComplainEmpty(config.Postmark.MessageStream, "* Postmark message stream is missing in config") && validConfig
|
||||
|
||||
if !validConfig {
|
||||
fmt.Println("Please fix your config and try again")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
/* Setup Cobra */
|
||||
/* *** */
|
||||
cmd := &cobra.Command{
|
||||
|
@ -469,7 +502,7 @@ func main() {
|
|||
maxIndexWidth := len(strconv.Itoa(len(subscribers)))
|
||||
for index, email := range subscribers {
|
||||
indexStr := strconv.Itoa(index + 1)
|
||||
indexStr = strings.Repeat(" ", maxIndexWidth - len(indexStr)) + indexStr // Right-align the index
|
||||
indexStr = strings.Repeat(" ", maxIndexWidth-len(indexStr)) + indexStr // Right-align the index
|
||||
fmt.Printf("%s. \033[1m%s\033[0m\n", indexStr, email)
|
||||
}
|
||||
fmt.Printf("\nMailing list grows automatically as more subscribe at \033[1mhandmadecities.com/meetups\033[0m\n")
|
||||
|
|
Loading…
Reference in New Issue