Documentation
¶
Overview ¶
Package dstest implements a mock Dark Sky server for testing.
Index ¶
Examples ¶
Constants ¶
View Source
const DefaultKey = "key"
DefaultKey is the default key.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*Server)
An Option sets an option on a Server.
func WithDefaultForecasts ¶
func WithDefaultForecasts() Option
WithDefaultForecasts returns an option that adds all default forecasts to a Server.
func WithForecast ¶
WithForecast returns an option that adds a forecastStr as a response to request on a Server.
type Request ¶
type Request struct { Latitude float64 Longitude float64 Time darksky.Time Exclude string // A string, not a []darksky.Block so we can use Request as a map key. Extend darksky.Extend Lang darksky.Lang Units darksky.Units }
A Request contains parameters for a request.
type Server ¶
A Server is a mock server.
func NewServer ¶
NewServer returns a new Server.
Example ¶
package main import ( "context" "fmt" "time" darksky "github.com/twpayne/go-darksky" "github.com/twpayne/go-darksky/dstest" ) func main() { ctx := context.Background() s := dstest.NewServer( dstest.WithDefaultForecasts(), ) c, err := s.NewClient() if err != nil { fmt.Println(err) return } f, err := c.Forecast(ctx, 34.0219, -118.4814, &darksky.Time{Time: time.Date(2019, 5, 1, 0, 0, 0, 0, time.UTC)}, nil) if err != nil { fmt.Println(err) return } fmt.Println(f.Currently.Icon) }
Output: partly-cloudy-day
Click to show internal directories.
Click to hide internal directories.