Go adalah bahasa pemrograman yang dibuat oleh Google pada tahun 2009. Tiga insinyur senior — Robert Griesemer, Rob Pike, dan Ken Thompson — menciptakannya karena frustasi dengan kompleksitas C++ dan kelambatan Java.
Hasilnya? Bahasa yang simpel seperti Python, tapi cepat seperti C. Berikut alasan kenapa Go layak dipelajari:
⚡ Performa tinggi — dikompilasi ke native binary, bisa handle jutaan request
🧵 Concurrency bawaan — goroutine dan channel memudahkan kode paralel
📦 Deployment mudah — satu file binary, tidak perlu install runtime di server
🔍 Sintaks simpel — hanya 25 keyword, mudah dibaca dan dipelajari
💼 Banyak dicari — dipakai oleh Docker, Kubernetes, Terraform, dan startup unicorn
Apa yang Akan Kita Bangun?
Sepanjang series ini kita akan membangun sebuah REST API Todo Manager — aplikasi manajemen tugas lengkap dengan:
CRUD (Create, Read, Update, Delete) task
Autentikasi JWT
Database PostgreSQL via GORM
Deployment ke VPS dengan Docker
Install Go
Windows
Download installer dari go.dev/dl, pilih versi terbaru (Go 1.22+). Jalankan installer, ikuti langkah-langkahnya.
Verifikasi instalasi:
go version
# Output: go version go1.22.0 windows/amd64
Linux / Mac
# 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
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc
source ~/.bashrc
# Mac (pakai Homebrew)
brew install go
Struktur Project Go
Di Go modern (Go 1.11+), kita pakai Go Modules untuk manajemen dependency. Tidak perlu lagi khawatir soal GOPATH.
# Buat folder project
mkdir todo-api
cd todo-api
# Inisialisasi module
go mod init github.com/username/todo-api
Perintah go mod init membuat file go.mod yang berisi nama module dan versi Go.
Hello World!
Buat file main.go:
package main
import "fmt"
func main() {
fmt.Println("Halo, Go!")
fmt.Println("Selamat datang di dunia Golang 🚀")
}
Jalankan:
go run main.go
# Output:
# Halo, Go!
# Selamat datang di dunia Golang 🚀
Memahami Kode di Atas
package main — setiap file Go harus punya package. Package main adalah entry point aplikasi.
import "fmt" — mengimpor package fmt (format) dari standard library untuk input/output.
func main() — fungsi main adalah fungsi yang pertama kali dieksekusi.
fmt.Println() — mencetak teks ke konsol dengan newline di akhir.
Perintah Go yang Perlu Diketahui
go run main.go # Jalankan langsung tanpa build
go build . # Compile menjadi binary executable
go build -o app . # Compile dengan nama output 'app'
go fmt ./... # Format kode otomatis
go vet ./... # Cek potensi bug
go mod tidy # Bersihkan dependency yang tidak terpakai
Setup Editor (VS Code)
Install extension Go dari Google di VS Code. Extension ini menyediakan:
Autocomplete dan IntelliSense
Format otomatis saat save
Debugging bawaan
Linting dan error checking
Setelah install extension, VS Code akan minta install beberapa tools Go tambahan — klik "Install All".
Checklist Progress
Siap lanjut? Di Part 2 kita akan belajar sintaks dasar Go — variabel, tipe data, kondisi, dan looping.
Go is a programming language created by Google in 2009. Three senior engineers — Robert Griesemer, Rob Pike, and Ken Thompson — created it out of frustration with the complexity of C+ + and the slowness of Java.
The result? A language as simple as Python, but as fast as C. Here are the reasons why Go is worth learning:
⚡ High performance — compiled to native binary, can handle millions of requests
Built-in 🧵 concurrency — goroutine and channel ease parallel code
Easy 📦 deployment — one binary file, no need to install runtime on server
Simple 🔍 syntax — only 25 keywords, easy to read and learn
💼 Widely used by Docker, Kubernetes, Terraform, and unicorn startups
What Will We Build?
Throughout this series we will build a Todo Manager rest API — a task management application complete with:
CRUD (Create, Read, Update, Delete) task
JWT Authentication
PostgreSQL Database via Gorm
Deployment to VPS with Docker
Install Go
Windows
Download the installer from go.dev/dl, select the latest version (Go 1.22+). Run the installer, follow thesteps.
Verify installation:
go version
# Output: go version go1.22.0 windows/amd64
Linux / Mac
# 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
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc
source ~/.bashrc
# Mac (pakai Homebrew)
brew install go
Structure of Project Go
In modern Go (Go 1.11+), we use Go Modules for dependency management. No more worrying about GOPATH.
# Buat folder project
mkdir todo-api
cd todo-api
# Inisialisasi module
go mod init github.com/username/todo-api
The go mod init command creates a go.mod file containing the module name and Go version.
"Hello, World!" program
Create main.go file:
package main
import "fmt"
func main() {
fmt.Println("Halo, Go!")
fmt.Println("Selamat datang di dunia Golang 🚀")
}
Go
go run main.go
# Output:
# Halo, Go!
# Selamat datang di dunia Golang 🚀
Understanding the Code Above
package main — each Go file must have a package. Package main is the application entry point.
import "FMT" — import FMT packages (formats) from standard libraries for input/output.
func main() — the main function is the first executed function.
fmt.Println() — prints text to the console with the newline at the end.
Need-to-Know Go Commands
go run main.go # Jalankan langsung tanpa build
go build . # Compile menjadi binary executable
go build -o app . # Compile dengan nama output 'app'
go fmt ./... # Format kode otomatis
go vet ./... # Cek potensi bug
go mod tidy # Bersihkan dependency yang tidak terpakai
Setup Editor (VS Code)
Install the Go extension from Google in VS Code. This extension provides:
Autocomplete and IntelliSense
Auto-format on save
Built-in debugging
Linting and error checking
After installing the extension, VS Code will ask to install some additional Go tools — click "Install All".
Progress Checklist
Ready to go further? In Part 2 we'll learn the basic syntax of Go-variables, data types, conditions, and looping.
Komentar 0