Agent skill · software engineering · affaan-m
golang-patterns
Idiomatic Go patterns, best practices, and conventions for building robust, efficient, and maintainable Go applications.
Why this skill is useful
Provides idiomatic Go patterns and best practices that the AI wouldn't reliably generate on its own.
What it needs
About 6k tokens when loaded. Last updated 2026-08-06. 238,342 stars on the source repository.
What this skill does
Go 開發模式 用於建構穩健、高效且可維護應用程式的慣用 Go 模式和最佳實務。 何時啟用 撰寫新的 Go 程式碼 審查 Go 程式碼 重構現有 Go 程式碼 設計 Go 套件/模組 核心原則 1. 簡單與清晰 Go 偏好簡單而非聰明。程式碼應該明顯且易讀。 2. 讓零值有用 設計類型使其零值無需初始化即可立即使用。 3. 接受介面,回傳結構 函式應接受介面參數並回傳具體類型。 錯誤處理模式 帶上下文的錯誤包裝 自訂錯誤類型 使用 errors.Is 和 errors.As 檢查錯誤 絕不忽略錯誤 並行模式 Worker Pool 取消和逾時的 Context 優雅關閉 協調 Goroutines 的 errgroup 避免 Goroutine 洩漏 介面設計 小而專注的介面 在使用處定義介面 使用型別斷言的可選行為 套件組織 標準專案結構 套件命名 避免套件層級狀態 結構設計 Functional Options 模式 嵌入用於組合 記憶體與效能 已知大小時預分配 Slice 頻繁分配使用 sync.Pool 避免迴圈中的字串串接 Go 工具整合 基本指令 建議的 Linter 設定(.golangci.yml) 快速參考:Go 慣用語 慣用語 描述 ------- ------ 接受介面,回傳結構 函式接受介面參數,回傳具體類型 錯誤是值 將錯誤視為一等值,而非例外 不要透過共享記憶體通訊 使用 channel 在 goroutine 間協調 讓零值有用 類型應無需明確初始化即可工作 一點複製比一點依賴好 避免不必要的外部依賴 清晰優於聰明 優先考慮可讀性而非聰明 gofmt 不是任何人的最愛但是所有人的朋友 總是用 gofmt/goimports 格式化 提早返回 先處理錯誤,保持快樂路徑不縮排 要避免的反模式 記住:Go 程式碼應該以最好的方式無聊 - 可預測、一致且易於理解。有疑慮時,保持簡單。
How to use it
Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:
@skills affaan-m/golang-patterns--cf781c