mirror of
https://github.com/Pacerino/CaddyProxyManager.git
synced 2026-08-04 03:05:30 -04:00
Introduce a Provider interface selectable via CPM_CADDY_MODE: - CaddyfileProvider renders per-host snippets (template whitespace fixed) - APIProvider manages Caddy's JSON config via the admin API Add configurable reload strategy (systemd/exec/api/none) and a configurable listen address for the bootstrapped server in API mode. Includes unit tests for the JSON builder, provider factory and the API provider (httptest).
32 lines
968 B
Go
32 lines
968 B
Go
package caddy
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/Pacerino/CaddyProxyManager/internal/config"
|
|
"github.com/Pacerino/CaddyProxyManager/internal/database"
|
|
)
|
|
|
|
// Provider applies host configuration to Caddy. Implementations either write
|
|
// per-host Caddyfiles (CaddyfileProvider) or manage Caddy's JSON config through
|
|
// its admin API (APIProvider).
|
|
type Provider interface {
|
|
// WriteHost creates or updates the configuration for a host.
|
|
WriteHost(h database.Host) error
|
|
// RemoveHost removes the configuration for a host.
|
|
RemoveHost(hostID int) error
|
|
}
|
|
|
|
// GetProvider returns the configured Provider based on CPM_CADDY_MODE.
|
|
func GetProvider() (Provider, error) {
|
|
switch strings.ToLower(config.Configuration.Caddy.Mode) {
|
|
case "", "caddyfile":
|
|
return &CaddyfileProvider{}, nil
|
|
case "api":
|
|
return NewAPIProvider(), nil
|
|
default:
|
|
return nil, fmt.Errorf("unknown caddy mode %q (expected \"caddyfile\" or \"api\")", config.Configuration.Caddy.Mode)
|
|
}
|
|
}
|