weather/qweather/get.go

30 lines
519 B
Go
Raw Normal View History

2025-01-02 22:57:51 +08:00
package qweather
import (
"encoding/json"
"io"
"net/http"
)
// 获取天气
func Get(location_id, weather_type_id int, dev bool) (json.RawMessage, error) {
// 生成url
url, err := makeURL(dev, location_id, weather_type_id)
if err != nil {
return nil, err
}
// 发送请求, 获取数据
resp, err := http.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
// 读取数据
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
// 返回数据
return body, nil
}