I'm using the following code:
Go
type ResponseData struct {
Message string `json:"message"`
}
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
w.Header().Set("Access-Control-Allow-Headers", "Accept, Content-Type, Content-Length, Authorization")
json.NewEncoder(w).Encode(ResponseData{Message: "Hello, World"})
JavaScript
fetch('http://localhost:8080/get', {
method: "GET"
})
.then(res => res.json())
.then(data => console.log(data))
.catch(err => console.log(err.message))
The code is working fine, but when someone enters http://localhost:8080/get, it shows {"message":"Hello, World"}, is there a way to get the object only in JavaScript?