-
Notifications
You must be signed in to change notification settings - Fork 0
/
examples_test.go
43 lines (37 loc) 路 885 Bytes
/
examples_test.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
package goweather
import (
"fmt"
"time"
)
// Example of fetching current weather
func ExampleAPI_Current() {
api, err := NewAPI("", "en", "metric")
if err != nil {
panic(err)
}
data, err := api.Current("Lyon,FR")
if err != nil {
panic(err)
}
fmt.Println(data.City.Name, ":", data.Conditions.Description)
if data.Conditions.Clouds < 20 {
println("What a beautiful moment ! Go outside !")
}
}
// Example of fetching forecast
func ExampleAPI_Forecast() {
api, err := NewAPI("", "en", "metric")
if err != nil {
panic(err)
}
data, err := api.Forecast("Lyon,FR")
if err != nil {
panic(err)
}
fmt.Println(data.City.Name)
println("---------------")
for _, condition := range data.Conditions {
conditionTime := time.Unix(int64(condition.Timestamp), 0)
fmt.Printf("At %d:%d : %s", conditionTime.Hour(), conditionTime.Minute(), condition.Description)
}
}