From de4ce9431e20f6f9dbbc93090f5ac750f401bd2b Mon Sep 17 00:00:00 2001 From: Neven Miculinic Date: Thu, 28 Mar 2019 13:58:11 +0100 Subject: [PATCH] Added empty checks --- wg.go | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/wg.go b/wg.go index d137552..a63970c 100644 --- a/wg.go +++ b/wg.go @@ -33,17 +33,22 @@ func Up(cfg *Config, iface string, logger logrus.FieldLogger) error { } } - if err := execSh(cfg.PreUp, iface, log); err != nil { - return err + if cfg.PreUp != "" { + if err := execSh(cfg.PreUp, iface, log); err != nil { + return err + } + log.Infoln("applied pre-up command") } - log.Infoln("applied pre-up command") if err := Sync(cfg, iface, logger); err != nil { return err } - if err := execSh(cfg.PostUp, iface, log); err != nil { - return err + + if cfg.PostUp != "" { + if err := execSh(cfg.PostUp, iface, log); err != nil { + return err + } + log.Infoln("applied post-up command") } - log.Infoln("applied post-up command") return nil } @@ -61,18 +66,23 @@ func Down(cfg *Config, iface string, logger logrus.FieldLogger) error { } } - if err := execSh(cfg.PreDown, iface, log); err != nil { - return err + if cfg.PreDown != "" { + if err := execSh(cfg.PreDown, iface, log); err != nil { + return err + } + log.Infoln("applied pre-down command") } - log.Infoln("applied pre-down command") + if err := netlink.LinkDel(link); err != nil { return err } log.Infoln("link deleted") - if err := execSh(cfg.PostDown, iface, log); err != nil { - return err + if cfg.PostDown != "" { + if err := execSh(cfg.PostDown, iface, log); err != nil { + return err + } + log.Infoln("applied post-down command") } - log.Infoln("applied post-down command") return nil }