Added empty checks

This commit is contained in:
Neven Miculinic 2019-03-28 13:58:11 +01:00
parent cc65c47fd3
commit de4ce9431e

10
wg.go
View File

@ -33,17 +33,22 @@ func Up(cfg *Config, iface string, logger logrus.FieldLogger) error {
} }
} }
if cfg.PreUp != "" {
if err := execSh(cfg.PreUp, iface, log); err != nil { if err := execSh(cfg.PreUp, iface, log); err != nil {
return err return err
} }
log.Infoln("applied pre-up command") log.Infoln("applied pre-up command")
}
if err := Sync(cfg, iface, logger); err != nil { if err := Sync(cfg, iface, logger); err != nil {
return err return err
} }
if cfg.PostUp != "" {
if err := execSh(cfg.PostUp, iface, log); err != nil { if err := execSh(cfg.PostUp, iface, log); err != nil {
return err return err
} }
log.Infoln("applied post-up command") log.Infoln("applied post-up command")
}
return nil return nil
} }
@ -61,18 +66,23 @@ func Down(cfg *Config, iface string, logger logrus.FieldLogger) error {
} }
} }
if cfg.PreDown != "" {
if err := execSh(cfg.PreDown, iface, log); err != nil { if err := execSh(cfg.PreDown, iface, log); err != nil {
return err return err
} }
log.Infoln("applied pre-down command") log.Infoln("applied pre-down command")
}
if err := netlink.LinkDel(link); err != nil { if err := netlink.LinkDel(link); err != nil {
return err return err
} }
log.Infoln("link deleted") log.Infoln("link deleted")
if cfg.PostDown != "" {
if err := execSh(cfg.PostDown, iface, log); err != nil { if err := execSh(cfg.PostDown, iface, log); err != nil {
return err return err
} }
log.Infoln("applied post-down command") log.Infoln("applied post-down command")
}
return nil return nil
} }