A very specific Golang interface to the Dark Sky API for my Chrome Extension
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
3.4 KiB

  1. package main
  2. // Timestamp is an int64 timestamp
  3. type Timestamp int64
  4. // ForecastRequest contains all available options for requesting a forecast
  5. type ForecastRequest struct {
  6. Latitude float64
  7. Longitude float64
  8. Time Timestamp
  9. Options ForecastRequestOptions
  10. }
  11. // ForecastRequestOptions are optional and passed as query parameters
  12. type ForecastRequestOptions struct {
  13. Exclude string `url:"exclude,omitempty"`
  14. Extend string `url:"extend,omitempty"`
  15. Lang string `url:"lang,omitempty"`
  16. Units string `url:"units,omitempty"`
  17. }
  18. // ForecastResponse is the response containing all requested properties
  19. type ForecastResponse struct {
  20. Latitude float64 `json:"latitude,omitempty"`
  21. Longitude float64 `json:"longitude,omitempty"`
  22. Timezone string `json:"timezone,omitempty"`
  23. Currently *DataPoint `json:"currently,omitempty"`
  24. Minutely *DataBlock `json:"minutely,omitempty"`
  25. Hourly *DataBlock `json:"hourly,omitempty"`
  26. Daily *DataBlock `json:"daily,omitempty"`
  27. Alerts []*Alert `json:"alerts,omitempty"`
  28. Flags *Flags `json:"flags,omitempty"`
  29. }
  30. // DataPoint contains various properties, each representing the average (unless otherwise specified) of a particular weather phenomenon occurring during a period of time.
  31. type DataPoint struct {
  32. ApparentTemperature float64 `json:"apparentTemperature,omitempty"`
  33. ApparentTemperatureHigh float64 `json:"apparentTemperatureHigh,omitempty"`
  34. ApparentTemperatureLow float64 `json:"apparentTemperatureLow,omitempty"`
  35. Humidity float64 `json:"humidity,omitempty"`
  36. Icon string `json:"icon"`
  37. MoonPhase float64 `json:"moonPhase,omitempty"`
  38. Summary string `json:"summary,omitempty"`
  39. SunriseTime Timestamp `json:"sunriseTime,omitempty"`
  40. SunsetTime Timestamp `json:"sunsetTime,omitempty"`
  41. Temperature float64 `json:"temperature,omitempty"`
  42. TemperatureHigh float64 `json:"temperatureHigh"`
  43. TemperatureLow float64 `json:"temperatureLow"`
  44. TemperatureMax float64 `json:"temperatureMax"`
  45. TemperatureMin float64 `json:"temperatureMin"`
  46. Time Timestamp `json:"time,omitempty"`
  47. Visibility float64 `json:"visibility,omitempty"`
  48. WindBearing float64 `json:"windBearing"`
  49. WindGust float64 `json:"windGust"`
  50. WindSpeed float64 `json:"windSpeed"`
  51. }
  52. // DataBlock represents the various weather phenomena occurring over a period of time
  53. type DataBlock struct {
  54. Summary string `json:"summary,omitempty"`
  55. Icon string `json:"icon,omitempty"`
  56. Data []DataPoint `json:"data,omitempty"`
  57. }
  58. // Alert contains objects representing the severe weather warnings issued for the requested location by a governmental authority
  59. type Alert struct {
  60. Title string `json:"title,omitempty"`
  61. Severity string `json:"severity,omitempty"`
  62. Description string `json:"description,omitempty"`
  63. Expires Timestamp `json:"expires,omitempty"`
  64. Regions []string `json:"regions,omitempty"`
  65. Time Timestamp `json:"time,omitempty"`
  66. URI string `json:"uri,omitempty"`
  67. }
  68. // Flags contains various metadata information related to the request
  69. type Flags struct {
  70. DarkSkyUnavailable string `json:"darksky-unavailable,omitempty"`
  71. Sources []string `json:"sources,omitempty"`
  72. Units string `json:"units,omitempty"`
  73. }