docs(zh-CN): sync Chinese docs with latest upstream changes (#202)

* docs(zh-CN): sync Chinese docs with latest upstream changes

* docs: improve Chinese translation consistency in go-test.md

* docs(zh-CN): update image paths to use shared assets directory

- Update image references from ./assets/ to ../../assets/
- Remove zh-CN/assets directory to use shared assets

---------

Co-authored-by: neo <neo.dowithless@gmail.com>
This commit is contained in:
zdoc.app
2026-02-13 17:04:58 +08:00
committed by GitHub
parent 49aee612fb
commit 95f63c3cb0
41 changed files with 4651 additions and 263 deletions

View File

@@ -0,0 +1,39 @@
# Go 模式
> 本文档在 [common/patterns.md](../common/patterns.md) 的基础上扩展了 Go 语言特定的内容。
## 函数式选项
```go
type Option func(*Server)
func WithPort(port int) Option {
return func(s *Server) { s.port = port }
}
func NewServer(opts ...Option) *Server {
s := &Server{port: 8080}
for _, opt := range opts {
opt(s)
}
return s
}
```
## 小接口
在接口被使用的地方定义它们,而不是在它们被实现的地方。
## 依赖注入
使用构造函数来注入依赖:
```go
func NewUserService(repo UserRepository, logger Logger) *UserService {
return &UserService{repo: repo, logger: logger}
}
```
## 参考
有关全面的 Go 模式(包括并发、错误处理和包组织),请参阅技能:`golang-patterns`