Extract connector complete handler from NewMux

Reduce closure size in NewMux by extracting the /connectors/complete
handler into a dedicated handleConnectorComplete function. Cache
r.URL.Query() into a local variable to avoid repeated parsing.

Signed-off-by: Aurélien Sibiril <81782+aureliensibiril@users.noreply.github.com>
This commit is contained in:
Aurélien Sibiril
2026-04-06 21:04:48 +02:00
parent 9fc0cd577b
commit b2d5f49bef

View File

@@ -149,8 +149,29 @@ func NewMux(
http.Redirect(w, r, redirectURL, http.StatusSeeOther) http.Redirect(w, r, redirectURL, http.StatusSeeOther)
}) })
r.Get("/connectors/complete", func(w http.ResponseWriter, r *http.Request) { r.Get("/connectors/complete", handleConnectorComplete(
stateToken := r.URL.Query().Get("state") logger,
baseURL,
proboSvc,
connectorRegistry,
safeRedirect,
))
})
return r
}
func handleConnectorComplete(
logger *log.Logger,
baseURL *baseurl.BaseURL,
proboSvc *probo.Service,
connectorRegistry *connector.ConnectorRegistry,
safeRedirect *saferedirect.SafeRedirect,
) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
query := r.URL.Query()
stateToken := query.Get("state")
if stateToken == "" { if stateToken == "" {
httpserver.RenderError(w, http.StatusBadRequest, fmt.Errorf("missing state parameter")) httpserver.RenderError(w, http.StatusBadRequest, fmt.Errorf("missing state parameter"))
return return
@@ -211,7 +232,6 @@ func NewMux(
} }
} }
// Append connector_id to the redirect URL so frontend can create the bridge
redirectURL := state.ContinueURL redirectURL := state.ContinueURL
if redirectURL == "" { if redirectURL == "" {
redirectURL = baseURL.WithPath("/organizations/" + organizationID.String()).MustString() redirectURL = baseURL.WithPath("/organizations/" + organizationID.String()).MustString()
@@ -228,10 +248,7 @@ func NewMux(
parsedURL.RawQuery = q.Encode() parsedURL.RawQuery = q.Encode()
safeRedirect.Redirect(w, r, parsedURL.String(), "/", http.StatusSeeOther) safeRedirect.Redirect(w, r, parsedURL.String(), "/", http.StatusSeeOther)
}) }
})
return r
} }
func (r *Resolver) ProboService(ctx context.Context, tenantID gid.TenantID) *probo.TenantService { func (r *Resolver) ProboService(ctx context.Context, tenantID gid.TenantID) *probo.TenantService {