Handle read config file errors

This commit is contained in:
mlsmaycon 2021-07-17 14:58:02 +02:00
parent 4587f7686e
commit 1e250fc0df
2 changed files with 9 additions and 3 deletions

View File

@ -22,13 +22,16 @@ var (
os.Exit(ExitSetupFailed)
}
config, _ := Read(configPath)
config, err := Read(configPath)
if err != nil {
log.Fatalf("Error reading config file, message: %v", err)
}
config.Peers = append(config.Peers, connection.Peer{
WgPubKey: key,
WgAllowedIps: allowedIPs,
})
err := config.Write(configPath)
err = config.Write(configPath)
if err != nil {
log.Errorf("failed writing config to %s: %s", config, err.Error())
os.Exit(ExitSetupFailed)

View File

@ -17,7 +17,10 @@ var (
Run: func(cmd *cobra.Command, args []string) {
InitLog(logLevel)
config, _ := Read(configPath)
config, err := Read(configPath)
if err != nil {
log.Fatalf("Error reading config file, message: %v", err)
}
myKey, err := wgtypes.ParseKey(config.PrivateKey)
if err != nil {