gocommon/log/hooks/gelf/config.go
Matthieu 'JP' DERASSE 2259c587e1
Some checks failed
continuous-integration/drone/push Build is failing
feat(middlewares): Add stacktrace in recovery log
2023-01-15 19:42:39 +00:00

32 lines
824 B
Go

package gelf
import (
"strconv"
"github.com/asaskevich/govalidator"
"github.com/juju/errors"
)
// ConfigStruct is the configuration for GELF Provider.
type ConfigStruct struct {
Host string `yaml:"host"`
Port int `yaml:"port"`
}
// IsValid will check that the Gelf configuration is valid.
func (c *ConfigStruct) IsValid() error {
if c.Host == "" {
return errors.NotValidf("Host is empty in GELF configuration")
} else if !govalidator.IsDNSName(c.Host) && !govalidator.IsIP(c.Host) {
return errors.NotValidf("Host is invalid in GELF configuration. Should be a DNS name or an IP")
}
if c.Port == 0 {
return errors.NotValidf("Port is empty in GELF configuration")
} else if !govalidator.IsPort(strconv.Itoa(c.Port)) {
return errors.NotValidf("Port is invalid in GELF configuration")
}
return nil
}