printf-style function with dynamic format string and no further arguments should use print-style function instead
My VScode keeps highlighting my fmt.Fprintf(w, prettyJSON.String())
statements with the warning stated above. Not sure what it means, or how to fix. Here is an example on how I use Fprintf()
:
func (s *Server) getWorkSpaces(w http.ResponseWriter, r *http.Request) {
client := &http.Client{}
var prettyJSON bytes.Buffer
req, err := http.NewRequest("GET", "url.com", nil)
if err != nil {
// if there was an error parsing the request, return an error to user and quit function
responses.ERROR(w, http.StatusBadRequest, fmt.Errorf("unable to read request body: %v", err))
return
}
resp, err := client.Do(req)
if err != nil {
// if there was an error parsing the request, return an error to user and quit function
responses.ERROR(w, http.StatusBadRequest, fmt.Errorf("unable to read request body: %v", err))
return
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatalln(err)
}
error := json.Indent(&prettyJSON, body, "", "\t")
if error != nil {
log.Println("JSON parse error: ", error)
return
}
fmt.Fprintf(w, prettyJSON.String())
}
How can I stop this error? Could someone explain to me why my VScode is throwing that up on the screen? Note that my code runs and works well.