gocommon/log/hooks/file/config.go
Matthieu 'JP' DERASSE 5591da9c47
Some checks failed
continuous-integration/drone/push Build is failing
feat(log): Working on log library
2022-11-28 22:06:42 +00:00

43 lines
1023 B
Go

package file
import (
"github.com/asaskevich/govalidator"
"github.com/juju/errors"
)
// ConfigStruct is the configuration for File Provider.
type ConfigStruct struct {
Filename string `yaml:"filename"`
MaxLines int `yaml:"max_lines"`
MaxSize int `yaml:"max_size"`
Daily bool `yaml:"daily"`
MaxDays int `yaml:"max_days"`
Rotate bool `yaml:"rotate"`
Perm string `yaml:"perm"`
RotatePerm string `yaml:"rotate_perm"`
}
// IsValid will check that the File configuration is valid.
func (c *ConfigStruct) IsValid() error {
if c.Filename == "" {
return errors.NotValidf("Path is empty in File configuration")
} else if isValid, _ := govalidator.IsFilePath(c.Filename); !isValid {
return errors.NotValidf("Path is invalid in File configuration")
}
return nil
}
// ApplyDefault will check config and apply default on mandatory values.
func (c *ConfigStruct) ApplyDefault() {
if c.Perm == "" {
c.Perm = "0660"
}
if c.RotatePerm == "" {
c.RotatePerm = "0440"
}
}