Files
tiny-forge/internal/proxy/provider.go
T
alexei.dolgolyov 7d6719da12 refactor: extract ProxyProvider interface with None and NPM implementations
Replace direct npm.Client usage throughout the codebase with the
proxy.Provider interface, enabling pluggable proxy backends. The
deployer, API layer, and proxy manager now use provider-agnostic
route management (ConfigureRoute/DeleteRoute) instead of NPM-specific
API calls. Adds ProxyRouteID (string) to Instance model and
ProxyProvider setting to Settings, with SQLite migrations for
backward compatibility.
2026-04-04 19:39:08 +03:00

37 lines
1.5 KiB
Go

package proxy
import "context"
// RouteOptions holds optional configuration for a proxy route.
type RouteOptions struct {
SSLCertificateID int
ForwardScheme string // "http" or "https", defaults to "http"
}
// Provider is the interface for proxy route management.
// Implementations handle the specifics of each proxy system (NPM, Traefik, etc.).
// The "None" provider implements all methods as no-ops.
type Provider interface {
// Name returns the provider identifier (e.g., "npm", "traefik", "none").
Name() string
// ConfigureRoute creates or updates a proxy route for the given domain.
// Returns a route ID string that can be used for updates and deletes.
// For NPM, the route ID is the proxy host ID (stringified).
// For Traefik, the route ID is the router name.
// For None, returns empty string.
ConfigureRoute(ctx context.Context, domain, targetHost string, targetPort int, opts RouteOptions) (routeID string, err error)
// DeleteRoute removes a proxy route by its route ID.
// Does nothing if routeID is empty.
DeleteRoute(ctx context.Context, routeID string) error
// ContainerLabels returns Docker labels to set on containers at creation time.
// Traefik uses labels for auto-discovery; NPM and None return nil.
ContainerLabels(domain string, port int) map[string]string
// Ping checks connectivity to the proxy backend.
// Returns nil if healthy or if the provider doesn't need external connectivity (None).
Ping(ctx context.Context) error
}