Added "alert" field to weather route and fixed some bugs
This commit is contained in:
@@ -62,3 +62,32 @@ func (t ZephyrTime) MarshalJSON() ([]byte, error) {
|
||||
|
||||
return []byte("\"" + fmtTime + "\""), nil
|
||||
}
|
||||
|
||||
type ZephyrAlertDate struct {
|
||||
Date time.Time
|
||||
}
|
||||
|
||||
func (t *ZephyrAlertDate) UnmarshalJSON(b []byte) error {
|
||||
s := strings.Trim(string(b), "\"")
|
||||
if s == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
t.Date, err = time.Parse("Monday, 2006/01/02 15:04", s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t ZephyrAlertDate) MarshalJSON() ([]byte, error) {
|
||||
if t.Date.IsZero() {
|
||||
return []byte("\"\""), nil
|
||||
}
|
||||
|
||||
fmtTime := t.Date.Format("Monday, 2006/01/02 3:04 PM")
|
||||
|
||||
return []byte("\"" + fmtTime + "\""), nil
|
||||
}
|
||||
|
||||
@@ -1,12 +1,22 @@
|
||||
package types
|
||||
|
||||
// The WeatherAlert data type, representing a
|
||||
// weather alert
|
||||
type WeatherAlert struct {
|
||||
Event string `json:"event"`
|
||||
Start ZephyrAlertDate `json:"startDate"`
|
||||
End ZephyrAlertDate `json:"endDate"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
// The Weather data type, representing the weather of a certain location
|
||||
type Weather struct {
|
||||
Date ZephyrDate `json:"date"`
|
||||
Temperature string `json:"temperature"`
|
||||
Min string `json:"min"`
|
||||
Max string `json:"max"`
|
||||
Condition string `json:"condition"`
|
||||
FeelsLike string `json:"feelsLike"`
|
||||
Emoji string `json:"emoji"`
|
||||
Date ZephyrDate `json:"date"`
|
||||
Temperature string `json:"temperature"`
|
||||
Min string `json:"min"`
|
||||
Max string `json:"max"`
|
||||
Condition string `json:"condition"`
|
||||
FeelsLike string `json:"feelsLike"`
|
||||
Emoji string `json:"emoji"`
|
||||
Alerts []WeatherAlert `json:"alerts"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user