Introduction to Go (Golang)

Go, also known as Golang, is a modern programming language developed at Google to solve real-world problems in large-scale systems.

It was designed to be:

  • Simple
  • Fast
  • Efficient
  • Scalable

Go is widely used for:

  • Backend development (APIs, servers)
  • Cloud infrastructure
  • DevOps tools
  • Networking systems

Popular tools built in Go:

  • Docker
  • Kubernetes
  • Terraform

Why Go is So Popular

🔹 Key Benefits

  1. Fast Compilation Strongly Typed & Statically Typed

    var age int = 16

    Wrong:

    age = "hello" // ERROR

    Checked at compile time → fewer bugs

    Memory Management (Garbage Collector)
    Go uses:
    Automatic Garbage Collection
    Unlike C:
    No manual memory free
    Safer

    Conditionals in Go

    if age > 18 {
    fmt.Println("Adult")
    } else {
    fmt.Println("Minor")
    }

    Special Feature:

    if x := 10; x > 5 {
    fmt.Println(x)
    }



    Arrays vs Slices
    Array (Fixed)

    var arr [3]int = [3]int{1,2,3}

    Slice (Dynamic)

    nums := []int{1,2,3}


    Slice Operations

    nums = append(nums, 4)
    fmt.Println(len(nums))
    fmt.Println(cap(nums))


    Important Rule

    nums = append(nums, 5) // ALWAYS reassign


    Maps in Go

    m := make(map[string]int)
    m["age"] = 16

    Safe Access:

    value, ok := m["age"]


    Common Crash

    var m map[string]int
    m["x"] = 1 // PANIC

    Fix:

    m = make(map[string]int)


    Pointers in Go

    x := 10
    p := &x
    fmt.Println(*p)



    Crash Example

    var p *int
    fmt.Println(*p) // PANIC

    Fix:

    if p != nil {
    fmt.Println(*p)
    }



    Interfaces in Go

    type Shape interface {
    Area() float64
    }

    ✔ No inheritance
    ✔ Simple design
    ✔ Implicit implementation
  2. Variadic Functions

    func sum(nums ...int) int {
    total := 0
    for _, v := range nums {
    total += v
    }
    return total
    }


    Concurrency in Go (Powerful Feature)
    Goroutines

    go myFunction()


    Channels

    ch := make(chan int)
    ch <- 5
    value := <-ch



    Select Statement

    select {
    case msg := <-ch1:
    fmt.Println(msg)
    case msg := <-ch2:
    fmt.Println(msg)
    }


    Channel Crash Rules
    Operation
    Result
    Send to nil
    Block forever
    Send to closed
    Panic
    Receive closed
    Zero value

    WaitGroup Example

    var wg sync.WaitGroup

    wg.Add(1)
    go func() {
    defer wg.Done()
    fmt.Println("Done")
    }()
    wg.Wait()



    Go Modules

    go mod init myproject
    go mod tidy



    Backend Development Example

    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "Hello API")
    })
    http.ListenAndServe(":8080", nil)


    Common Errors & Fixes

    Panic: nil pointer
    ✔ Fix: check before use

    Slice bug (append)
    ✔ Fix:

    slice = append(slice, val)


    Deadlock

    ch := make(chan int)
    ch <- 1 // no receiver → deadlock

    ✔ Fix:

    go func(){ ch <- 1 }()
    <-ch



    Import errors
    ✔ Fix:

    go mod tidy


    Advantages of Go
    ✔ Fast compilation
    ✔ Simple syntax
    ✔ Built-in concurrency
    ✔ No VM required
    ✔ Cross-platform binaries
    ✔ Strong typing

    x Disadvantages of Go
    xNo generics (older versions)
    x Limited OOP features
    x Verbose error handling
    x Garbage collector overhead

    Fun Facts About Go
    Go was created in 2009
    Designed by engineers at Google
    Compilation is so fast it feels like scripting
    Used in massive systems like Kubernetes
    Has built-in concurrency (rare in languages)
    • Much faster than C, C++, Rust
    • Saves developer time
  3. Good Performance
    • Faster than Python/JavaScript
    • Comparable to Java/C#
  4. Low Memory Usage
    • No heavy virtual machine (like Java)
    • Lightweight runtime
  5. Simple Syntax
    • Easier than C++
    • Cleaner than Java

Is Go a Compiler or Interpreter?

Go is a compiled language

What is Compilation?

Compilation = converting human-readable code into machine code

Example:

fmt.Println("Hello World")

Becomes:

Binary executable → runs directly on CPU

Go vs Interpreted Languages

FeatureGoPython
TypeCompiledInterpreted
SpeedFastSlower
Needs runtime?❌ No✅ Yes

How Compilation Works in Go

Build Command

go build main.go

Output:

main.exe (Windows)
main (Linux/Mac)

Run Without Building

go run main.go

Installing Go on All Platforms


Windows (64-bit & 32-bit)

  1. Go to official website
  2. Download:
  3. Install and verify:
go version

Common Windows Issues

“go not recognized”

Fix:

  • Add Go to PATH:
C:\Program Files\Go\bin

macOS

Using Homebrew:

brew install go

Or download pkg installer.


Linux (Ubuntu/Debian)

sudo apt update
sudo apt install golang

Or manual:

wget https://go.dev/dl/go1.xx.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf file.tar.gz

Add to PATH:

export PATH=$PATH:/usr/local/go/bin

Termux (Android)

pkg update
pkg install golang

Check:

go version

Basic Go Program

package mainimport "fmt"func main() {
fmt.Println("Hello, Mustafa!")
}

Run:

go run main.go

Strongly Typed & Statically Typed

var age int = 16

x Wrong:

age = "hello" // ERROR

✔ Checked at compile time → fewer bugs


Memory Management (Garbage Collector)

Go uses:
Automatic Garbage Collection

Unlike C:

  • No manual memory free
  • Safer

Conditionals in Go

if age > 18 {
fmt.Println("Adult")
} else {
fmt.Println("Minor")
}

Special Feature:

if x := 10; x > 5 {
fmt.Println(x)
}

Arrays vs Slices

Array (Fixed)

var arr [3]int = [3]int{1,2,3}

Slice (Dynamic)

nums := []int{1,2,3}

Slice Operations

nums = append(nums, 4)
fmt.Println(len(nums))
fmt.Println(cap(nums))

Important Rule

nums = append(nums, 5) // ALWAYS reassign

Maps in Go

m := make(map[string]int)
m["age"] = 16

Safe Access:

value, ok := m["age"]

x Common Crash

var m map[string]int
m["x"] = 1 // PANIC

Fix:

m = make(map[string]int)

Pointers in Go

x := 10
p := &x
fmt.Println(*p)

Crash Example

var p *int
fmt.Println(*p) // PANIC

Fix:

if p != nil {
fmt.Println(*p)
}

Interfaces in Go

type Shape interface {
Area() float64
}

✔ No inheritance
✔ Simple design
✔ Implicit implementation


Variadic Functions

func sum(nums ...int) int {
total := 0
for _, v := range nums {
total += v
}
return total
}

Concurrency in Go (Powerful Feature)

Goroutines

go myFunction()

Channels

ch := make(chan int)
ch <- 5
value := <-ch

Select Statement

select {
case msg := <-ch1:
fmt.Println(msg)
case msg := <-ch2:
fmt.Println(msg)
}

Channel Crash Rules

OperationResult
Send to nilBlock forever
Send to closedPanic
Receive closedZero value

Wait Group Example

var wg sync.WaitGroupwg.Add(1)
go func() {
defer wg.Done()
fmt.Println("Done")
}()
wg.Wait()

Go Modules

go mod init myproject
go mod tidy

Backend Development Example

http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello API")
})
http.ListenAndServe(":8080", nil)

Common Errors & Fixes


x Panic: nil pointer

✔ Fix: check before use


x Slice bug (append)

✔ Fix:

slice = append(slice, val)

x Deadlock

ch := make(chan int)
ch <- 1 // no receiver → deadlock

✔ Fix:

go func(){ ch <- 1 }()
<-ch

x Import errors

✔ Fix:

go mod tidy

Advantages of Go

✔ Fast compilation
✔ Simple syntax
✔ Built-in concurrency
✔ No VM required
✔ Cross-platform binaries
✔ Strong typing


x Disadvantages of Go

x No generics (older versions)
x Limited OOP features
x Verbose error handling
x Garbage collector overhead


Fun Facts About Go

  • Go was created in 2009
  • Designed by engineers at Google
  • Compilation is so fast it feels like scripting
  • Used in massive systems like Kubernetes
  • Has built-in concurrency (rare in languages)
  • )

Real-World Use Cases

  • Web APIs
  • Cloud services
  • CLI tools
  • Microservices
  • Networking tools

Conclusion

Go is one of the best modern programming languages if you want:

  • Speed ⚡
  • Simplicity 🧠
  • Scalability 📈

It is especially powerful for:
Backend + DevOps + Cloud systems

Final Tip

If you’re starting:

  1. Learn basics (syntax, slices, maps)
  2. Practice small programs
  3. Build APIs
  4. Explore concurrency
Categories: GoLang

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *