Documentation
¶
Overview ¶
Package nws provides a client for the National Weather Service API.
Package nws provides a client for the National Weather Service API.
Index ¶
Constants ¶
const (
APIHost = "https://api.weather.gov"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type API ¶
type API struct {
// contains filtered or unexported fields
}
API represents a client for the National Weather Service API.
func (*API) GetForecasts ¶
func (a *API) GetForecasts(ctx context.Context, gp GridPoints, opts ...operations.Option) (Forecast, error)
GetForecasts returns the forecasts for the specified grid point. A cache keyed by grid point is used to avoid repeated lookups. The expiration of cache entries defaults to the ValidTimes entry in the forecast and can be overridden with the WithForecastExpiration option.
func (*API) LookupGridPoints ¶
func (a *API) LookupGridPoints(ctx context.Context, lat, long float64, opts ...operations.Option) (GridPoints, error)
LookupGridPoints returns the grid points for the specified lat/long. A cache keyed by exact lat/long is used to avoid repeated lookups. The expiration of cache entries defaults to 1 week and can be overridden with the WSithGridpointExpiration option.
type Forecast ¶
type Forecast struct { Generated time.Time Updated time.Time ValidFrom time.Time ValidFor time.Duration Periods []Period }
Forecast represents the forecasts for a specific grid point for a number of periods.
type GridPoints ¶
GridPoints represents the grid points for a specific lat/long.
type OpaqueCloudCoverage ¶
type OpaqueCloudCoverage int
OpaqueCloudCoverage represents the cloud coverage as a fraction of the sky as defined at https://www.weather.gov/bgm/forecast_terms.
const ( UnknownOpaqueCloudCoverage OpaqueCloudCoverage = iota ClearSunny // 0 to 1/8 Opaque Cloud Coverage MostlyClearSunny // 1/8 to 3/8 PartlyCloudySunny // 3/8 to 5/8 MostlyCloudy // 5/8 to 7/8 Cloudy // 7/8 to 8/8 )
func CloudOpacityFromShortForecast ¶
func CloudOpacityFromShortForecast(forecast string) OpaqueCloudCoverage
CloudOpacityFromShortForecast returns the cloud opacity based on the short forecast string.
func (OpaqueCloudCoverage) String ¶
func (o OpaqueCloudCoverage) String() string
type Option ¶
type Option func(o *options)
func WithForecastExpiration ¶
WithForecastExpiration sets the expiration time for forecast cache entries, if not set, the ValidTimes times entry in the forecast will be used. Set this to a lower value to update the forecast more requgularly (eg. to 24 hours).
func WithGridpointExpiration ¶
WithGridpointExpiration sets the expiration time for gridpoint cache entries. The mapping from lat/long to gridpoints is largely stable so this can be set to a long duration, the default is 1 week.