refactor(customerio): centralize URL path building in a formatPath helper [AMPB-826]#76
Merged
Conversation
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.
50857d7 to
045cbee
Compare
joeybaer
approved these changes
Jun 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
formatPath, a small printf-style path builder thaturl.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 acrosscustomerio.go,device.go,segments.go,transactional.go, andtrigger_broadcast.go. Behavior is preserved; addsurl_test.go.This is a rework of #73 on top of current main.
APIClient.doRequestis 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 aprintf-style template and automaticallyurl.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
formatPathinstead of ad hocfmt.Sprintfplus 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.gowith 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.