Skip to content

Latest commit

 

History

History
52 lines (42 loc) · 1.85 KB

File metadata and controls

52 lines (42 loc) · 1.85 KB

Darksky API Client Implementation in go

GoDoc

A Simple implementation of a darksky API client.

Usage

First instantiate an api with your secret (you can sign up for free and get a secret here)

    api, err := darksky.NewAPI("my-secret")

If you need to pass a custom http client, you can use an option like this:

    api, err := darksky.NewAPI(
        "my-secret",
        darksky.HTTPClientOption(&MyCustomClient{}),
    )

It's also possible to pass a logger, for errors that are less relevant to the API user, but still relevant to report. The default logger will be logging to standard error.

    logger := log.New(os.Stderr, "Darksky API Client - ", log.LstdFlags)

    api, err := darksky.NewAPI(
        "my-secret",
        darksky.LoggerOption(logger),
    )

Then, you can query the API for forecast or time machine request like this:

    data, err := api.Forecast(42.3601, -71.0589)
    data, err := api.TimeMachine(42.3601, -71.0589, time.Now())

You can pass options to the query like this:

    data, err := api.Forecast(
        42.3601, -71.0589,
        darksky.LanguageOption(darksky.LangFR),
        ...
        )

Those options are :

  • Language through ex. LanguageOption(LangFR)
  • Extend option through ex. ExtendOption()
  • Exclude option through ex. ExcludeOption(ExMinutely, ExHourly)
  • Unit option through ex. UnitOption(UnitCA)

For more information on the API, please visit https://darksky.net/dev/docs. It is the source of most of the terminology used concerning the API parts in this project. Excerpt from the documentation has also been used as comments in the code to describe the parts that are directly in connection with the official documentation.