Skip to content

Commit b8b0e45

Browse files
committed
feat: add listener policy calculator
1 parent 35cd3b9 commit b8b0e45

2 files changed

Lines changed: 38 additions & 15 deletions

File tree

internal/bootstrap/app_bootstrap.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -255,21 +255,7 @@ func (app *BootstrapApp) Setup() error {
255255
}
256256

257257
// setup listeners
258-
runUnix := app.config.Server.SocketPath != ""
259-
runHTTP := app.config.Server.SocketPath == "" || app.config.Server.ConcurrentListenersEnabled
260-
runTailscale := app.services.tailscaleService != nil
261-
262-
if runHTTP {
263-
app.listeners = append(app.listeners, ListenerHTTP)
264-
}
265-
266-
if runUnix {
267-
app.listeners = append(app.listeners, ListenerUnix)
268-
}
269-
270-
if runTailscale {
271-
app.listeners = append(app.listeners, ListenerTailscale)
272-
}
258+
app.listeners = app.calculateListenerPolicy()
273259

274260
if app.config.Server.ConcurrentListenersEnabled {
275261
app.log.App.Info().Msg("Concurrent listeners enabled, will run on all available listeners")

internal/bootstrap/router_bootstrap.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,43 @@ func (app *BootstrapApp) runListeners() (chan error, error) {
8585
return lec, nil
8686
}
8787

88+
// The way we calculate listeners is as follows:
89+
// If concurrent listeners are disabled, we pick the first available listener, so:
90+
// 1. If tailscale is enabled, we use tailscale
91+
// 2. If socket path is configured, we use unix socket
92+
// 3. Finally if none is configured we use http
93+
// If concurrent listeners are enabled, we add all available listeners in the following order
94+
func (app *BootstrapApp) calculateListenerPolicy() []Listener {
95+
l := []Listener{}
96+
97+
if !app.config.Server.ConcurrentListenersEnabled {
98+
if app.config.Tailscale.Enabled {
99+
l = append(l, ListenerTailscale)
100+
return l
101+
}
102+
103+
if app.config.Server.SocketPath != "" {
104+
l = append(l, ListenerUnix)
105+
return l
106+
}
107+
108+
l = append(l, ListenerHTTP)
109+
return l
110+
}
111+
112+
if app.config.Server.SocketPath != "" {
113+
l = append(l, ListenerUnix)
114+
}
115+
116+
if app.config.Tailscale.Enabled {
117+
l = append(l, ListenerTailscale)
118+
}
119+
120+
l = append(l, ListenerHTTP)
121+
122+
return l
123+
}
124+
88125
func (app *BootstrapApp) listenerFromType(listenerType Listener) (func() error, error) {
89126
switch listenerType {
90127
case ListenerHTTP:

0 commit comments

Comments
 (0)