Files
notifier/pkg/client/types.go
T
igodwin eda033ff9b
CI / Lint (push) Successful in 2m29s
Build and Publish Container / build-and-publish (push) Successful in 2m58s
CI / Vulnerability scan (push) Successful in 44s
CI / Test (push) Successful in 1m45s
fix: clear golangci-lint backlog and make lint job blocking
Addresses errcheck, gosec, revive, staticcheck, and unused findings
across the codebase (unchecked error returns, unsafe file inclusion
warnings on operator/test-controlled paths, missing package comments,
unused parameters, deprecated API usage). Also fixes two suppression
comments that were silently no-ops due to wrong syntax (#nosec needs
a leading '#', nolint reasons need '//' not '--').

With the backlog clear, drop continue-on-error from the CI lint job
per the plan left in b4b4806.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-18 10:32:51 -07:00

110 lines
4.6 KiB
Go

// Package client provides a Go client library and types for interacting
// with the notifier service's REST API.
package client
import "time"
// NotificationRequest represents a notification to send
type NotificationRequest struct {
Type string `json:"type"` // stdout, email, slack, ntfy
Account string `json:"account"` // Optional: account name (uses default if empty)
Subject string `json:"subject"` // Email subject or title
Body string `json:"body"` // Notification message body
Recipients []string `json:"recipients"` // Email addresses, Slack channels, etc.
Metadata map[string]string `json:"metadata,omitempty"` // Optional metadata
}
// NotificationResponse represents the response from sending a notification
type NotificationResponse struct {
NotificationID string `json:"notification_id"`
Success bool `json:"success"`
Message string `json:"message,omitempty"`
Error string `json:"error,omitempty"`
SentAt time.Time `json:"sent_at"`
}
// NotificationStatus represents the status of a notification
type NotificationStatus string
// Notification status values returned by the notifier service.
const (
StatusPending NotificationStatus = "pending"
StatusQueued NotificationStatus = "queued"
StatusRetrying NotificationStatus = "retrying"
StatusSent NotificationStatus = "sent"
StatusFailed NotificationStatus = "failed"
)
// Notification represents a notification with full details
type Notification struct {
ID string `json:"id"`
Type string `json:"type"`
Account string `json:"account"`
Subject string `json:"subject"`
Body string `json:"body"`
Recipients []string `json:"recipients"`
Status NotificationStatus `json:"status"`
RetryCount int `json:"retry_count"`
MaxRetries int `json:"max_retries"`
LastError string `json:"last_error,omitempty"`
CreatedAt time.Time `json:"created_at"`
SentAt *time.Time `json:"sent_at,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
}
// NotificationStats represents statistics about notifications
type NotificationStats struct {
TotalSent int64 `json:"total_sent"`
TotalFailed int64 `json:"total_failed"`
TotalPending int64 `json:"total_pending"`
TotalQueued int64 `json:"total_queued"`
ByType map[string]int64 `json:"by_type"`
ByStatus map[string]int64 `json:"by_status"`
}
// ListNotificationsRequest represents filters for listing notifications
type ListNotificationsRequest struct {
IDs []string `json:"ids,omitempty"`
Types []string `json:"types,omitempty"`
Statuses []NotificationStatus `json:"statuses,omitempty"`
Recipients []string `json:"recipients,omitempty"`
CreatedAfter *time.Time `json:"created_after,omitempty"`
CreatedBefore *time.Time `json:"created_before,omitempty"`
Offset int `json:"offset,omitempty"`
Limit int `json:"limit,omitempty"`
}
// ListNotificationsResponse represents the response from listing notifications
type ListNotificationsResponse struct {
Notifications []*Notification `json:"notifications"`
Total int `json:"total"`
}
// NotifierInfo represents information about an available notifier
type NotifierInfo struct {
Type string `json:"type"`
Accounts []string `json:"accounts"`
DefaultAccount string `json:"default_account"`
}
// NotifiersResponse represents available notifiers
type NotifiersResponse struct {
Notifiers []NotifierInfo `json:"notifiers"`
}
// Config contains configuration for the client
type Config struct {
BaseURL string // Base URL for REST API (e.g., "http://localhost:8080")
APIKey string // Optional API key for authentication
Timeout time.Duration // Request timeout (default: 30s)
MaxRetries int // Max retries on failure (default: 3)
RetryBackoff time.Duration // Backoff between retries (default: 100ms)
// TLSInsecure disables TLS verification - ONLY for testing with self-signed certs in dev/test environments
// NEVER set this to true in production. Use proper certificates or provide custom CA certificates instead.
TLSInsecure bool
}
// ClientConfig is a backward-compatible alias for Config.
// Deprecated: use Config.
type ClientConfig = Config //nolint:revive // kept for API compatibility