Documentation
¶
Overview ¶
Package router provides domain-based reverse proxy, automatic TLS via Let's Encrypt, request logging, and server lifecycle management.
router.Proxy("app.example.com", "myapp:5000")
router.Listen(router.WithLogger(), security.New(), application.New(views))
Index ¶
- func AllowDomain(host string) error
- func AllowDomainUnchecked(host string)
- func ClientIP(r *http.Request) string
- func DisallowDomain(host string)
- func Handler(fallback http.Handler) http.Handler
- func Listen(middleware ...func(http.Handler) http.Handler)
- func Proxies() map[string]string
- func Proxy(host, target string)
- func RemoveProxy(host string)
- func ServerIP() string
- func SetCertDir(dir string)
- func WithLogger() func(http.Handler) http.Handler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllowDomain ¶
AllowDomain validates DNS and adds a domain to the TLS whitelist. Returns an error if the domain doesn't resolve.
func AllowDomainUnchecked ¶
func AllowDomainUnchecked(host string)
AllowDomainUnchecked adds a domain without DNS validation. Use for system domains loaded from config/env at startup.
func DisallowDomain ¶
func DisallowDomain(host string)
DisallowDomain removes a domain from the TLS whitelist.
func Handler ¶
Handler returns an http.Handler that does domain-based proxy routing. Requests matching a Proxy() entry are reverse-proxied to the target. All other requests fall through to the provided handler.
func Listen ¶
Listen is the declarative entry point. It composes the middleware chain and starts the server. The last middleware is typically the application. Blocks until shutdown signal (SIGINT/SIGTERM).
router.Listen(
router.WithLogger(),
security.New(security.WithNonce(), security.WithHeaders()),
application.New(views, ...),
)
func Proxy ¶
func Proxy(host, target string)
Proxy maps a domain to a backend target (e.g. "myapp:5000"). Requests with this Host header are reverse-proxied to the target.
func ServerIP ¶
func ServerIP() string
ServerIP returns this server's public IP (cached after first call).
func SetCertDir ¶
func SetCertDir(dir string)
SetCertDir sets the directory for autocert certificate storage. Must be called before Listen.
Types ¶
This section is empty.