beginner Step 1 of 15

Introduction to Go

Go Programming

Introduction to Go

Go (often called Golang) is an open-source programming language created at Google by Robert Griesemer, Rob Pike, and Ken Thompson, and first released in 2009. Go was designed to address the challenges of building large-scale, concurrent, and reliable software systems. It combines the performance of compiled languages like C with the simplicity and readability of dynamically typed languages like Python. Go is statically typed, compiled to native machine code, and has built-in support for concurrency through goroutines and channels, making it ideal for cloud services, microservices, CLIs, and DevOps tools.

Installing Go

# Install on macOS
brew install go

# Install on Linux
wget https://go.dev/dl/go1.22.0.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.22.0.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin

# Verify installation
go version
# go version go1.22.0 darwin/arm64

Your First Go Program

// main.go
package main

import "fmt"

func main() {
    fmt.Println("Hello, World!")

    // Variables
    name := "Go Developer"  // Short variable declaration
    age := 30
    fmt.Printf("Name: %s, Age: %d\n", name, age)
}

// Run: go run main.go
// Build: go build -o myapp main.go

Go Project Structure

# Initialize a new module
go mod init github.com/username/myproject

# Project structure
myproject/
├── go.mod           # Module definition and dependencies
├── go.sum           # Dependency checksums
├── main.go          # Entry point
├── internal/        # Private packages
│   ├── handlers/
│   └── models/
├── pkg/             # Public packages
└── cmd/             # CLI entry points
    └── server/
        └── main.go

Why Go?

Go shines in scenarios requiring high performance, concurrency, and simplicity. It compiles to a single static binary with no external dependencies, making deployment trivial. Docker, Kubernetes, Terraform, and Hugo are all written in Go. The language has a deliberately small feature set — there are no classes, no generics (until Go 1.18), no exceptions, and no inheritance — which forces developers to write simple, straightforward code. The standard library is comprehensive, covering HTTP servers, JSON handling, cryptography, testing, and more without third-party packages.

Pro tip: Use go fmt to automatically format your code according to Go's standard style. Every Go developer uses the same formatting, eliminating style debates. Run go vet to catch common mistakes and go test ./... to run all tests in your project.

Key Takeaways

  • Go is a statically typed, compiled language designed for simplicity, performance, and concurrency.
  • Every Go program starts with package main and a main() function as the entry point.
  • Use := for short variable declaration and go mod init to create new projects.
  • Go compiles to a single static binary, making deployment extremely simple.
  • The standard library is comprehensive — you can build HTTP servers, parse JSON, and write tests without third-party packages.