This Go package provides simple bindings to the Meteologix/Kachelmann-Wetter API. It provides access to "Stations", "Current Weather" and "Forecast". An API key or username/password pair is required to access the endpoints. An API key can be configured in your account settings.
go-meteologix follows idiomatic Go style and best practice. It's only dependency is the Go Standard Library.
For Geolocation lookups, the package makes use of the OpenStreetMap Nominatim API. This requires no API key.
The library is fully documented using the execellent GoDoc functionality. Check out the full reference on pkg.go.dev for details.
This program uses the OSM Nominatim API to lookup the GeoLocation data for Berlin, Germany.
On success it will return the Latitude
and Longitude
fields.
package main
import (
"fmt"
"os"
"github.com/wneessen/go-meteologix"
)
func main() {
c := meteologix.New()
gl, err := c.GetGeoLocationByName("Berlin, Germany")
if err != nil {
fmt.Println("GeoLocation lookup failed", err)
os.Exit(1)
}
fmt.Printf("GeoLocation - Latitude: %f, Longitude: %f\n", gl.Latitude,
gl.Longitude)
}
This program makes use of the GeoLocation support in the package. It looks up the GeoLocation of the location in question and queries the Kachelmann API for the station nearest to that location. The returned list of stations is sorted by distance to the provided GeoLocation. In our example we will return the first station in that list.
package main
import (
"fmt"
"os"
"github.com/wneessen/go-meteologix"
)
func main() {
client := meteologix.New(meteologix.WithAPIKey(os.Getenv("API_KEY")))
stations, err := client.StationSearchByLocation("Berlin, Germany")
if err != nil {
fmt.Printf("station lookup failed: %s", err)
os.Exit(1)
}
if len(stations) > 0 {
fmt.Printf("Station no. 1: %+v", stations[0])
}
}
This program takes a station ID and looks up the latest station observation data and returns the Observation type. This type then has lots of methods to access the observation data. In our example we will print out the formatted values for the current temperature and the dewpoint.
package main
import (
"fmt"
"math"
"os"
"github.com/wneessen/go-meteologix"
)
func main() {
client := meteologix.New(meteologix.WithAPIKey(os.Getenv("API_KEY")))
observation, err := client.ObservationLatestByStationID("H744")
if err != nil {
fmt.Printf("station lookup failed: %s", err)
os.Exit(1)
}
if observation.Temperature().IsAvailable() {
fmt.Printf("Temperature at station: %s\n", observation.Temperature())
fmt.Printf("Temperature at station in Fahrenheit: %s\n", observation.Temperature().FahrenheitString())
}
if observation.Dewpoint().IsAvailable() {
fmt.Printf("Dewpoint in Fahrenheit: %s\n", observation.Dewpoint().FahrenheitString())
}
}
This program takes a location string, searches for the weather station with the shortest distancen and looks up the station's latest observation data. We then print out the temperature in C and F, as well as the station name and the time of the measurement (if the data point is available from that station).
package main
import (
"fmt"
"os"
"github.com/wneessen/go-meteologix"
)
func main() {
client := meteologix.New(meteologix.WithAPIKey(os.Getenv("API_KEY")))
observation, s, err := client.ObservationLatestByLocation("Ehrenfeld, Germany")
if err != nil {
fmt.Printf("Failed: %s\n", err)
os.Exit(1)
}
if observation.Temperature().IsAvailable() {
fmt.Printf("Temperature at %s: %s/%s (time of measurement: %s)\n",
s.Name, observation.Temperature(), observation.Temperature().FahrenheitString(),
observation.Temperature().DateTime().Local().Format("15:04h"))
}
}
go-meteologix was authored and developed by Winni Neessen.
Big thanks to the following people, for contributing to the go-meteologix project (either in form of code, reviewing code, writing documenation or contributing in any other form):
- Maria Letta (designed the go-meteologix logo)