types.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package reverseproxy
  2. import (
  3. "time"
  4. )
  5. const (
  6. DefaultConfigPath = "/etc/debtik/reverse_proxy.json"
  7. ProtocolHTTP = "http"
  8. ProtocolHTTPS = "https"
  9. ProtocolBoth = "both"
  10. )
  11. // RuleStats holds runtime counters for a proxy rule.
  12. type RuleStats struct {
  13. Requests uint64 `json:"requests"`
  14. BytesReceived uint64 `json:"bytes_received"`
  15. BytesSent uint64 `json:"bytes_sent"`
  16. LastAccess time.Time `json:"last_access,omitempty"`
  17. }
  18. // Rule represents a single routing rule for the reverse proxy.
  19. type Rule struct {
  20. ID string `json:"id"`
  21. Name string `json:"name"`
  22. Enabled bool `json:"enabled"`
  23. Domains []string `json:"domains"` // Hostnames or IPs to match (e.g. "example.com", "app.local", "*")
  24. Path string `json:"path"` // Inbound path prefix to match (e.g. "/" or "/app1")
  25. TargetURL string `json:"target_url"` // Backend target URL (e.g. "http://example.com/app1" or "http://10.0.0.5:8080")
  26. StripPath bool `json:"strip_path"` // Whether to strip the inbound path prefix before forwarding
  27. PreserveHost bool `json:"preserve_host"` // If true, forward client Host header; else use TargetURL host
  28. Protocol string `json:"protocol"` // "http", "https", "both"
  29. Certificate string `json:"certificate,omitempty"` // Certificate name from CertManager for TLS/HTTPS
  30. HTTPToHTTPS bool `json:"http_to_https"` // Auto-redirect HTTP to HTTPS for this rule
  31. InsecureTLS bool `json:"insecure_tls"` // Skip TLS verification for backend HTTPS targets
  32. CustomHeaders map[string]string `json:"custom_headers,omitempty"` // Custom HTTP headers to inject
  33. Comment string `json:"comment,omitempty"` // User description
  34. CreatedAt time.Time `json:"created_at"`
  35. UpdatedAt time.Time `json:"updated_at"`
  36. Stats RuleStats `json:"stats"`
  37. }
  38. // Config represents global reverse proxy configuration.
  39. type Config struct {
  40. Enabled bool `json:"enabled"`
  41. HTTPPort int `json:"http_port"` // Inbound HTTP port (default: 80)
  42. HTTPSPort int `json:"https_port"` // Inbound HTTPS port (default: 443)
  43. DefaultCert string `json:"default_cert,omitempty"` // Fallback certificate name
  44. Rules []*Rule `json:"rules"`
  45. }