Getting backlashes in GET response


I am new with Go. I have reviewed the documentation on how to make http.ResponseWriter work. I built a GET request to an API that looks like the following:

    ```func main() {
    	router := mux.NewRouter()
    	router.HandleFunc("/gomk/fixall/{server}", handler).Methods("GET")
    	headers := handlers.AllowedHeaders([]string
        {"X-Requested-With", "Content-Type", "Authorization", 
        "access-control-allow-headers", "access-control-allow-methods",
    	methods := handlers.AllowedMethods([]string
        {"GET", "POST", "PUT", "DELETE", "OPTIONS"})
    	origins := handlers.AllowedOrigins([]string{"*"})

    	fmt.Println("Server is running at port 8000")
    	log.Fatal(http.ListenAndServe(":8000", handlers.CORS(headers, 
        methods, origins)(router)))

    func handler(w http.ResponseWriter, r *http.Request) {
    	params := mux.Vars(r)
    	server := params["server"]`
    resp, err := http.Get(`{"hostname":"` 
    + params["server"] + `","mode":"test"}`)
    	if err != nil {

    	defer resp.Body.Close()

    	body, err := ioutil.ReadAll(resp.Body)
    	if err != nil {


The call does return the correct information in the browser at port 8000: however, I am getting the following backslashes in the response:

"{\"result\": \"

Where it actually should be:

{"result": "

The correct output without the backlashes does show in the console output. Can somebody please help with the reason why I am getting those backlashes in the browser and what type of configuration would help me receive the output that I am looking for?

You json encode a string and not an object. Maybe you should just write the string from the api as it is?

ok. Will investigate on that. Just to clarify my post, currently in the console output I do receive {"result": " without the backlashes (just corrected my post).

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.