This Weather App is a command-line application written in Go that allows you to fetch real-time weather data for any location based on a zip code. The app leverages the WeatherAPI.com to retrieve and display detailed weather information, including temperature, humidity, wind speed, and more.
- Real-Time Weather Data: Get up-to-date weather information for any location by entering its zip code.
- Detailed Weather Metrics: Displays temperature, weather condition, humidity, wind speed, cloud cover, visibility, and more.
- User Input: Dynamically input the zip code to retrieve specific weather data for any location.
- Environment Variable for API Key: Store your WeatherAPI.com API key securely in an
.envfile.
- Go: You must have Go installed on your system.
- WeatherAPI.com API Key: You need to sign up for a free API key from WeatherAPI.com.
-
Clone the Repository:
git clone https://github.com/rlanier-webdev/go-weatherapp.git cd weather-app -
Set Up Your API Key:
- Create a
.envfile in the root directory of the project. - Add your WeatherAPI.com API key to the
.envfile:APIKEY=your_api_key_here
- Ensure your
.envfile is included in your.gitignoreto keep it out of version control:echo ".env" >> .gitignore
- Create a
-
Install Go Modules:
- If you are using Go modules, ensure that your dependencies are up-to-date by running:
go mod tidy
- If you are using Go modules, ensure that your dependencies are up-to-date by running:
-
Build the Application:
go build -o go-weatherapp
-
Run the Application:
./go-weatherapp
-
When you run the application, it will prompt you to enter the zip code of the location for which you want to retrieve weather data:
Enter the zip code of the location:
-
After entering the zip code, the application will fetch and display the weather information, including:
- Location name
- Temperature (in Celsius and Fahrenheit)
- Weather condition (e.g., sunny, cloudy)
- Humidity
- Wind speed
- Feels-like temperature
- Visibility
- UV Index
- Wind gusts
Example output:
Location: Saint Louis, Missouri, USA
Temperature: 22.8°C (73.0°F)
Condition: Partly cloudy
Humidity: 46%
Cloud Cover: 75%
Feels Like: 24.2°C (75.5°F)
Wind Speed: 10.5 mph (16.9 kph)
Wind Chill: 22.4°C (72.3°F)
Heat Index: 23.9°C (75.0°F)
Dew Point: 7.3°C (45.2°F)
Visibility: 16.0 km (9.0 miles)
UV Index: 6.0
Gust: 15.0 mph (24.1 kph)To securely manage your WeatherAPI.com API key:
-
Create a
.envFile:- Place your API key in a
.envfile at the root of the project:APIKEY=your_api_key_here
- Place your API key in a
-
Load the API Key in Your Code:
- Use a package like
godotenvto load the environment variables in your Go application:import ( "os" "github.com/joho/godotenv" ) func init() { err := godotenv.Load() if err != nil { fmt.Println("Error loading .env file") } } func main() { apiKey := os.Getenv("APIKEY") // Use apiKey for your API requests }
- Use a package like
This project includes manual tests.