From 4e3856c638650e73275c5183f4a11243eb51cede Mon Sep 17 00:00:00 2001 From: TwinProduction Date: Fri, 23 Oct 2020 16:07:51 -0400 Subject: [PATCH] Improve code documentation --- config/config.go | 17 +++++++++++++---- core/types.go | 13 +++++++++++-- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/config/config.go b/config/config.go index 069fabd8..6e69da6e 100644 --- a/config/config.go +++ b/config/config.go @@ -23,11 +23,19 @@ const ( ) var ( - ErrNoServiceInConfig = errors.New("configuration file should contain at least 1 service") - ErrConfigFileNotFound = errors.New("configuration file not found") - ErrConfigNotLoaded = errors.New("configuration is nil") + // ErrNoServiceInConfig is an error returned when a configuration file has no services configured + ErrNoServiceInConfig = errors.New("configuration file should contain at least 1 service") + + // ErrConfigFileNotFound is an error returned when the configuration file could not be found + ErrConfigFileNotFound = errors.New("configuration file not found") + + // ErrConfigNotLoaded is an error returned when an attempt to Get() the configuration before loading it is made + ErrConfigNotLoaded = errors.New("configuration is nil") + + // ErrInvalidSecurityConfig is an error returned when the security configuration is invalid ErrInvalidSecurityConfig = errors.New("invalid security configuration") - config *Config + + config *Config ) // Config is the main configuration structure @@ -168,6 +176,7 @@ func validateAlertingConfig(config *Config) { log.Printf("[config][validateAlertingConfig] configuredProviders=%s; ignoredProviders=%s", validProviders, invalidProviders) } +// GetAlertingProviderByAlertType returns an provider.AlertProvider by its corresponding core.AlertType func GetAlertingProviderByAlertType(config *Config, alertType core.AlertType) provider.AlertProvider { switch alertType { case core.SlackAlert: diff --git a/core/types.go b/core/types.go index 5ca8f05d..86874e8c 100644 --- a/core/types.go +++ b/core/types.go @@ -4,8 +4,13 @@ import ( "time" ) +// HealthStatus is the status of Gatus type HealthStatus struct { - Status string `json:"status"` + // Status is the state of Gatus (UP/DOWN) + Status string `json:"status"` + + // Message is an accompanying description of why the status is as reported. + // If the Status is UP, no message will be provided Message string `json:"message,omitempty"` } @@ -42,7 +47,11 @@ type Result struct { Timestamp time.Time `json:"timestamp"` } +// ConditionResult result of a Condition type ConditionResult struct { + // Condition that was evaluated Condition string `json:"condition"` - Success bool `json:"success"` + + // Success whether the condition was met (successful) or not (failed) + Success bool `json:"success"` }