types.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package sitecheck
  2. import (
  3. "time"
  4. )
  5. // Site health check status constants
  6. const (
  7. StatusOnline = "online"
  8. StatusOffline = "offline"
  9. StatusError = "error"
  10. StatusChecking = "checking"
  11. )
  12. // SiteInfo represents the information about a site
  13. type SiteInfo struct {
  14. ID uint64 `json:"id"` // Site config ID for API operations
  15. Host string `json:"host"` // host:port format
  16. Port int `json:"port"` // port number
  17. Scheme string `json:"scheme"` // http, https, grpc, grpcs
  18. DisplayURL string `json:"display_url"` // computed URL for display
  19. Name string `json:"name"`
  20. Status string `json:"status"` // StatusOnline, StatusOffline, StatusError, StatusChecking
  21. StatusCode int `json:"status_code"`
  22. ResponseTime int64 `json:"response_time"` // in milliseconds
  23. FaviconURL string `json:"favicon_url"`
  24. FaviconData string `json:"favicon_data"` // base64 encoded favicon
  25. Title string `json:"title"`
  26. LastChecked int64 `json:"last_checked"` // Unix timestamp in seconds
  27. Error string `json:"error,omitempty"`
  28. // Legacy fields for backward compatibility
  29. URL string `json:"url,omitempty"` // deprecated, use display_url instead
  30. HealthCheckProtocol string `json:"health_check_protocol,omitempty"` // deprecated, use scheme instead
  31. HostPort string `json:"host_port,omitempty"` // deprecated, use host instead
  32. }
  33. // CheckOptions represents options for site checking
  34. type CheckOptions struct {
  35. Timeout time.Duration
  36. UserAgent string
  37. FollowRedirects bool
  38. MaxRedirects int
  39. CheckFavicon bool
  40. }
  41. // DefaultCheckOptions returns default checking options
  42. func DefaultCheckOptions() CheckOptions {
  43. return CheckOptions{
  44. Timeout: 10 * time.Second,
  45. UserAgent: "Nginx-UI Site Checker/1.0",
  46. FollowRedirects: true,
  47. MaxRedirects: 3,
  48. CheckFavicon: true,
  49. }
  50. }