This project is a Go-based web service that provides temperature information for a given CEP (Postal Code) in Brazil. It uses the ViaCEP API to get location information and the WeatherAPI to fetch temperature data.
The service is designed to be deployed on Google Cloud Run.
Deploy URL: https://go-expert-cep-temperature-gcr-608943233137.us-central1.run.app/weather?cep=01001000
- Fetch location information using CEP (Brazilian Postal Code)
- Retrieve current temperature for the location
- Convert temperature to Celsius, Fahrenheit, and Kelvin
- Configurable using environment variables
- Designed with Clean Architecture principles
- Go 1.19 or later
- WeatherAPI API key (sign up at https://www.weatherapi.com)
-
Clone the repository:
git clone https://github.com/renanmav/GoExpert-CEPTemperature-GCR.git cd GoExpert-CEPTemperature-GCR -
Create a
.envfile from the provided.env.example:cp .env.example .env -
Edit the
.envfile and set your WeatherAPI key:WEATHER_API_KEY=your_api_key_here -
Install dependencies:
go mod tidy
To run the application locally:
go run cmd/main.go
The server will start on the port specified in your .env file (default is 8080).
To get weather information for a CEP, make a GET request to the /weather endpoint with the cep query parameter:
curl http://localhost:8080/weather?cep=01001000The response will be a JSON object containing the city name and temperature in Celsius, Fahrenheit, and Kelvin.
-
Build the Docker image:
docker build -t gcr.io/goexpert-436420/go-expert-cep-temperature-gcr . -
Push the image to Google Container Registry:
docker push gcr.io/goexpert-436420/go-expert-cep-temperature-gcr -
Deploy to Cloud Run:
gcloud run deploy --image gcr.io/goexpert-436420/go-expert-cep-temperature-gcr --platform managed
Make sure to set the WEATHER_API_KEY environment variable in your Cloud Run configuration.