-
Notifications
You must be signed in to change notification settings - Fork 71
/
forecast5.go
50 lines (43 loc) · 1.14 KB
/
forecast5.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package openweathermap
import (
"encoding/json"
"io"
"strings"
"time"
)
type DtTxt struct {
time.Time
}
func (dt *DtTxt) UnmarshalJSON(b []byte) error {
t, err := time.Parse("2006-01-02 15:04:05", strings.Trim(string(b), "\""))
dt.Time = t
return err
}
func (t *DtTxt) MarshalJSON() ([]byte, error) {
return json.Marshal(t)
}
// Forecast5WeatherList holds specific query data
type Forecast5WeatherList struct {
Dt int `json:"dt"`
Main Main `json:"main"`
Weather []Weather `json:"weather"`
Clouds Clouds `json:"clouds"`
Wind Wind `json:"wind"`
Rain Rain `json:"rain"`
Snow Snow `json:"snow"`
DtTxt DtTxt `json:"dt_txt"`
}
// Forecast5WeatherData will hold returned data from queries
type Forecast5WeatherData struct {
// COD string `json:"cod"`
// Message float64 `json:"message"`
City City `json:"city"`
Cnt int `json:"cnt"`
List []Forecast5WeatherList `json:"list"`
}
func (f *Forecast5WeatherData) Decode(r io.Reader) error {
if err := json.NewDecoder(r).Decode(&f); err != nil {
return err
}
return nil
}