Apa Itu Go (Golang)?
Go atau Golang adalah bahasa pemrograman yang dikembangkan oleh Google pada tahun 2009. Dirancang oleh Robert Griesemer, Rob Pike, dan Ken Thompson, Go dibuat untuk mengatasi masalah di bahasa lain seperti C++ dan Java. Go terkenal dengan kesederhanaan, performa tinggi, dan dukungan concurrency yang excellent.
Mengapa Go Populer?
- Sederhana — Sintaks minimalis, mudah dipelajari
- Performa Tinggi — Compiled language, cepat seperti C
- Concurrency — Goroutines dan channels untuk parallel processing
- Static Typing — Type safety tanpa verbosity
- Fast Compilation — Compile sangat cepat
- Single Binary — Deploy satu file executable
- Cloud Native — Docker, Kubernetes ditulis dengan Go
Roadmap Belajar Go
Level 1: Beginner (Dasar Go)
- Sintaks Dasar — package main, func main(), fmt.Println
- Variabel — var, :=, const, zero values
- Tipe Data — int, float64, string, bool, rune, byte
- Operator — Aritmatika, perbandingan, logika
- Kontrol Alur — if/else, switch, for (satu-satunya loop)
- Array & Slice — Fixed array, dynamic slice, append, copy
- Map — Key-value pairs, make, delete
- Struct — Custom types, methods, embedded structs
- Pointer — & (address), * (dereference)
Level 2: Intermediate
- Interface — Implicit interface, type assertion, type switch
- Goroutines — Lightweight threads, go keyword
- Channels — Communication between goroutines, buffered/unbuffered
- Select — Multiplexing channels
- Error Handling — error type, errors.New, fmt.Errorf, custom errors
- Packages — Import, export, visibility (capitalized = public)
- File I/O — os, ioutil, bufio
- JSON — encoding/json, Marshal, Unmarshal
Level 3: Advanced
- HTTP Server — net/http, handlers, middleware
- REST API — Routing, JSON response, request parsing
- Database — database/sql, sqlx, GORM
- Testing — testing package, table-driven tests, benchmarks
- Generics — Type parameters (Go 1.18+)
- Context — context.Context untuk timeout dan cancellation
Level 4: Expert
- Microservices — gRPC, protobuf, service mesh
- Cloud Native — Docker, Kubernetes, Helm
- Performance — Profiling, pprof, optimization
- Concurrency Patterns — Worker pool, pipeline, fan-out/fan-in
- Design Patterns — Repository, Factory, Strategy
Contoh Kode Go
package main
import (
"fmt"
"strings"
)
// Struct
type Produk struct {
Nama string
Harga float64
}
func (p *Produk) Diskon(persen float64) {
p.Harga *= (1 - persen/100)
}
func (p Produk) Info() string {
return fmt.Sprintf("%s - Rp %.0f", p.Nama, p.Harga)
}
// Function
func Sapa(nama, waktu string) string {
if waktu == "" {
waktu = "pagi"
}
return fmt.Sprintf("Selamat %s, %s!", waktu, nama)
}
func main() {
// Variabel
nama := "Muhamad Widiono"
umur := 30
fmt.Printf("Nama: %s, Umur: %d\n", nama, umur)
// Slice
hobi := []string{"Coding", "Blogging", "Gaming"}
for i, h := range hobi {
fmt.Printf("%d. %s\n", i+1, h)
}
// Map
siswa := map[string]interface{}{
"nama": "Budi",
"umur": 20,
"kota": "Jakarta",
}
fmt.Println("Siswa:", siswa)
// Struct
laptop := Produk{Nama: "Laptop", Harga: 10000000}
laptop.Diskon(10)
fmt.Println(laptop.Info())
// Goroutine
go func() {
fmt.Println("Hello dari goroutine!")
}()
// Channel
ch := make(chan string)
go func() {
ch <- "Pesan dari goroutine"
}()
msg := <-ch
fmt.Println(msg)
// Error handling
result, err := bagi(10, 0)
if err != nil {
fmt.Println("Error:", err)
} else {
fmt.Println("Hasil:", result)
}
}
func bagi(a, b float64) (float64, error) {
if b == 0 {
return 0, fmt.Errorf("pembagian dengan nol")
}
return a / b, nil
}
Tips Belajar Go
- Pelajari dari Tour of Go — tour.golang.org (official interactive tutorial)
- Pahami goroutines & channels — Fitur utama Go
- Ikuti Go conventions — gofmt, go vet, golangci-lint
- Bangun project REST API — Cara terbaik belajar Go
- Pelajari standard library — Go stdlib sangat lengkap
- Baca Effective Go — Dokumentasi best practices
Tools yang Dibutuhkan
| Tool | Deskripsi |
|---|---|
| Go SDK | Compiler dan runtime Go (go.dev) |
| VS Code + Go extension | Code editor dengan Go support |
| GoLand | IDE khusus Go (JetBrains) |
| Docker | Containerization |
| Git | Version control |
Kesimpulan
Go adalah bahasa pemrograman modern yang sederhana namun powerful. Dengan performa tinggi dan dukungan concurrency yang excellent, Go adalah pilihan ideal untuk backend, microservices, dan cloud-native applications. Mulai dari dasar, praktik konsisten!
"Go is not meant to innovate programming theory. It's meant to innovate programming practice." — Rob Pike




