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)
}