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"` ExtrasFields map[string]interface{} `yaml:"extra_fields"` } // 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 }