58 lines
2.2 KiB
Markdown
58 lines
2.2 KiB
Markdown
# current-weather
|
|
|
|
From recruiter:
|
|
|
|
> Coding Assessment:
|
|
>
|
|
> Here is code exam neeed for new Golang Roles - Weather Service Assignment
|
|
>
|
|
> Write an HTTP server that serves the current weather. Your server should expose an endpoint that:
|
|
>
|
|
> 1. Accepts latitude and longitude coordinates
|
|
> 2. Returns the short forecast for that area for Today (“Partly Cloudy” etc)
|
|
> 3. Returns a characterization of whether the temperature is “hot”, “cold”, or “moderate” (use your discretion on mapping temperatures to each type)
|
|
> 4. Use the National Weather Service API Web Service as a data source.
|
|
>
|
|
> The purpose of this exercise is to provide a sample of your work that we can discuss together in the Technical Interview.
|
|
>
|
|
> * We respect your time. Spend as long as you need, but we intend it to take around an hour.
|
|
> * We do not expect a production-ready service, but you might want to comment on your shortcuts.
|
|
> * The submitted project should build and have brief instructions so we can verify that it works.
|
|
> * You may write in whatever language or stack you're most comfortable in
|
|
|
|
This HTTP service gets a short forecast (results in JSON) for a given latitude and longitude.
|
|
|
|
### Build requirements
|
|
A local installation of Go is needed. Instructions to install Go can be found here: https://go.dev/learn/. I've used Ubuntu, but any OS should work.
|
|
|
|
### Building and Running
|
|
In the top-level-directory, run the following command:
|
|
|
|
`go build main.go`
|
|
|
|
This will build a binary in that folder, which can be run without arguments.
|
|
|
|
`./main`
|
|
|
|
To call the endpoint, use an HTTP client to send a GET request to `localhost:8080/forecast`. The payload should look like this:
|
|
```json
|
|
{
|
|
"latitude": 48.29944,
|
|
"longitude": -116.56
|
|
}
|
|
```
|
|
|
|
The result should look like this:
|
|
```json
|
|
{
|
|
"shortForecast": "Mostly Sunny",
|
|
"temperature": "hot"
|
|
}
|
|
```
|
|
|
|
### Shortcuts
|
|
* This should be containerized in something like Docker
|
|
* The code is all in main.go, but if this project was to grow, it should be broken down.
|
|
* There are no tests, but `httptest` should be used to test this. With rules, the temperature could be tested as well.
|
|
* Logging is sparse, but should be enough to test for this assessment.
|