resty
resty copied to clipboard
Request URL as empty string
Hi,
package main
import (
"fmt"
"github.com/go-resty/resty/v2"
)
func main() {
client := resty.New()
req := client.
SetBaseURL("https://example.com").
R().
SetQueryParam("page", "1")
/*
result: ""
expected: "https://example.com?page=1"
*/
fmt.Println(req.URL)
req.Get("")
req.SetQueryParam("page", "2")
/*
result: "https://example.com?page=1"
expected: "https://example.com?page=2"
*/
fmt.Println(req.URL)
}
This piece reveals a weird behavior. Those prints are not correct. I am doing something wrong?. Thank you all in advance.
I'm pretty sure Request.URL
is purposely not set until a request is finally executed. In your example, that happens with req.Get
.
So, the only way for caching requests is prebuilding the url. Right??