weather

package module
v1.0.17 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2024 License: MIT Imports: 14 Imported by: 1

README

Go Reference GitHub go.mod Go version GitHub release (latest by date) Go Report Card Actions Status

HomeDashboard Weather DataSource

Fetches weather data from Open Weather Map API using it's One Call API to get current weather and a 7-days forcast.

Config

You have to pass the OpenWeatherMap API url, together with a geographical location (logitude, latitude) as config. Optional config param are units. More details about loading config at https://github.com/tommzn/go-config

Config example with all required values
weather:
  owm:
    url: https://api.openweathermap.org/data/2.5
    longitude: 37.33195305634116 
    latitude: -122.0309010022451
Full Config
weather:
  owm:
    url: https://api.openweathermap.org/data/2.5
    longitude: 37.33195305634116 
    latitude: -122.0309010022451
    units: metric

Secrets

OpenWeatherMap requires an API key to call the One Call API. You have to pass a SecretsManager which is able to obtain an API key as OWM_API_KEY

Get Weather Data

After creating a new datasource, you can fetch current weather data and a forecast. If anything works well Fetch will return a weather data struct or otherwise an error.


    import (
       weather "github.com/tommzn/hdb-datasource-weather"  
       events "github.com/tommzn/hdb-events-go"  
    )
    
    datasource, err := weather.New(config, secretsmanager)
    if err != nil {
        panic(err)
    }

    weatherData, err := datasource.Fetch()
    if err != nil {
        panic(err)
    }

    fmt.Printf("Current Temperature: %.2f\n", weatherData.(events.WeatherData).Current.Temperature)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(config config.Config, secrestmanager secrets.SecretsManager, logger log.Logger) (core.DataSource, error)

New returns a new weather datasource

Types

type OpenWeatherMapClient added in v1.0.2

type OpenWeatherMapClient struct {
	// contains filtered or unexported fields
}

OpenWeatherMapClient handles requests for current weather and a 7-days forecast to API provides by Open Weather Map. It can be used as a datasource directly.

func (*OpenWeatherMapClient) Fetch added in v1.0.2

func (client *OpenWeatherMapClient) Fetch() (proto.Message, error)

Fetch calls the OpenWeatherMap One Call api to get the current weather and a 7-days forecast.

Directories

Path Synopsis
lambda module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL