I understand you're encountering an issue with API parameters containing special characters like "/". Here's how to solve it:
1. URL-Encode the Parameter:
Before constructing the request URL, encode the "search" parameter value using a URL encoding function:
import "net/url"
searchEncoded := url.QueryEscape(search)
response, err := http.NewRequest(http.MethodGet, companyhelper.GetHisUrl(cmpId)+"/tregistration/search/"+searchEncoded, nil)
2. Adjust the Route Definition (if necessary):
If you have control over the API route definition, consider removing unnecessary slashes or using more flexible path parameters:
router.GET("/getdate/:param1/:param2", func(c *gin.Context) {
param1 := c.Param("param1")
param2 := c.Param("param2")
})
3. Reconstruct the URL with a URL Builder (optional):
For complex URLs with multiple parameters, use a URL builder library to ensure proper encoding:
import "net/url"
u, err := url.Parse(companyhelper.GetHisUrl(cmpId) + "/tregistration/search/")
if err != nil {
}
u.RawQuery = url.Values{"search": {search}}.Encode()
finalURL := u.String()
response, err := http.NewRequest(http.MethodGet, finalURL, nil)