Skip to content

Commit 46ed56e

Browse files
committed
feat(x): improve URL construction for API requests
- Add proper handling of DefaultAPIBase in URL construction - Ensure consistent path separator handling with TrimRight/TrimLeft - Add debug logging for constructed API URL - Fix URL concatenation to prevent double slashes This change ensures proper URL construction when making API requests, incorporating the base API path from environment configuration.
1 parent b01fc78 commit 46ed56e

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

pkg/x/search.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,13 @@ func SearchX(baseURL string, apiPath string, params SearchParams) (*SearchRespon
9090
apiPath = DefaultAPIPath
9191
}
9292

93-
// Construct full URL
94-
apiURL := fmt.Sprintf("%s/%s", strings.TrimRight(baseURL, "/"), strings.TrimLeft(apiPath, "/"))
93+
// Construct full URL with proper path components
94+
baseURL = strings.TrimRight(baseURL, "/")
95+
apiBase := strings.TrimRight(DefaultAPIBase, "/")
96+
apiPath = strings.TrimLeft(apiPath, "/")
97+
98+
apiURL := fmt.Sprintf("%s%s/%s", baseURL, apiBase, apiPath)
99+
logger.Debugf("Constructed API URL: %s", apiURL)
95100

96101
// Prepare request body
97102
body := map[string]interface{}{

0 commit comments

Comments
 (0)