Golang-语法错误:顶层声明后出现意外的{



我是Golang的新手,在我开始编写的文件中,它看起来像这样:

package controllers
import (
"encoding/json"
"io/ioutil"
"net/http"
)
type Coordinate Struct {
Lat string `json:"lat"`
Lng string `json:"lng"`
}
type Location Struct {
Name string
Country string
CountryCode string
Center Coordinate
Coordinates []Coordinate
}
const baseURL = "https://nominatim.openstreetmap.org/lookup"
const osmIDs = "R8063578"
// ImportRegions fetches, transforms and saves geocoding data from osm as json file
func (server *Server) ImportRegions(w http.ResponseWriter, r *http.Request) {
res, err := http.Get(baseURL + "?osm_ids=" + osmIDs + "&format=json&polygon_geojson=1")
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
}
bytes, err := ioutil.ReadAll(res.Body)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
}
var location Location
if err := json.Unmarshal(bytes, &location); err != nil {
fmt.Println("Error parsing json", err)
}
fmt.Println(location)
}

我收到以下错误:

api/controllers/gecoder.go:10:24: syntax error: unexpected { after top level declaration
api/controllers/gecoder.go:16:22: syntax error: unexpected { after top level declaration

为什么我定义的两种类型都会出现错误?我应该如何解决这个问题?

Struct语法不正确,您需要struct(小写(

type Coordinate struct {
[...]

结构-围棋之旅

相关内容

最新更新