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:
@@ -149,8 +149,29 @@ func NewMux(
|
||||
http.Redirect(w, r, redirectURL, http.StatusSeeOther)
|
||||
})
|
||||
|
||||
r.Get("/connectors/complete", func(w http.ResponseWriter, r *http.Request) {
|
||||
stateToken := r.URL.Query().Get("state")
|
||||
r.Get("/connectors/complete", handleConnectorComplete(
|
||||
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 == "" {
|
||||
httpserver.RenderError(w, http.StatusBadRequest, fmt.Errorf("missing state parameter"))
|
||||
return
|
||||
@@ -211,7 +232,6 @@ func NewMux(
|
||||
}
|
||||
}
|
||||
|
||||
// Append connector_id to the redirect URL so frontend can create the bridge
|
||||
redirectURL := state.ContinueURL
|
||||
if redirectURL == "" {
|
||||
redirectURL = baseURL.WithPath("/organizations/" + organizationID.String()).MustString()
|
||||
@@ -228,10 +248,7 @@ func NewMux(
|
||||
parsedURL.RawQuery = q.Encode()
|
||||
|
||||
safeRedirect.Redirect(w, r, parsedURL.String(), "/", http.StatusSeeOther)
|
||||
})
|
||||
})
|
||||
|
||||
return r
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Resolver) ProboService(ctx context.Context, tenantID gid.TenantID) *probo.TenantService {
|
||||
|
||||
Reference in New Issue
Block a user