Skip to content

Commit

Permalink
[#32]: chore: do not allow zero exec_timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
rustatian authored Jan 11, 2023
2 parents 0899086 + 5780140 commit c7541d6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
13 changes: 11 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package service

import "time"
import (
"errors"
"time"
)

// Env variables type alias
type Env map[string]string
Expand All @@ -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
Expand All @@ -39,4 +46,6 @@ func (c *Config) InitDefault() {
}
}
}

return nil
}
5 changes: 4 additions & 1 deletion plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit c7541d6

Please sign in to comment.