cloudflare/pint
Publicmirrored from https://github.com/cloudflare/pintAvailable
internal/config/cost.go
33lines · modecode
| 1 | package config |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | |
| 6 | "github.com/cloudflare/pint/internal/checks" |
| 7 | ) |
| 8 | |
| 9 | type CostSettings struct { |
| 10 | BytesPerSample int `hcl:"bytesPerSample,optional"` |
| 11 | MaxSeries int `hcl:"maxSeries,optional"` |
| 12 | Severity string `hcl:"severity,optional"` |
| 13 | } |
| 14 | |
| 15 | func (cs CostSettings) validate() error { |
| 16 | if cs.Severity != "" { |
| 17 | if _, err := checks.ParseSeverity(cs.Severity); err != nil { |
| 18 | return err |
| 19 | } |
| 20 | } |
| 21 | if cs.MaxSeries < 0 { |
| 22 | return fmt.Errorf("maxSeries value must be >= 0") |
| 23 | } |
| 24 | return nil |
| 25 | } |
| 26 | |
| 27 | func (cs CostSettings) getSeverity(fallback checks.Severity) checks.Severity { |
| 28 | if cs.Severity != "" { |
| 29 | sev, _ := checks.ParseSeverity(cs.Severity) |
| 30 | return sev |
| 31 | } |
| 32 | return fallback |
| 33 | } |