Replace MarshalYAML() with IsZero() method for Regexp
Signed-off-by: Liam Howe <liam.howe@maersk.com>
This commit is contained in:
parent
835dfa7eb6
commit
5d97f17ff1
|
@ -111,15 +111,6 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||||
return c.Validate()
|
return c.Validate()
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarshalYAML implements the yaml.Marshaler interface.
|
|
||||||
func (c Config) MarshalYAML() (interface{}, error) {
|
|
||||||
// Omit the regex if it is the default regex as it was not provided in the first place.
|
|
||||||
if c.Regex == DefaultRelabelConfig.Regex {
|
|
||||||
c.Regex.Regexp = nil
|
|
||||||
}
|
|
||||||
return c, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Config) Validate() error {
|
func (c *Config) Validate() error {
|
||||||
if c.Action == "" {
|
if c.Action == "" {
|
||||||
return fmt.Errorf("relabel action cannot be empty")
|
return fmt.Errorf("relabel action cannot be empty")
|
||||||
|
@ -214,6 +205,11 @@ func (re Regexp) MarshalYAML() (interface{}, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsZero implements the yaml.IsZeroer interface.
|
||||||
|
func (re Regexp) IsZero() bool {
|
||||||
|
return re.Regexp == DefaultRelabelConfig.Regex.Regexp
|
||||||
|
}
|
||||||
|
|
||||||
// String returns the original string used to compile the regular expression.
|
// String returns the original string used to compile the regular expression.
|
||||||
func (re Regexp) String() string {
|
func (re Regexp) String() string {
|
||||||
str := re.Regexp.String()
|
str := re.Regexp.String()
|
||||||
|
|
Loading…
Reference in New Issue