I'm getting the following two errors on the following code and it won't compile. I'm not really sure what I've done wrong in this code. Here are my errors: .\app.go:52:52: syntax error: unexpected }, expecting comma or ) .\app.go:55:1: syntax error: non-declaration statement outside function body. I don't know what else to check in the following code. Any help would be appreciated
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"time"
)
type Results struct {
Results []Result `json:"results"`
}
type Result struct {
Name string `json:"name"`
Rating float64 `json:"rating"`
}
func main() {
url := "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=33.985,-118.4695&radius=500&type=restaurant&key=MYKEY"
resultClient := http.Client{
Timeout: time.Second * 2,
}
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
log.Fatal(err)
}
req.Header.Set("User-Agent", "eattheshoals")
res, getErr := resultClient.Do(req)
if getErr != nil {
log.Fatal(getErr)
}
byteValue, _ := ioutil.ReadAll(res.Body)
//if readErr != nil {
// log.Fatal(readErr)
//}
var results Results
jsonErr := json.Unmarshal(byteValue, &results)
if jsonErr != nil {
log.Fatal(jsonErr)
}
for i := 0; i < len(results.Results); i++ {
fmt.Println("Name " + results.Results[i].Name)
fmt.Println("Rating " + results.Results[i].Rating})
}
}