Skip to content

Validatable interface #854

@kke

Description

@kke

There's UnmarshalJSON and UnmarshalYAML for the unmarshalers, then there's SetDefaults for the https://github.com/creasty/defaults but for the validator, you need to use the RegisterValidation thing.

Could the validator just call some kind of Validate() error function on all targets if they have it?

type Config struct {
  Attrs *Attributes
}

type Attributes struct {
  Setting bool
  Value valueString
}

type valueString string
func (v valueString) Validate() error {
  if strings.HasPrefix(v, "x") {
    return fmt.Errorf("can't start with x")
  }
  return nil
}

func (a Attributes) Validate() error {
  if a.Setting {
    return fmt.Errorf("this setting must be true")
  }
  return nil
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions