-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathendpoints.go
39 lines (29 loc) · 975 Bytes
/
endpoints.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package weatherkit
import (
"fmt"
"net/url"
)
// WeatherKit API base URL
var BaseUrl = "https://weatherkit.apple.com"
func weatherEndpoint(lang string, latitude float64, longitude float64, values url.Values) string {
return BaseUrl + "/api/v1/weather/" + fmt.Sprintf("%s/%g/%g", lang, latitude, longitude) + encodeUrlParameters(values)
}
func availabilityEndpoint(latitude, longitude float64, values url.Values) string {
return BaseUrl + "/api/v1/availability/" + fmt.Sprintf("%g/%g", latitude, longitude) + encodeUrlParameters(values)
}
func weatherAlertEndpoint(lang string, id string) string {
return BaseUrl + "/api/v1/weatherAlert/" + fmt.Sprintf("%s/%s", lang, id)
}
func attribution(lang string) string {
return BaseUrl + "/attribution/" + lang
}
func encodeUrlParameters(values url.Values) string {
queryString := values.Encode()
if queryString == "" {
return queryString
}
return "?" + queryString
}
type urlBuilder interface {
url() string
}