Add logging for the loading config file values
This commit is contained in:
15
main.go
15
main.go
@@ -31,6 +31,7 @@ func main() {
|
|||||||
// Parse and check config values
|
// Parse and check config values
|
||||||
if cfg.Section("app").HasKey("subreddit") {
|
if cfg.Section("app").HasKey("subreddit") {
|
||||||
subreddit = cfg.Section("app").Key("subreddit").String()
|
subreddit = cfg.Section("app").Key("subreddit").String()
|
||||||
|
printConfig("subreddit", subreddit)
|
||||||
} else {
|
} else {
|
||||||
quitConfigParseError("Missing 'subreddit'")
|
quitConfigParseError("Missing 'subreddit'")
|
||||||
}
|
}
|
||||||
@@ -38,18 +39,23 @@ func main() {
|
|||||||
if cfg.Section("app").HasKey("interval") {
|
if cfg.Section("app").HasKey("interval") {
|
||||||
// default to 5 minutes
|
// default to 5 minutes
|
||||||
interval = cfg.Section("app").Key("interval").MustInt(5)
|
interval = cfg.Section("app").Key("interval").MustInt(5)
|
||||||
|
printConfig("interval", strconv.Itoa(interval))
|
||||||
} else {
|
} else {
|
||||||
quitConfigParseError("Missing 'interval'")
|
quitConfigParseError("Missing 'interval'")
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.Section("app").HasKey("keyword") {
|
if cfg.Section("app").HasKey("keyword") {
|
||||||
keywords = cfg.Section("app").Key("keyword").ValueWithShadows()
|
keywords = cfg.Section("app").Key("keyword").ValueWithShadows()
|
||||||
|
for _, keys := range keywords {
|
||||||
|
printConfig("keyword", keys)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
quitConfigParseError("Missing 'keyword'")
|
quitConfigParseError("Missing 'keyword'")
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.Section("smtp").HasKey("smtp_server") {
|
if cfg.Section("smtp").HasKey("smtp_server") {
|
||||||
smtpServer = cfg.Section("smtp").Key("smtp_server").String()
|
smtpServer = cfg.Section("smtp").Key("smtp_server").String()
|
||||||
|
printConfig("smtp_server", smtpServer)
|
||||||
} else {
|
} else {
|
||||||
quitConfigParseError("Missing 'smtp_server'")
|
quitConfigParseError("Missing 'smtp_server'")
|
||||||
}
|
}
|
||||||
@@ -57,30 +63,35 @@ func main() {
|
|||||||
if cfg.Section("smtp").HasKey("smtp_port") {
|
if cfg.Section("smtp").HasKey("smtp_port") {
|
||||||
// default to port 25
|
// default to port 25
|
||||||
smtpPort = cfg.Section("smtp").Key("smtp_port").MustInt(25)
|
smtpPort = cfg.Section("smtp").Key("smtp_port").MustInt(25)
|
||||||
|
printConfig("smtp_port", strconv.Itoa(smtpPort))
|
||||||
} else {
|
} else {
|
||||||
quitConfigParseError("Missing 'smtp_port'")
|
quitConfigParseError("Missing 'smtp_port'")
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.Section("smtp").HasKey("smtp_username") {
|
if cfg.Section("smtp").HasKey("smtp_username") {
|
||||||
smtpUsername = cfg.Section("smtp").Key("smtp_username").String()
|
smtpUsername = cfg.Section("smtp").Key("smtp_username").String()
|
||||||
|
printConfig("smtp_username", smtpUsername)
|
||||||
} else {
|
} else {
|
||||||
quitConfigParseError("Missing 'smtp_username'")
|
quitConfigParseError("Missing 'smtp_username'")
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.Section("smtp").HasKey("smtp_password") {
|
if cfg.Section("smtp").HasKey("smtp_password") {
|
||||||
smtpPassword = cfg.Section("smtp").Key("smtp_password").String()
|
smtpPassword = cfg.Section("smtp").Key("smtp_password").String()
|
||||||
|
printConfig("smtp_password", "<redacted>")
|
||||||
} else {
|
} else {
|
||||||
quitConfigParseError("Missing 'smtp_password'")
|
quitConfigParseError("Missing 'smtp_password'")
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.Section("smtp").HasKey("smtp_to") {
|
if cfg.Section("smtp").HasKey("smtp_to") {
|
||||||
smtpTo = cfg.Section("smtp").Key("smtp_to").String()
|
smtpTo = cfg.Section("smtp").Key("smtp_to").String()
|
||||||
|
printConfig("smtp_to", smtpTo)
|
||||||
} else {
|
} else {
|
||||||
quitConfigParseError("Missing 'smtp_to'")
|
quitConfigParseError("Missing 'smtp_to'")
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.Section("smtp").HasKey("smtp_from") {
|
if cfg.Section("smtp").HasKey("smtp_from") {
|
||||||
smtpFrom = cfg.Section("smtp").Key("smtp_from").String()
|
smtpFrom = cfg.Section("smtp").Key("smtp_from").String()
|
||||||
|
printConfig("smtp_from", smtpFrom)
|
||||||
} else {
|
} else {
|
||||||
quitConfigParseError("Missing 'smtp_from'")
|
quitConfigParseError("Missing 'smtp_from'")
|
||||||
}
|
}
|
||||||
@@ -148,6 +159,10 @@ func loop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func printConfig(key string, value string) {
|
||||||
|
fmt.Println("Loaded "+key+": ", value)
|
||||||
|
}
|
||||||
|
|
||||||
func quitConfigParseError(msg string) {
|
func quitConfigParseError(msg string) {
|
||||||
fmt.Println("Error parsing config.ini: ", msg)
|
fmt.Println("Error parsing config.ini: ", msg)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
Reference in New Issue
Block a user