Documentation ¶
Overview ¶
Package goweather lets anybody easily fetch weather information using the OpenWeatherMap API
Before playing around with the library, get an API key at https://openweathermap.org.
Create an API structure :
api, _ := goweather.NewAPI("token", "en", "metric")
Get the current weather using this API :
data, _ := api.Current("Lyon, FR")
Get the forecast using this API :
data, _ := api.Forecast("Lyon, FR")
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type API ¶
type API struct {
// contains filtered or unexported fields
}
API is the main piece of the library : it centralizes requests made to OpenWeatherMap and parameters.
func (API) Current ¶
Current gets current weather information for a specific location
Example ¶
Example of fetching current weather
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 !") }
Output:
func (API) Forecast ¶
Forecast get forecasts for a specific location
Example ¶
Example of fetching 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) }
Output:
Click to show internal directories.
Click to hide internal directories.