I’ve just started a 40-day journey to learn Go (Golang).
This is a record of what I learn in each session—concepts, examples, and even small details.
My goal is to stay consistent, document my progress, and hopefully make this series helpful for anyone else starting with Go.
Let’s start with why Go is worth learning.
Why Go?
Earlier scripting relied on Bash and later Python.
Python made automation easier but required dependencies and external packages.
Go solves this by producing standalone binary files that are small, portable, and easy to share.
Example: Tools like Cobra or notification services are distributed as single binaries (~13 MB).
Go is widely used today for microservices, APIs, and CLI tools.
Compiled vs Interpreted Languages
Go is a compiled language.
Compilation catches errors before runtime.
Interpreted languages (Python, Ruby) execute line by line, so errors appear only when that line runs.
With Go, if there’s a problem, compilation stops immediately.
Writing the First Program
- Create a file: hello.go.
-
Structure:
-
package main→ entry point. -
import "fmt"→ for printing. -
func main()→ mandatory starting function. -
fmt.Println("Hello World")→ prints output. - Notes:
- Curly brackets must be on the same line as the function declaration. (example please refer below)
- Semicolons are optional (not required).
-
Quotes in Go
- In Go, text (like words or sentences) must be inside double quotes " ". If you only want a single character, like A or b, you use single quotes ' '. Example:
-
name := "Rajesh" // string
initial := 'R' // single character
-
Printlnadds a newline;Printdoes not.
Running and Building
go run hello.go→ runs the file directly.go build hello.go→ produces an executable binary.Initial builds may take longer due to compilation and caching, but subsequent runs are faster.
These binaries are easy to share because they don’t need external dependencies installed. However, a binary built on one system won’t automatically run on all others. You must compile separately for each Operating System (OS) and Architecture.
Curly Bracket Placement in Go
One important detail in Go is how you place curly brackets { }. Unlike some other languages (like C or JavaScript), Go enforces a strict style:
The opening bracket must be on the same line as the function declaration or control statement.
If you try to put the { on the next line, the compiler will throw an error.
For example:
// âś… Correct
func main() {
fmt.Println("Hello World")
}
// ❌ Incorrect
func main()
{
fmt.Println("Hello World")
}
This rule is part of Go’s design philosophy — it keeps code consistent and avoids style debates. The Go compiler itself enforces this formatting, so following it is not optional.
Variables and Printing
- Two ways to declare variables:
Shorthand: name := "Rajesh" (type inferred).
Explicit: var name string = "Rajesh".
Example:
name := "Rajesh"
age := 28
fmt.Printf("%s is %d years old", name, age)
%sis a placeholder for strings,%dfor integers.Redeclaration of the same variable causes an error.
Real-World Use Cases
Most CLI tools are written in Go.
Many APIs and backend servers use Go for speed and efficiency.
Go binaries are portable and don’t require installation, making them ideal for deployment.
Self-hosted tools and Dockerized applications often rely on Go.
Today’s Takeaway:
I learned why Go is important, how it differs from Python and Bash, and wrote my first “Hello World” program. I also understood Go’s syntax rules (curly brackets, quotes, semicolons) and how to run/build executables.
Thanks for reading my notes from today’s session. This is part of my ongoing 40‑day Go learning series, where I’ll post after every class. Stay tuned for the next entry as I continue building my understanding step by step.
Top comments (0)