From 887e47e6210dabdeb221b7f22de5849463d4632b Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Wed, 11 Jan 2023 15:48:35 +0100 Subject: [PATCH 1/2] chore: do not allow zero exec_timeout --- config.go | 11 +++++++++-- plugin.go | 5 ++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/config.go b/config.go index bb37337..f24521e 100644 --- a/config.go +++ b/config.go @@ -1,6 +1,9 @@ package service -import "time" +import ( + "errors" + "time" +) // Env variables type alias type Env map[string]string @@ -21,12 +24,16 @@ type Config struct { Services map[string]*Service `mapstructure:"service"` } -func (c *Config) InitDefault() { +func (c *Config) InitDefault() error { if len(c.Services) > 0 { for k, v := range c.Services { val := c.Services[k] c.Services[k] = val + if v.ExecTimeout == 0 { + return errors.New("exec_timeout should be more 0") + } + if v.ProcessNum == 0 { val := c.Services[k] val.ProcessNum = 1 diff --git a/plugin.go b/plugin.go index d3073f4..8ae388d 100644 --- a/plugin.go +++ b/plugin.go @@ -39,7 +39,10 @@ func (p *Plugin) Init(cfg Configurer, log *zap.Logger) error { } // init default parameters if not set by user - p.cfg.InitDefault() + err = p.cfg.InitDefault() + if err != nil { + return err + } // save the logger p.logger = log From 5780140d5c1ac3609cd9169c861b2e123dee1fa6 Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Wed, 11 Jan 2023 15:54:37 +0100 Subject: [PATCH 2/2] - missed return Signed-off-by: Valery Piashchynski --- config.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config.go b/config.go index f24521e..6eed941 100644 --- a/config.go +++ b/config.go @@ -46,4 +46,6 @@ func (c *Config) InitDefault() error { } } } + + return nil }