Building a Weather Forecast CLI Tool in Go: A Terminal Weather Wizard

Gaurang Patel
3 min readSep 16, 2023

Your gateway to build Golang CLIs to create stuff to automate your redundant tasks.

For terminal aficionados, the command-line world is a captivating realm, granting the ability to perform tasks and access data without leaving the terminal. In this article, we’ll explore Go programming to craft a robust Weather Forecast CLI tool. Whether you seek a sunny day for sports or a coding project, join us in creating your own weather tool.

Let’s get started

Firstly to get access to the weather APIs you need to sign up and obtain an API key which can further help us build the CLI tool with ease.

  1. Prerequisites

Before we dive into the coding adventure, let’s ensure we have everything we need:

2. Gathering Weather Data

Our journey begins with fetching weather data. We will rely on a weather API to provide us with the necessary information. We use the net/http package in Go to make an HTTP GET request to the API and retrieve weather data.

package main

import (
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"time"
)

--

--

Gaurang Patel

Engineering @ Razorpay! Enabling smoother card payments for 25% Indian everyday.