main: Allow starting without a config file

This commit is contained in:
Michael Aldridge 2026-11-01 19:17:51 -06:00
parent 9a270abbf2
commit 8263737b18

14
main.go
View file

@ -1,6 +1,7 @@
package main
import (
"errors"
"os"
"os/signal"
"strings"
@ -55,9 +56,16 @@ func main() {
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.SetEnvPrefix("NETAUTH")
viper.AutomaticEnv()
// Every setting has either a default or an environment
// counterpart, so a missing config file is not a reason to
// refuse to start. Anything else (bad syntax, unreadable file)
// still is.
if err := viper.ReadInConfig(); err != nil {
appLogger.Error("Error loading config", "error", err)
os.Exit(5)
var notFound viper.ConfigFileNotFoundError
if !errors.As(err, &notFound) {
appLogger.Error("Error loading config", "error", err)
os.Exit(5)
}
}
nacl, err := netauth.NewWithLog(appLogger.Named("netauth"))
@ -83,7 +91,7 @@ func main() {
appLogger.Warn(" WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING ")
appLogger.Warn("===================================================================")
appLogger.Warn("")
appLogger.Warn("You are launching this server in plaintext mode! This is allowable")
appLogger.Warn("You are launching this server in plaintext mode! This is only")
appLogger.Warn("advisable when bound to localhost, and the bind configuration has")
appLogger.Warn("been detected as not being bound to localhost.")
appLogger.Warn("")