Skip to content

refactor(customerio): centralize URL path building in a formatPath helper [AMPB-826]#76

Merged
hownowstephen merged 1 commit into
mainfrom
refactor_AMPB-826_build-urls-with-net-url
Jun 25, 2026
Merged

refactor(customerio): centralize URL path building in a formatPath helper [AMPB-826]#76
hownowstephen merged 1 commit into
mainfrom
refactor_AMPB-826_build-urls-with-net-url

Conversation

@hownowstephen

@hownowstephen hownowstephen commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Adds formatPath, a small printf-style path builder that url.PathEscapes string arguments (so a / inside an ID becomes %2F) and passes non-string args (e.g. int IDs) through unchanged. Routes Track and App API path construction through it across customerio.go, device.go, segments.go, transactional.go, and trigger_broadcast.go. Behavior is preserved; adds url_test.go.

This is a rework of #73 on top of current main.

APIClient.doRequest is unchanged from main.


Note

Medium Risk
Touches URL construction for every outbound API call; regressions could mis-route requests, though behavior is intended to match prior escaping and is covered by new unit tests.

Overview
Introduces formatPath, a shared helper that builds request paths from a printf-style template and automatically url.PathEscapes string arguments (including encoding / as %2F), while leaving non-string args (e.g. segment/broadcast IDs) unchanged.

Track and App API callers now build paths through formatPath instead of ad hoc fmt.Sprintf plus manual escaping: customer identify/track/delete, device add/delete, segment membership URLs, transactional send paths, and broadcast trigger paths. Static paths (e.g. anonymous events, merge customers) use simple string concatenation where there are no dynamic segments.

Adds url_test.go with cases for spaces, slashes in IDs, multiple string segments, and integer path segments.

Reviewed by Cursor Bugbot for commit 045cbee. Bugbot is set up for automated code reviews on this repo. Configure here.

Add formatPath, a printf-style path builder that url.PathEscapes string
args (so '/' inside an ID becomes %2F) and passes non-string args (int
IDs) through. Route Track and App API path construction through it
across customerio.go, device.go, segments.go, transactional.go, and
trigger_broadcast.go. Behavior is preserved. Adds url_test.go.

Follows the helper-around-fmt.Sprintf idiom used by major Go API
clients (e.g. stripe-go's FormatURLPath) rather than a net/url
segments builder.
@hownowstephen hownowstephen force-pushed the refactor_AMPB-826_build-urls-with-net-url branch from 50857d7 to 045cbee Compare June 25, 2026 14:18
@hownowstephen hownowstephen changed the title refactor(customerio): build URLs with net/url instead of fmt.Sprintf [AMPB-826] refactor(customerio): centralize URL path building in a formatPath helper [AMPB-826] Jun 25, 2026
@hownowstephen hownowstephen merged commit 3840e28 into main Jun 25, 2026
10 checks passed
@hownowstephen hownowstephen deleted the refactor_AMPB-826_build-urls-with-net-url branch June 25, 2026 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants