This project is a command-line interface (CLI) tool written in Go that fetches and displays weather data from a public API.
- Fetch current weather data.
- Fetch weather forecast for the next 7 days.
- Display weather information in a user-friendly table format.
to run the tool, use the following command:
go run main.go daily
or
./somwther dailyreturns the daily weather forecast for the next 7 days.
go run main.go now
or
./somwther nowreturns the current weather data.
- Create two packages/directories:
cmdfor CLI commands andapifor API interactions and formatting tables. - Use the
cobrapackage for CLI command handling. - Use the
net/httppackage to make HTTP requests to the weather API. - Use the
encoding/jsonpackage to parse JSON responses. - Format and display the weather data in a readable table format using the
text/tabwriter
Api Link: https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.41&daily=weather_code&timezone=Africa%2FCairo
Api Doc: https://open-meteo.com/en/docs?timezone=Africa%2FCairo&daily=weather_code
Cli flags Cobra: https://github.com/spf13/cobra