gocommon/log/hooks/gelf/config.go

32 lines
824 B
Go
Raw Normal View History

2022-11-26 20:45:32 +00:00
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"`
2022-11-26 20:45:32 +00:00
}
// 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
}