Documentation
¶
Overview ¶
Package http provides an HTTP health check provider with response validation capabilities using CEL (Common Expression Language).
The HTTP provider supports:
- HTTP/HTTPS requests with configurable methods and bodies
- TLS certificate verification and detail extraction
- Response validation using CEL expressions
- JSON response parsing and field validation
- Status code, header, and body validation via CEL
CEL Expression Context: The following variables are available in CEL expressions:
Request context:
- request.method (string): HTTP method (GET, POST, etc.)
- request.body (string): Request body text
- request.headers (map[string]string): Request headers (lowercase keys)
- request.url (string): Target URL
Response context:
- response.json (map[string]any): Parsed JSON response body (nil if not JSON)
- response.body (string): Raw response body as text
- response.status (int): HTTP status code
- response.headers (map[string]string): Response headers (lowercase keys)
Example CEL expressions:
- response.status == 200 // Status code validation
- response.status >= 200 && response.status < 300 // Status range validation
- response.json.status == "healthy" // JSON field validation
- response.headers["x-health-status"] == "ok" // Header validation
- response.body.contains("success") // Body text validation
- response.headers["content-type"].contains("application/json") // Content type validation
- request.method == "POST" && response.status == 201 // Method-specific validation
- response.headers["content-type"] == request.headers["accept"] // Content negotiation
Index ¶
- Constants
- type Component
- func (c *Component) GetCheckConfig() *checks.CEL
- func (c *Component) GetCheckContext(ctx context.Context) (map[string]any, error)
- func (c *Component) GetHealth(ctx context.Context) *ph.HealthCheckResponse
- func (c *Component) GetType() string
- func (c *Component) LogValue() slog.Value
- func (c *Component) SetChecks(exprs []checks.Expression) error
- func (c *Component) Setup() error
Constants ¶
View Source
const ( ProviderType = "http" DefaultTimeout = 10 * time.Second )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Component ¶ added in v0.6.0
type Component struct {
provider.Base
provider.BaseWithChecks
URL string `mapstructure:"url"`
Method string `mapstructure:"method" default:"HEAD"`
Body string `mapstructure:"body"`
Headers map[string]string `mapstructure:"headers"`
Insecure bool `mapstructure:"insecure"`
Detail bool `mapstructure:"detail"`
}
Component provides HTTP health checks with CEL-based response validation
func (*Component) GetCheckConfig ¶ added in v0.7.0
GetCheckConfig returns the HTTP provider's CEL variable declarations.
func (*Component) GetCheckContext ¶ added in v0.7.0
GetCheckContext satisfies the CheckContextProvider interface.
func (*Component) GetHealth ¶ added in v0.6.0
func (c *Component) GetHealth(ctx context.Context) *ph.HealthCheckResponse
Click to show internal directories.
Click to hide internal directories.