跪拜 Guibai
← Back to the summary

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:

  1. Unix — The Primordial Ancestor (sets the heavenly rules of the system)
  2. C — The Jade Disc of Creation (the core foundational technique, the base of all things)
  3. BSD / System V / Linux — The Three Pure Ones, the Great Sages (the three disciples of the Primordial Ancestor, each evolving their own lineage)
  4. C++ — The Grand Supreme Elderly Lord (refines spiritual treasures based on the foundational technique, most feature-rich, specialized for complex large-scale infrastructure)
  5. 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)
  6. Java — The Western Guide (wraps a layer of virtual machine barrier, cross-world universal, but heavy and cumbersome)
  7. Python — The lazy technique of rogue cultivators (easy to start, encapsulates the bottom layer, no need to painstakingly cultivate basic internal skills)
  8. Windows — An Outer Domain Demon God, forming its own small world, early on rejecting the Primordial Ancestor's lineage

image.png

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:

  1. 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.
  2. 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.
  3. 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.
  4. Cross-platform Compilation: Built-in cross-compilation capability. A single go build command on macOS can produce binary files for Linux, Windows, and other platforms.
  5. 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.
  6. 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.
  7. Powerful Standard Library: Core libraries like net/http, encoding/json, context are battle-tested in production. Common needs like networking, serialization, and concurrency control are available out of the box.
  8. Integrated Toolchain: go mod manages dependencies, go test runs tests, go fmt unifies 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.

image.png

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.

image.png

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)

image.png

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.

image.png

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

  1. 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.
  2. Competitive Salary: Engineers with Go + cloud-native (K8s, Docker) skills generally have more bargaining power in the market than pure CRUD backend developers.
  3. 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.
  4. 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.
  5. 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.
  6. 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.
  7. Wide Range of Application Scenarios: Microservice APIs, command-line tools, crawlers, message queues, gateways, DevOps scripts—covering everything from business to infrastructure.
  8. 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:

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
  1. package main = Tells the Go compiler that this is the entry package of the program (executable program).
  2. 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.

  1. fmt: The formatted input/output package officially provided by Go.
  2. Println(): A function in the fmt package used to print content and add a newline.

func main()

  1. func main(): Defines a function named main, which is the entry function of the Go program.
  2. {}: The code block of the main function, required.
  3. fmt.Println("Hello, World!"): Calls the Println function from the fmt package to print the "Hello, World!" string.

Assignment

  1. Modify the hello.go file, changing "Hello, World!" to "Hello, Go!".
  2. Run the program and observe the output result.
Comments

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.

Selicens

```go package main import "fmt" func main() { fmt.Println("Hello, go!") } ```