Merge pull request #53 from wiretrustee/handle-read-config-file-errors

Handle read config file errors
This commit is contained in:
Mikhail Bragin 2021-07-17 17:30:07 +02:00 committed by GitHub
commit bffea0e145
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 {