1
我是新來的,所以這可能是最基本的。我有一個函數來從URL中檢索json,並且需要在URL中傳遞一個變量整數。如何將變量追加到另一個變量的末尾?這裏是我的代碼:在URL中傳遞變量golang
type content struct {
StationTitle string `json:"StationTitle"`
}
func main() {
resp := content{}
getContent("http://foo.foo2.foo3=variableInteger", &resp)
println(resp.StationTitle)
}
// fetch json
func getContent(url string, target interface{}) error {
r, err := http.Get(url)
if err != nil {
return err
}
defer r.Body.Close()
return json.NewDecoder(r.Body).Decode(target)
}