-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from kashifkhan0771/feature/history-api
Added history API
- Loading branch information
Showing
6 changed files
with
86 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package go_weather | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
// Define the minimum allowed date (2010-01-01) | ||
var minAllowedDate = time.Date(2010, 1, 1, 0, 0, 0, 0, time.UTC) | ||
|
||
// validateQuery ensure the required query in the option is not empty | ||
func validateQuery(q string) bool { | ||
return q != "" | ||
} | ||
|
||
// Ensure the date is on or after January 1st, 2010 | ||
func validateDate(date time.Time) bool { | ||
if date.IsZero() { | ||
return false | ||
} | ||
|
||
// Check if the input date is on or after 2010-01-01 | ||
return !date.Before(minAllowedDate) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,28 @@ | ||
package go_weather | ||
|
||
import ( | ||
"errors" | ||
"net/http" | ||
"time" | ||
|
||
"github.com/kashifkhan0771/go-weather/config" | ||
) | ||
|
||
// WeatherAPIConfig has the configurations required to call the APIs | ||
type WeatherAPIConfig struct { | ||
// XApiKey can be obtained from: https://www.weatherapi.com/ after you log in | ||
XApiKey string `json:"key"` | ||
XApiKey string `json:"key"` | ||
HttpClient *http.Client `json:"-"` | ||
} | ||
|
||
// NewWeatherAPIConfig creates a WeatherAPIConfig with apiKey passed. | ||
func NewWeatherAPIConfig(apiKey string) (*WeatherAPIConfig, error) { | ||
if apiKey == "" { | ||
return nil, errors.New("API key cannot be empty") | ||
} | ||
|
||
return &WeatherAPIConfig{ | ||
XApiKey: apiKey, | ||
HttpClient: &http.Client{Timeout: time.Second * config.APIsTimeout}, | ||
}, nil | ||
} |