appc: factor app connector arguments into a Config type (#17389)

Replace the positional arguments to NewAppConnector with a Config struct.
Update the existing uses. Other than the API change, there are no functional
changes in this commit.

Updates #15160
Updates #17192

Change-Id: Ibf37f021372155a4db8aaf738f4b4f2c746bf623
Signed-off-by: M. J. Fromberger <fromberger@tailscale.com>
This commit is contained in:
M. J. Fromberger
2025-10-01 11:39:01 -07:00
committed by GitHub
parent 05a4c8e839
commit 6f7ce5eb5d
5 changed files with 133 additions and 38 deletions

View File

@@ -162,17 +162,36 @@ type AppConnector struct {
writeRateDay *rateLogger
}
// Config carries the settings for an [AppConnector].
type Config struct {
// Logf is the logger to which debug logs from the connector will be sent.
// It must be non-nil.
Logf logger.Logf
// RouteAdvertiser allows the connector to update the set of advertised routes.
// It must be non-nil.
RouteAdvertiser RouteAdvertiser
// RouteInfo, if non-nil, use used as the initial set of routes for the
// connector. If nil, the connector starts empty.
RouteInfo *RouteInfo
// StoreRoutesFunc, if non-nil, is called when the connector's routes
// change, to allow the routes to be persisted.
StoreRoutesFunc func(*RouteInfo) error
}
// NewAppConnector creates a new AppConnector.
func NewAppConnector(logf logger.Logf, routeAdvertiser RouteAdvertiser, routeInfo *RouteInfo, storeRoutesFunc func(*RouteInfo) error) *AppConnector {
func NewAppConnector(c Config) *AppConnector {
ac := &AppConnector{
logf: logger.WithPrefix(logf, "appc: "),
routeAdvertiser: routeAdvertiser,
storeRoutesFunc: storeRoutesFunc,
logf: logger.WithPrefix(c.Logf, "appc: "),
routeAdvertiser: c.RouteAdvertiser,
storeRoutesFunc: c.StoreRoutesFunc,
}
if routeInfo != nil {
ac.domains = routeInfo.Domains
ac.wildcards = routeInfo.Wildcards
ac.controlRoutes = routeInfo.Control
if c.RouteInfo != nil {
ac.domains = c.RouteInfo.Domains
ac.wildcards = c.RouteInfo.Wildcards
ac.controlRoutes = c.RouteInfo.Control
}
ac.writeRateMinute = newRateLogger(time.Now, time.Minute, func(c int64, s time.Time, l int64) {
ac.logf("routeInfo write rate: %d in minute starting at %v (%d routes)", c, s, l)