weathergov

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package weathergov provides a client for the Weather.gov API described at https://www.weather.gov/documentation/services-web-api#

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// GetForecast gets the forecast for the given location.
	GetForecast(ctx context.Context, lat, long float64) (*Forecast, error)
	// Name provides a client name used to report health check issues.
	Name() string
	// Ping checks the client is healthy.
	Ping(ctx context.Context) error
}

Client is a client for the Weather.gov API.

func New

func New(c Doer) Client

New returns a new client for the Weather.gov API.

type Doer added in v0.12.0

type Doer interface {
	Do(req *http.Request) (*http.Response, error)
}

Doer is an interface for making HTTP requests.

type Forecast

type Forecast struct {
	// Location is the location of the forecast.
	Location *Location
	// Periods is the forecast for the location.
	Periods []*Period
}

Forecast represents the forecast for a given location.

type GetForecastFunc

type GetForecastFunc func(ctx context.Context, lat, long float64) (*Forecast, error)

GetForecastFunc mocks the GetForecast method.

type Location

type Location struct {
	// Lat is the latitude of the location.
	Lat float64
	// Long is the longitude of the location.
	Long float64
	// City is the city of the location.
	City string
	// State is the state of the location.
	State string
}

Location represents the geographical location of a forecast.

type Mock

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

Mock implementation of the weather API client.

func NewMock

func NewMock(t *testing.T) *Mock

NewMock returns a new mock client.

func (*Mock) AddGetForecastFunc

func (m *Mock) AddGetForecastFunc(f GetForecastFunc)

AddGetForecastFinc adds f to the mocked call sequence.

func (*Mock) GetForecast

func (m *Mock) GetForecast(ctx context.Context, lat, long float64) (*Forecast, error)

GetForecast implements the Client interface.

func (*Mock) HasMore

func (m *Mock) HasMore() bool

HasMore returns true if there are more calls to be made.

func (*Mock) Name

func (m *Mock) Name() string

Mock health-check implementation.

func (*Mock) Ping

func (m *Mock) Ping(context.Context) error

func (*Mock) SetGetForecastFunc

func (m *Mock) SetGetForecastFunc(f GetForecastFunc)

SetGetForecastFunc sets f for all calls to the mocked method.

type Period

type Period struct {
	// Name is the name of the forecast period.
	Name string
	// StartTime is the start time of the forecast period in RFC3339 format.
	StartTime string
	// EndTime is the end time of the forecast period in RFC3339 format.
	EndTime string
	// Temperature is the temperature of the forecast period.
	Temperature int
	// TemperatureUnit is the temperature unit of the forecast period.
	TemperatureUnit string
	// Summary is the summary of the forecast period.
	Summary string
}

Period represents a forecast period.

Jump to

Keyboard shortcuts

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