Go's 25 Keywords, Goroutines, and Single-Binary Deploys: A First-Look Setup Guide
Go (also known as Golang) is a statically compiled programming language launched by Google in 2007 and officially open-sourced in 2009. It was primarily developed by Rob Pike, Ken Thompson (the father of C and Unix), and Robert Griesemer.
Let's understand Go through a mythological story:
- Unix — The Primordial Ancestor (sets the heavenly rules of the system)
- C — The Jade Disc of Creation (the core foundational technique, the base of all things)
- BSD / System V / Linux — The Three Pure Ones, the Great Sages (the three disciples of the Primordial Ancestor, each evolving their own lineage)
- C++ — The Grand Supreme Elderly Lord (refines spiritual treasures based on the foundational technique, most feature-rich, specialized for complex large-scale infrastructure)
- Go — A new simplified technique created by the descendants of the Primordial Ancestor (Ken Thompson is a Unix/C elder, simplifying C to adapt to the Cloud Wilderness)
- Java — The Western Guide (wraps a layer of virtual machine barrier, cross-world universal, but heavy and cumbersome)
- Python — The lazy technique of rogue cultivators (easy to start, encapsulates the bottom layer, no need to painstakingly cultivate basic internal skills)
- Windows — An Outer Domain Demon God, forming its own small world, early on rejecting the Primordial Ancestor's lineage
Go Language Features
Go's design philosophy is "less is more" — cutting redundant features, focusing on engineering efficiency and maintainability. Here are its core features:
- Native Concurrency: Implements the CSP concurrency model based on goroutines and channels. The initial stack of a goroutine is only a few KB, far lighter than traditional OS threads, scheduled uniformly by the runtime, naturally suited for high-concurrency services.
- Automatic Memory Management: Built-in GC garbage collector, eliminating the need for manual memory allocation and deallocation like in C/C++, striking a balance between development efficiency and runtime safety.
- Static Compilation: The compilation product is a single executable file with no external runtime dependencies. Copy it to the target machine and run it; deployment is extremely simple.
- Cross-platform Compilation: Built-in cross-compilation capability. A single
go buildcommand on macOS can produce binary files for Linux, Windows, and other platforms. - Simple Syntax: Only 25 keywords, using composition instead of inheritance, rejecting over-design. Code is easy to read and write, with a gentle learning curve.
- Extremely Fast Compilation: Full compilation of large projects is usually completed in seconds. After modifying code, it's almost instant to compile and run, providing a smooth development experience.
- Powerful Standard Library: Core libraries like
net/http,encoding/json,contextare battle-tested in production. Common needs like networking, serialization, and concurrency control are available out of the box. - Integrated Toolchain:
go modmanages dependencies,go testruns tests,go fmtunifies formatting. Official tools support the entire workflow from coding to release.
How to Install Go
1. Download the Installation Package
The Go installation package can be downloaded from the Go official website.
Select your corresponding operating system and click to download the installation package.
2. Install Go
Click "Next" all the way until the installation is complete.
3. Verify Installation
Enter the go version command in the terminal. If the Go version information is displayed, the installation is successful. (The main package currently uses version 1.26.4)
4. Download Editor
It is recommended to use the VS Code editor, as the Go official team recommends VS Code as the development tool. Click "Next" all the way after downloading until the installation is complete.
5. Configure Go Language Plugin
Install the Go language plugin in VS Code. After installation, VS Code will automatically configure the Go language environment.
Why This Tutorial and Why Learn Go
Why Write This Tutorial
There is no shortage of Chinese Go materials, but the quality is uneven—some are too shallow, others directly translate official documentation, lacking a clear learning path. This series aims to provide a systematic, hands-on introductory guide for those starting from zero or transitioning from other languages, to help them avoid detours.
Why Learn Go
- High Job Market Demand: Backend, infrastructure, and middleware positions at major companies like ByteDance, Tencent, Meituan, and Baidu heavily recruit Go developers; it's almost unavoidable in cloud-native and microservices directions.
- Competitive Salary: Engineers with Go + cloud-native (K8s, Docker) skills generally have more bargaining power in the market than pure CRUD backend developers.
- Relatively Friendly Entry Barrier: Simple syntax, few keywords. Those with a foundation in Python, Java, or frontend JS can usually write runnable services within one to two weeks.
- A Pragmatic Choice for Frontend to Full-Stack Transition: As competition for pure frontend positions intensifies, mastering Go allows one to independently complete backend APIs and middleware logic, moving towards full-stack or platform engineering.
- The 'Official Language' of the Cloud-Native Era: Core infrastructure like Docker, Kubernetes, Prometheus, and Etcd are all written in Go. Learning Go helps truly understand the underlying principles of these tools.
- Mainstream Tech Stack for Blockchain/Web3: The Ethereum Go client Geth, Hyperledger Fabric, etc., are all based on Go, and related positions universally list it as a hard requirement.
- Wide Range of Application Scenarios: Microservice APIs, command-line tools, crawlers, message queues, gateways, DevOps scripts—covering everything from business to infrastructure.
- Balance of Performance and Development Efficiency: Fast compilation, simple deployment, clear concurrency model. In scenarios requiring high concurrency but wanting to avoid the complexity of C++, Go is a highly cost-effective choice.
If you fall into any of the following categories, this is a great place to start:
- Want to transition to backend or full-stack but don't know where to begin
- Work in operations/cloud computing and want to read the code of the K8s ecosystem
- Are a student or career changer hoping to master a practical language that's "good for finding a job"
- Already know some programming and want to systematically complete your Go knowledge system
Hello World
We can create a new hello.go file and enter the following code:
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
Then open the terminal and enter the go run hello.go command to run the program.
go run hello.go
Output> Hello, World!
package main
package main
- package main = Tells the Go compiler that this is the entry package of the program (executable program).
- Go officially stipulates that the program entry must be called main, the name is fixed and cannot be modified.
For example, if I change it to aaa, it will report an error:
package aaa
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
package command-line-arguments is not a main package # Error message
import "fmt"
Import the fmt package from the Go standard library, allowing the current file to use its provided functions.
- fmt: The formatted input/output package officially provided by Go.
- Println(): A function in the fmt package used to print content and add a newline.
func main()
- func main(): Defines a function named main, which is the entry function of the Go program.
- {}: The code block of the main function, required.
- fmt.Println("Hello, World!"): Calls the Println function from the fmt package to print the "Hello, World!" string.
Assignment
- Modify the
hello.gofile, changing "Hello, World!" to "Hello, Go!". - Run the program and observe the output result.
Top 2 from juejin.cn, machine-translated. The original thread is authoritative.
When I have AI write tools, I basically use Go now — the compiled binary is small.
```go package main import "fmt" func main() { fmt.Println("Hello, go!") } ```