openweather

package
v0.0.0-...-ea69528 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Current = iota
	Minutely
	Hourly
	Daily
	Alerts
	Standard
	Metric
	Imperial
)

Const enums for query options/settings

Variables

View Source
var (

	// Map to store emojis
	Emojis map[string]string
)

Functions

This section is empty.

Types

type ErrAPIError

type ErrAPIError struct {
	Err  error
	Msg  string
	Code int
}

ErrAPIError is returned when the API returns an error

func (*ErrAPIError) Error

func (e *ErrAPIError) Error() string

type ErrNoAPIKey

type ErrNoAPIKey struct {
	Err error
	Msg string
}

ErrNoAPIKey is returned when no API key is provided

func (*ErrNoAPIKey) Error

func (e *ErrNoAPIKey) Error() string

Error returns the error message

type ErrNoLocation

type ErrNoLocation struct {
	Err error
	Msg string
}

ErrNoLocation is returned when no location is provided

func (*ErrNoLocation) Error

func (e *ErrNoLocation) Error() string

Error returns the error message

type ErrorResponse

type ErrorResponse struct {
	Cod     int    `json:"cod"`
	Message string `json:"message"`
}

type Location

type Location struct {
	Lat float64
	Lon float64
}

Location for the weather query

type Openweather

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

Openweather for the weather query

func New

func New(opts ...func(*Openweather)) (*Openweather, error)

New returns a new Config with the given options

func (*Openweather) GetOneCallWeather

func (c *Openweather) GetOneCallWeather() (*Weather, error)

GetOneCallWeather returns the current, minute, hourly, and daily weather plus alerts

type Option

type Option func(c *Openweather)

Options for the weather query

func WithAPIKey

func WithAPIKey(apikey string) Option

WithAPIKey sets the API key

func WithExcludes

func WithExcludes(excludes ...int) Option

WithExcludes sets the exclude list

func WithLanguage

func WithLanguage(lang string) Option

WithLanguage sets the language

func WithLocation

func WithLocation(location *Location) Option

WithLocation sets the location

func WithLogger

func WithLogger(log *zerolog.Logger) Option

WithLogger sets the logger

func WithRootURL

func WithRootURL(rooturl *url.URL) Option

WithRootURL sets the root URL

func WithUnits

func WithUnits(units int) Option

WithUnits sets the units

type Rain

type Rain struct {
	OneH float64 `json:"1h"`
}

Rain holds the rain data

type Snow

type Snow struct {
	OneH float64 `json:"1h"`
}

Snow holds the snow data

type Weather

type Weather struct {
	Units          string          `json:"units"`
	Lat            float64         `json:"lat"`
	Lon            float64         `json:"lon"`
	Timezone       string          `json:"timezone"`
	TimezoneOffset int             `json:"timezone_offset"`
	Current        *WeatherCurrent `json:"current"`
	Minutely       []struct {
		Dt            int     `json:"dt"`
		Precipitation float64 `json:"precipitation"`
	} `json:"minutely"`
	Hourly *[]WeatherHourly `json:"hourly"`
	Daily  *[]WeatherDaily  `json:"daily"`
	Alerts *[]WeatherAlerts `json:"alerts"`
}

Weather returns the weather for the given location

func (*Weather) Text

func (weather *Weather) Text(brief bool) error

Text returns the weather as text

func (*Weather) ToJSON

func (w *Weather) ToJSON() ([]byte, error)

ToJSON returns the weather as a JSON byte array

func (*Weather) ToToml

func (w *Weather) ToToml() ([]byte, error)

ToToml returns the weather as a TOML byte array

func (*Weather) ToYAML

func (w *Weather) ToYAML() ([]byte, error)

ToYAML returns the weather as a YAML byte array

type WeatherAlerts

type WeatherAlerts struct {
	SenderName  string   `json:"sender_name"`
	Event       string   `json:"event"`
	Start       int64    `json:"start"`
	End         int64    `json:"end"`
	Description string   `json:"description"`
	Tags        []string `json:"tags"`
}

WeatherAlerts holds the weather alerts

type WeatherCurrent

type WeatherCurrent struct {
	Dt         int64           `json:"dt"`
	Sunrise    int64           `json:"sunrise"`
	Sunset     int64           `json:"sunset"`
	Temp       float64         `json:"temp"`
	FeelsLike  float64         `json:"feels_like"`
	Pressure   int             `json:"pressure"`
	Humidity   int             `json:"humidity"`
	DewPoint   float64         `json:"dew_point"`
	Clouds     int             `json:"clouds"`
	Uvi        float64         `json:"uvi"`
	Visibility int             `json:"visibility"`
	WindSpeed  float64         `json:"wind_speed"`
	WindGust   float64         `json:"wind_gust"`
	WindDeg    int             `json:"wind_deg"`
	Rain       Rain            `json:"rain"`
	Snow       Snow            `json:"snow"`
	Weather    []*WeatherStats `json:"weather"`
}

WeatherCurrent holds the current weather data

type WeatherDaily

type WeatherDaily struct {
	Dt        int64   `json:"dt"`
	Sunrise   int64   `json:"sunrise"`
	Sunset    int64   `json:"sunset"`
	Moonrise  int64   `json:"moonrise"`
	Moonset   int64   `json:"moonset"`
	MoonPhase float64 `json:"moon_phase"`
	Temp      struct {
		Morn  float64 `json:"morn"`
		Day   float64 `json:"day"`
		Eve   float64 `json:"eve"`
		Night float64 `json:"night"`
		Min   float64 `json:"min"`
		Max   float64 `json:"max"`
	} `json:"temp"`
	FeelsLike struct {
		Morn  float64 `json:"morn"`
		Day   float64 `json:"day"`
		Eve   float64 `json:"eve"`
		Night float64 `json:"night"`
	} `json:"feels_like"`
	Pressure  int             `json:"pressure"`
	Humidity  int             `json:"humidity"`
	DewPoint  float64         `json:"dew_point"`
	WindSpeed float64         `json:"wind_speed"`
	WindGust  float64         `json:"wind_gust"`
	WindDeg   int             `json:"wind_deg"`
	Clouds    int             `json:"clouds"`
	Uvi       float64         `json:"uvi"`
	Pop       float64         `json:"pop"`
	Rain      float64         `json:"rain"`
	Snow      float64         `json:"snow"`
	Weather   []*WeatherStats `json:"weather"`
}

WeatherDaily holds the daily weather data

type WeatherHourly

type WeatherHourly struct {
	Dt         int64           `json:"dt"`
	Temp       float64         `json:"temp"`
	FeelsLike  float64         `json:"feels_like"`
	Pressure   int             `json:"pressure"`
	Humidity   int             `json:"humidity"`
	DewPoint   float64         `json:"dew_point"`
	Uvi        float64         `json:"uvi"`
	Clouds     int             `json:"clouds"`
	Visibility int             `json:"visibility"`
	WindSpeed  float64         `json:"wind_speed"`
	WindGust   float64         `json:"wind_gust"`
	WindDeg    int             `json:"wind_deg"`
	Pop        float64         `json:"pop"`
	Rain       Rain            `json:"rain"`
	Snow       Snow            `json:"snow"`
	Weather    []*WeatherStats `json:"weather"`
}

WeatherHourly holds the hourly weather data

type WeatherStats

type WeatherStats struct {
	ID          int      `json:"id"`
	Main        string   `json:"main"`
	Description string   `json:"description"`
	Icon        string   `json:"icon"`
	IconURL     *url.URL `json:"icon_url"`
}

WeatherStats holds the weather stats

Jump to

Keyboard shortcuts

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