cloudflare/pint
Publicmirrored from https://github.com/cloudflare/pintAvailable
internal/config/checks.go
35lines · modecode
| 1 | package config |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "slices" |
| 6 | |
| 7 | "github.com/cloudflare/pint/internal/checks" |
| 8 | ) |
| 9 | |
| 10 | type Checks struct { |
| 11 | Enabled []string `hcl:"enabled,optional" json:"enabled,omitempty"` |
| 12 | Disabled []string `hcl:"disabled,optional" json:"disabled,omitempty"` |
| 13 | } |
| 14 | |
| 15 | func (c Checks) validate() error { |
| 16 | for _, name := range c.Enabled { |
| 17 | if err := validateCheckName(name); err != nil { |
| 18 | return err |
| 19 | } |
| 20 | } |
| 21 | for _, name := range c.Disabled { |
| 22 | if err := validateCheckName(name); err != nil { |
| 23 | return err |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | return nil |
| 28 | } |
| 29 | |
| 30 | func validateCheckName(name string) error { |
| 31 | if slices.Contains(checks.CheckNames, name) { |
| 32 | return nil |
| 33 | } |
| 34 | return fmt.Errorf("unknown check name %s", name) |
| 35 | } |
| 36 | |