Regarding your question: You’ve just posted a snippet of code but you do not tell us what this code is supposed to do, if it is doing what you want it to do, or if there is any problem or error. What is your question?
// q is your struct
// url is your url.URL
body := &bytes.Buffer{}
if err := json.NewEncoder(body).Encode(&q); err != nil {
panic(err)
}
req, err := http.NewRequest(http.MethodPost, url.String(), body)