-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathrequest.go
More file actions
278 lines (233 loc) · 7.81 KB
/
request.go
File metadata and controls
278 lines (233 loc) · 7.81 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
package omgo
import "fmt"
// ForecastRequest represents a request to the Forecast API.
type ForecastRequest struct {
location Location
// Metrics to request
hourlyMetrics []HourlyMetric
dailyMetrics []DailyMetric
currentMetrics []CurrentMetric
minutely15Metrics []Minutely15Metric
// Units
temperatureUnit TemperatureUnit
windSpeedUnit WindSpeedUnit
precipitationUnit PrecipitationUnit
// Time options
timezone string
forecastDays int
pastDays int
forecastHours int
pastHours int
// Date range options
startDate string
endDate string
startHour string
endHour string
// Other options
cellSelection CellSelection
models []string
// Solar radiation options (for global_tilted_irradiance)
tilt *float64
azimuth *float64
}
// NewForecastRequest creates a new ForecastRequest for the given coordinates.
func NewForecastRequest(lat, lon float64) (*ForecastRequest, error) {
loc, err := NewLocation(lat, lon)
if err != nil {
return nil, err
}
return &ForecastRequest{
location: loc,
}, nil
}
// WithLocation sets the location from an existing Location struct.
func (r *ForecastRequest) WithLocation(loc Location) *ForecastRequest {
r.location = loc
return r
}
// WithHourly adds hourly metrics to the request.
func (r *ForecastRequest) WithHourly(metrics ...HourlyMetric) *ForecastRequest {
r.hourlyMetrics = append(r.hourlyMetrics, metrics...)
return r
}
// WithDaily adds daily metrics to the request.
func (r *ForecastRequest) WithDaily(metrics ...DailyMetric) *ForecastRequest {
r.dailyMetrics = append(r.dailyMetrics, metrics...)
return r
}
// WithCurrent adds current weather metrics to the request.
func (r *ForecastRequest) WithCurrent(metrics ...CurrentMetric) *ForecastRequest {
r.currentMetrics = append(r.currentMetrics, metrics...)
return r
}
// WithMinutely15 adds 15-minutely metrics to the request.
func (r *ForecastRequest) WithMinutely15(metrics ...Minutely15Metric) *ForecastRequest {
r.minutely15Metrics = append(r.minutely15Metrics, metrics...)
return r
}
// WithTemperatureUnit sets the temperature unit for the response.
func (r *ForecastRequest) WithTemperatureUnit(unit TemperatureUnit) *ForecastRequest {
r.temperatureUnit = unit
return r
}
// WithWindSpeedUnit sets the wind speed unit for the response.
func (r *ForecastRequest) WithWindSpeedUnit(unit WindSpeedUnit) *ForecastRequest {
r.windSpeedUnit = unit
return r
}
// WithPrecipitationUnit sets the precipitation unit for the response.
func (r *ForecastRequest) WithPrecipitationUnit(unit PrecipitationUnit) *ForecastRequest {
r.precipitationUnit = unit
return r
}
// WithTimezone sets the timezone for the response.
// Use "auto" to automatically detect the timezone based on coordinates.
// Any timezone name from the time zone database is supported.
func (r *ForecastRequest) WithTimezone(tz string) *ForecastRequest {
r.timezone = tz
return r
}
// WithForecastDays sets the number of forecast days (0-16).
func (r *ForecastRequest) WithForecastDays(days int) *ForecastRequest {
r.forecastDays = days
return r
}
// WithPastDays sets the number of past days to include (0-92).
func (r *ForecastRequest) WithPastDays(days int) *ForecastRequest {
r.pastDays = days
return r
}
// WithForecastHours sets the number of forecast hours.
func (r *ForecastRequest) WithForecastHours(hours int) *ForecastRequest {
r.forecastHours = hours
return r
}
// WithPastHours sets the number of past hours to include.
func (r *ForecastRequest) WithPastHours(hours int) *ForecastRequest {
r.pastHours = hours
return r
}
// WithDateRange sets a specific date range for the forecast.
// Dates should be in ISO8601 format (yyyy-mm-dd).
func (r *ForecastRequest) WithDateRange(startDate, endDate string) *ForecastRequest {
r.startDate = startDate
r.endDate = endDate
return r
}
// WithHourRange sets a specific hour range for the forecast.
// Times should be in ISO8601 format (yyyy-mm-ddThh:mm).
func (r *ForecastRequest) WithHourRange(startHour, endHour string) *ForecastRequest {
r.startHour = startHour
r.endHour = endHour
return r
}
// WithCellSelection sets the grid-cell selection preference.
func (r *ForecastRequest) WithCellSelection(selection CellSelection) *ForecastRequest {
r.cellSelection = selection
return r
}
// WithModels sets specific weather models to use.
func (r *ForecastRequest) WithModels(models ...string) *ForecastRequest {
r.models = append(r.models, models...)
return r
}
// WithTilt sets the tilt angle for global_tilted_irradiance calculations (0-90 degrees).
func (r *ForecastRequest) WithTilt(degrees float64) *ForecastRequest {
r.tilt = °rees
return r
}
// WithAzimuth sets the azimuth angle for global_tilted_irradiance calculations.
// 0° = south, -90° = east, 90° = west, ±180° = north.
func (r *ForecastRequest) WithAzimuth(degrees float64) *ForecastRequest {
r.azimuth = °rees
return r
}
// HistoricalRequest represents a request to the Historical API.
type HistoricalRequest struct {
location Location
// Required date range
startDate string
endDate string
// Metrics to request
hourlyMetrics []HourlyMetric
dailyMetrics []DailyMetric
// Units
temperatureUnit TemperatureUnit
windSpeedUnit WindSpeedUnit
precipitationUnit PrecipitationUnit
// Other options
timezone string
cellSelection CellSelection
// Solar radiation options
tilt *float64
azimuth *float64
}
// NewHistoricalRequest creates a new HistoricalRequest for the given coordinates and date range.
// startDate and endDate should be in ISO8601 format (yyyy-mm-dd).
func NewHistoricalRequest(lat, lon float64, startDate, endDate string) (*HistoricalRequest, error) {
loc, err := NewLocation(lat, lon)
if err != nil {
return nil, err
}
if startDate == "" {
return nil, fmt.Errorf("startDate is required for historical requests")
}
if endDate == "" {
return nil, fmt.Errorf("endDate is required for historical requests")
}
return &HistoricalRequest{
location: loc,
startDate: startDate,
endDate: endDate,
}, nil
}
// WithLocation sets the location from an existing Location struct.
func (r *HistoricalRequest) WithLocation(loc Location) *HistoricalRequest {
r.location = loc
return r
}
// WithHourly adds hourly metrics to the request.
func (r *HistoricalRequest) WithHourly(metrics ...HourlyMetric) *HistoricalRequest {
r.hourlyMetrics = append(r.hourlyMetrics, metrics...)
return r
}
// WithDaily adds daily metrics to the request.
func (r *HistoricalRequest) WithDaily(metrics ...DailyMetric) *HistoricalRequest {
r.dailyMetrics = append(r.dailyMetrics, metrics...)
return r
}
// WithTemperatureUnit sets the temperature unit for the response.
func (r *HistoricalRequest) WithTemperatureUnit(unit TemperatureUnit) *HistoricalRequest {
r.temperatureUnit = unit
return r
}
// WithWindSpeedUnit sets the wind speed unit for the response.
func (r *HistoricalRequest) WithWindSpeedUnit(unit WindSpeedUnit) *HistoricalRequest {
r.windSpeedUnit = unit
return r
}
// WithPrecipitationUnit sets the precipitation unit for the response.
func (r *HistoricalRequest) WithPrecipitationUnit(unit PrecipitationUnit) *HistoricalRequest {
r.precipitationUnit = unit
return r
}
// WithTimezone sets the timezone for the response.
func (r *HistoricalRequest) WithTimezone(tz string) *HistoricalRequest {
r.timezone = tz
return r
}
// WithCellSelection sets the grid-cell selection preference.
func (r *HistoricalRequest) WithCellSelection(selection CellSelection) *HistoricalRequest {
r.cellSelection = selection
return r
}
// WithTilt sets the tilt angle for global_tilted_irradiance calculations (0-90 degrees).
func (r *HistoricalRequest) WithTilt(degrees float64) *HistoricalRequest {
r.tilt = °rees
return r
}
// WithAzimuth sets the azimuth angle for global_tilted_irradiance calculations.
func (r *HistoricalRequest) WithAzimuth(degrees float64) *HistoricalRequest {
r.azimuth = °rees
return r
}