Skip to content

shawntoffel/go-weatherkit

Repository files navigation

go-weatherkit

Go Reference Go Report Card Build status

A WeatherKit API client in Go. WeatherKit is powered by the Apple Weather service.

Notice: The WeatherKit REST API is currently in beta and is subject to change. This client was created from documentation available here: https://developer.apple.com/documentation/weatherkitrestapi

go-weatherkit is an open source project not affiliated with Apple Inc.

Installing

This assumes you already have a working Go environment, if not please see this page first.

go get github.com/shawntoffel/go-weatherkit

Usage

Import the package into your project:

import "github.com/shawntoffel/go-weatherkit"

Create a new weatherkit client:

// See Authentication documentation below.
privateKeyBytes, _ := os.ReadFile("/path/to/AuthKey_ABCDE12345.p8")

client := weatherkit.NewCredentialedClient(weatherkit.Credentials{
	KeyID:      "key ID",
	TeamID:     "team ID",
	ServiceID:  "service ID",
	PrivateKey: privateKeyBytes,
})

Locating your identifiers:

  • Key ID (kid): An identifier associated with your private key. It can be found on the Certificates, Identifiers & Profiles page under Keys. Click on the appropriate key to view the ID.
  • Team ID (tid): Found on the account page under Membership details.
  • Service ID (sid): Found on the Certificates, Identifiers & Profiles page under Identifiers. Make sure "Services IDs" is selected from the dropdown.

Build a request:

request := weatherkit.WeatherRequest{
	Latitude:  38.960,
	Longitude: -104.506,
	Language:  "en",
	DataSets: weatherkit.DataSets{
		weatherkit.DataSetCurrentWeather,
	},
}

Get a response:

ctx := context.Background()

response, err := client.Weather(ctx, request)

Documentation

Attribution

See Apple's documentation for Apple Weather and third-party attribution requirements.

Examples

Troubleshooting

Please use the GitHub Discussions tab for questions regarding this client library. The Apple Developer forums are available for questions regarding the underlying API: https://developer.apple.com/forums/tags/weatherkit

About

A WeatherKit REST API client in Go

Topics

Resources

License

Stars

Watchers

Forks

Languages