2021-09-02 22:26:08 -04:00
package ui
2022-08-11 03:05:34 +02:00
import "errors"
2021-10-23 16:47:12 -04:00
// Config is the UI configuration for core.Endpoint
2021-09-02 22:26:08 -04:00
type Config struct {
2021-09-14 19:34:46 -04:00
// HideHostname whether to hide the hostname in the Result
HideHostname bool `yaml:"hide-hostname"`
2022-08-10 21:09:22 -04:00
2022-06-17 02:53:03 +05:00
// HideURL whether to ensure the URL is not displayed in the results. Useful if the URL contains a token.
HideURL bool `yaml:"hide-url"`
2022-08-10 21:09:22 -04:00
2021-09-14 19:34:46 -04:00
// DontResolveFailedConditions whether to resolve failed conditions in the Result for display in the UI
2022-08-10 21:09:22 -04:00
DontResolveFailedConditions bool `yaml:"dont-resolve-failed-conditions"`
2022-08-11 03:05:34 +02:00
// Badge is the configuration for the badges generated
Badge * Badge `yaml:"badge"`
}
type Badge struct {
ResponseTime * ResponseTime `yaml:"response-time"`
}
2022-08-10 21:09:22 -04:00
2022-08-11 03:05:34 +02:00
type ResponseTime struct {
Thresholds [] int `yaml:"thresholds"`
}
var (
ErrInvalidBadgeResponseTimeConfig = errors . New ( "invalid response time badge configuration: expected parameter 'response-time' to have 5 ascending numerical values" )
)
func ( config * Config ) ValidateAndSetDefaults () error {
if config . Badge != nil {
if len ( config . Badge . ResponseTime . Thresholds ) != 5 {
return ErrInvalidBadgeResponseTimeConfig
}
for i := 4 ; i > 0 ; i -- {
if config . Badge . ResponseTime . Thresholds [ i ] < config . Badge . ResponseTime . Thresholds [ i - 1 ] {
return ErrInvalidBadgeResponseTimeConfig
}
}
} else {
config . Badge = GetDefaultConfig (). Badge
}
return nil
2021-09-02 22:26:08 -04:00
}
// GetDefaultConfig retrieves the default UI configuration
func GetDefaultConfig () * Config {
return & Config {
2021-09-14 19:34:46 -04:00
HideHostname : false ,
2022-06-17 02:53:03 +05:00
HideURL : false ,
2021-09-14 19:34:46 -04:00
DontResolveFailedConditions : false ,
2022-08-11 03:05:34 +02:00
Badge : & Badge {
ResponseTime : & ResponseTime {
Thresholds : [] int { 50 , 200 , 300 , 500 , 750 },
},
},
2021-09-02 22:26:08 -04:00
}
}