What Go Does
- Compiled — fast native binaries, cross-compile
- Garbage collected — low-pause GC optimized for latency
- Static typing — with type inference via
:= - Goroutines — cheap concurrent functions (thousands per MB)
- Channels — CSP-style communication between goroutines
- Interfaces — structural typing, no inheritance
- Standard library — HTTP, crypto, JSON, SQL all in stdlib
- Tooling — go fmt, vet, test, doc, mod built in
- Modules — dependency management since Go 1.11
- Generics — since Go 1.18
Architecture
Compiler (gc) written in Go itself, plus gccgo alternative. Runtime manages goroutine scheduler (M:N mapping to OS threads), memory allocator, and garbage collector. Single static binary output — no DLL hell.
Self-Hosting
Language toolchain. Installs via official installer or package manager.
Key Features
- Single static binary output
- Lightning-fast compilation
- Cross-compilation (GOOS/GOARCH)
- Goroutines + channels
- Rich standard library
- go fmt canonical formatting
- Comprehensive tooling (test, vet, doc)
- Generics (since 1.18)
- Fuzzing (since 1.18)
- Workspaces for multi-module dev
Comparison
| Language | Concurrency | Compilation | GC | Typical Use |
|---|---|---|---|---|
| Go | Goroutines/CSP | Fast | Yes | Cloud infra |
| Rust | Async + threads | Slow | No (ownership) | Systems |
| Java | Threads + Project Loom | Medium | Yes | Enterprise |
| Python | asyncio | Interpreted | Yes | Scripts, ML |
| C++ | Threads + coroutines | Slow | No | Performance |
| Node.js | Event loop | JIT | Yes | Web APIs |
常见问题 FAQ
Q: Go 适合 web 开发吗? A: 非常适合。标准库有完整 HTTP server,加上 Gin、Echo、Fiber、Chi 等 framework。Go 也是微服务和 gRPC 后端的首选。
Q: 泛型什么时候加的? A: Go 1.18 (2022年3月)。之前要靠 interface{} 或代码生成,现在可以写真正的类型参数化函数和类型。
Q: Goroutines 和 OS 线程区别? A: Goroutine 是 Go 运行时管理的用户态协程,初始栈 2KB(vs OS 线程 1-8MB)。调度器在 OS 线程上 M:N 调度 goroutine,可轻松开百万个。
来源与致谢 Sources
- Docs: https://go.dev/doc
- GitHub: https://github.com/golang/go
- License: BSD 3-Clause