我正在从我的golang api调用另一个api服务,但是在获取结果时,我的回声c.string响应中附加了一个空值
[{"id":8,"name":null,"description":null,"code":null,"maker":null,"model":null,"duration":null,"maximum_speed":null,"average_speed":null,"maximum_rise_rate":null,"average_rise_rate":null,"maximum_fall_rate":null,"average_fall_rate":null,"turn_rate":null,"camera_angle":null,"moderate_horizontally_speed":null,"moderate_vertical_speed":null,"maximum_horizontally_speed":null,"maximum_vertical_speed":null,"minimum_horizontally_speed":null,"minimum_vertical_speed":null,"key":null,"note":null,"status":true,"deleted":false,"create_date":"2019-05-27T09:47:28.441Z","update_date":"2019-05-27T09:47:28.441Z"}]null <- this null
statusCode, response, err := utils.HTTPGet(utils.AircraftsURL())
if err != nil && statusCode != 200 {
return c.String(statusCode, err.Error())
}
return c.String(statusCode, response)
这是我的代码,它从已部署的url获取请求
func HTTPGet(url string) (int, string, error) {
client := &http.Client{
Timeout: 10 * time.Second,
}
req, err := http.NewRequest("GET", url, nil)
if err != nil {
log.Fatalf("cannot create a new request GET at HTTPGet = %v", err)
}
// req.Header.Set("Content-Type", "application/json")
res, err := client.Do(req)
if err != nil {
log.Fatalf("cannot send a request to the client at HTTPGet = %v", err)
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
return res.StatusCode, string(body), err
}
我的要求是他们的任何问题吗?我不知道为什么将null值附加到我的响应帖子中并得到