I have the following code sample and wondering how can I return the proper json?
package main
import (
"fmt"
"net/http"
"net/url"
"strings"
)
func main() {
apiURL := "http://example.com"
resource := "/sample"
data := url.Values{}
data.Add("test", "y")
u, _ := url.ParseRequestURI(apiURL)
u.Path = resource
urlStr := u.String()
client := &http.Client{}
r, _ := http.NewRequest("POST", urlStr, strings.NewReader(data.Encode())) // URL-encoded payload
resp, _ := client.Do(r)
fmt.Println(resp.Status)
fmt.Println(resp.ContentLength)
fmt.Println(resp.Request)
// fmt.Println(json.NewDecoder(resp.Body.Decode()))
}
Once I get the response, how can I accurately return a JSON response?