Documentation
¶
Overview ¶
Package status provides functionality for health checking and status page generation in Go applications. It allows monitoring of various dependencies and services with different importance levels.
Index ¶
Constants ¶
const ( // TargetImportanceLow indicates that the target is not critical for the application. TargetImportanceLow = TargetImportance("low") // TargetImportanceHigh indicates that the target is critical for the application. TargetImportanceHigh = TargetImportance("high") )
const ( // HealthTargetStatusOk indicates that the target is healthy. HealthTargetStatusOk = HealthTargetStatus("ok") // HealthTargetStatusFail indicates that the target is unhealthy. HealthTargetStatusFail = HealthTargetStatus("fail") )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conclusion ¶
type Conclusion string
const ( ConclusionOk Conclusion = "Ok" ConclusionWarning Conclusion = "Warning" ConclusionFail Conclusion = "Fail" )
type HealthCheckResult ¶
type HealthCheckResult struct {
Target HealthTarget `json:"target"`
Status HealthTargetStatus `json:"status"`
ErrorMessage string `json:"error,omitempty"`
Duration time.Duration `json:"duration,omitempty"`
// contains filtered or unexported fields
}
HealthCheckResult contains the result of a health check for a target.
type HealthChecker ¶
type HealthChecker struct {
// contains filtered or unexported fields
}
HealthChecker manages a collection of health check targets and provides functionality to check their health status.
func NewHealthChecker ¶
func NewHealthChecker() *HealthChecker
NewHealthChecker creates a new HealthChecker instance.
func (*HealthChecker) Check ¶
func (c *HealthChecker) Check(ctx context.Context) ([]HealthCheckResult, error)
Check performs health checks for all registered targets concurrently.
func (*HealthChecker) Handler ¶
func (c *HealthChecker) Handler() http.HandlerFunc
func (*HealthChecker) WithTarget ¶
func (c *HealthChecker) WithTarget(name string, check check.Check, opts ...TargetOption) *HealthChecker
WithTarget adds a new health check target to the checker.
type HealthGroup ¶
type HealthGroup struct {
Name string
Results []HealthCheckResult
}
HealthGroup represents a group of health check results.
type HealthTarget ¶
type HealthTarget struct {
Name string `json:"name"`
Importance TargetImportance `json:"importance"`
Icon string `json:"icon,omitempty"`
Group string `json:"group,omitempty"`
// contains filtered or unexported fields
}
HealthTarget represents a single health check target.
type HealthTargetStatus ¶
type HealthTargetStatus string
HealthTargetStatus represents the status of a health check target.
type Page ¶
type Page struct {
// contains filtered or unexported fields
}
Page represents a status page that can be served via HTTP.
func NewPage ¶
func NewPage(opts ...PageOption) *Page
NewPage creates a new status page with the given options.
func (*Page) Handler ¶
func (p *Page) Handler() http.HandlerFunc
Handler returns an HTTP handler that serves the status page.
type PageData ¶
type PageData struct {
Title string
Version string
Conclusion Conclusion
HealthResults []HealthCheckResult
HealthGroups []HealthGroup
Links []Link
}
PageData contains the data that will be rendered in the status page template.
type PageOption ¶
type PageOption func(*Page)
PageOption is a function that configures a Page.
func WithHealthChecker ¶
func WithHealthChecker(hc *HealthChecker) PageOption
WithHealthChecker sets the health checker for the status page.
func WithLink ¶
func WithLink(name, url string) PageOption
WithLink adds a navigation link to the status page.
func WithTemplate ¶
func WithTemplate(tmpl *template.Template) PageOption
WithTemplate sets a custom HTML template for the status page.
func WithTitle ¶
func WithTitle(title string) PageOption
WithTitle sets the title of the status page.
func WithVersion ¶
func WithVersion(show bool) PageOption
WithVersion configures whether to show version information on the status page.
type TargetImportance ¶
type TargetImportance string
TargetImportance defines the importance level of a health check target.
type TargetOption ¶
type TargetOption func(*HealthTarget)
TargetOption is a function that configures a HealthTarget.
func WithGroup ¶
func WithGroup(group string) TargetOption
WithGroup sets the group name for a health check target. Targets with the same group name will be displayed together.
func WithIcon ¶
func WithIcon(icon string) TargetOption
WithIcon sets the icon CSS class name for a health check target.
func WithImportance ¶
func WithImportance(importance TargetImportance) TargetOption
WithImportance sets the importance level of a health check target.