Browse Source

添加更新时间字段

liuxiulin 2 months ago
parent
commit
4232f0cd1f
2 changed files with 17 additions and 9 deletions
  1. 6 0
      .idea/vcs.xml
  2. 11 9
      api.go

+ 6 - 0
.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
+  </component>
+</project>

+ 11 - 9
api.go

@@ -104,15 +104,16 @@ type AirInfo struct {
 }
 }
 
 
 type WeatherInfoResp struct {
 type WeatherInfoResp struct {
-	Location    string `json:"location"`
-	Text        string `json:"text"`
-	Code        string `json:"code"`
-	Temperature int    `json:"temperature"`
-	Humidity    int    `json:"humidity"`
-	AQI         int    `json:"aqi"`
-	PM25        int    `json:"pm25"`
-	PM10        int    `json:"pm10"`
-	Quality     string `json:"quality"`
+	Location    string    `json:"location"`
+	Text        string    `json:"text"`
+	Code        string    `json:"code"`
+	Temperature int       `json:"temperature"`
+	Humidity    int       `json:"humidity"`
+	AQI         int       `json:"aqi"`
+	PM25        int       `json:"pm25"`
+	PM10        int       `json:"pm10"`
+	Quality     string    `json:"quality"`
+	LastUpdate  time.Time `json:"last_update"`
 }
 }
 
 
 func GetWeatherInfo(location, key string) (*WeatherInfoResp, error) {
 func GetWeatherInfo(location, key string) (*WeatherInfoResp, error) {
@@ -126,6 +127,7 @@ func GetWeatherInfo(location, key string) (*WeatherInfoResp, error) {
 	result.Code = info.Results[0].Now.Code
 	result.Code = info.Results[0].Now.Code
 	result.Temperature, _ = strconv.Atoi(info.Results[0].Now.Temperature)
 	result.Temperature, _ = strconv.Atoi(info.Results[0].Now.Temperature)
 	result.Humidity, _ = strconv.Atoi(info.Results[0].Now.Humidity)
 	result.Humidity, _ = strconv.Atoi(info.Results[0].Now.Humidity)
+	result.LastUpdate = info.Results[0].LastUpdate
 	airInfo, err := GetAirInfoByLocation(location, key)
 	airInfo, err := GetAirInfoByLocation(location, key)
 	if err != nil {
 	if err != nil {
 		return nil, err
 		return nil, err