Skills Plugins MCP Prompt Model 博客 我的中心

golang-patterns

Go-specific design patterns and best practices including functional options, small interfaces, dependency injection, concurrency patterns, error handling, and package organization. Use when working with Go code to apply idiomatic Go patterns.

DeepseekModel 官方收录技能 质量 优秀 · 90 v1.0.0

获取

https://deepseekmodel.com/api/download.php?id=affaan-m-ecc-kiro-skills-golang-patterns-skill-md&format=skill
下载 .skill 标准格式,含 system_prompt 与 model_config,导入任意 Agent 框架即可使用
.skill 文件中 system_prompt 字段的实际内容。
name golang-patterns description Go-specific design patterns and best practices including functional options, small interfaces, dependency injection, concurrency patterns, error handling, and package organization. Use when working with Go code to apply idiomatic Go patterns. metadata {"origin":"ECC","globs":["**/*.go","**/go.mod","**/go.sum"]} Go Patterns This skill provides comprehensive Go patterns extending common design principles with Go-specific idioms. Functional Options Use the functional options pattern for flexible constructor configuration: 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 } Benefits: Backward compatible API evolution Optional parameters with defaults Self-documenting configuration Small Interfaces Define interfaces where they are used, not where they are implemented. Principle: Accept interfaces, return structs // Good: Small, focused interface defined at point of use type UserStore interface { GetUser(id string ) (*User, error ) } func ProcessUser (store UserStore, id string ) error { user, err := store.GetUser(id) // ... } Benefits: Easier testing and mocking Loose coupling Clear dependencies Dependency Injection Use constructor functions to inject dependencies: func NewUserService (repo UserRepository, logger Logger) *UserService { return &UserService{ repo: repo, logger: logger, } } Pattern: Constructor functions (New* prefix) Explicit dependencies as parameters Return concrete types Validate dependencies in constructor Concurrency Patterns Worker Pool func workerPool (jobs <- chan Job, results chan <- Result, workers int ) { var wg sync.WaitGroup for i := 0 ; i < workers; i++ { wg.Add( 1 ) go func () { defer wg.Done() for job := range jobs { results <- processJob(job) } }() } wg.Wait() close (results) } Context Propagation Always pass context as first parameter: func FetchUser (ctx context.Context, id string ) (*User, error ) { // Check context cancellation select { case <-ctx.Done(): return nil , ctx.Err() default : } // ... fetch logic } Error Handling Error Wrapping if err != nil { return fmt.Errorf( "failed to fetch user %s: %w" , id, err) } Custom Errors type ValidationError struct { Field string Msg string } func (e *ValidationError) Error() string { return fmt.Sprintf( "%s: %s" , e.Field, e.Msg) } Sentinel Errors var ( ErrNotFound = errors.New( "not found" ) ErrInvalid = errors.New( "invalid input" ) ) // Check with errors.Is if errors.Is(err, ErrNotFound) { // handle not found } Package Organization Structure project/ ├── cmd/ # Main applications │ └── server/ │ └── main.go ├── internal/ # Private application code │ ├── domain/ # Business logic │ ├── handler/ # HTTP handlers │ └── repository/ # Data access └── pkg/ # Public libraries Naming Conventions Package names: lowercase, single word Avoid stutter: user.User not user.UserModel Use internal/ for private code Keep main package minimal Testing Patterns Table-Driven Tests func TestValidate (t *testing.T) { tests := [] struct { name string input string wantErr bool }{ { "valid" , "test@example.com" , false }, { "invalid" , "not-an-email" , true }, } for _, tt := range tests { t.Run(tt.name, func (t *testing.T) { err := Validate(tt.input) if (err != nil ) != tt.wantErr { t.Errorf( "got error %v, wantErr %v" , err, tt.wantErr) } }) } } Test Helpers func testDB (t *testing.T) *sql.DB { t.Helper() db, err := sql.Open( "sqlite3" , ":memory:" ) if err != nil { t.Fatalf( "failed to open test db: %v" , err) } t.Cleanup( func () { db.Close() }) return db } When to Use This Skill Designing Go APIs and packages Implementing concurrent systems Structuring Go projects Writing idiomatic Go code Refactoring Go codebases
Agent 识别该技能的关键词,点击任意一个即可复制。

该技能未提供触发词。

下载的 .skill 包内含以下字段。
字段 说明
format格式标识(skill/v1)
skill_id技能唯一 ID
name技能名称
version版本号
description技能描述
category所属分类(数组)
trigger_words触发词列表
tags标签列表
source来源标识
source_url来源链接(本页地址)
exported_at导出时间(每次下载生成)
system_prompt系统提示词正文
model_config模型参数:provider / model / temperature / max_tokens / top_p
examples示例
install_guide各平台导入说明(Coze / Dify / Claude / 自定义框架)
同一份技能可按不同平台格式导出。
.skill 标准格式,含 system_prompt 与 model_config,导入任意 Agent 框架即可使用 下载
.skillpro 增强格式,额外含脚本 / 工具 / 依赖 / 钩子占位 下载
.json 纯 JSON 导出,只含 system_prompt 与模型参数 下载
Coze 带 frontmatter 的 Markdown,Coze 平台导入用 下载
Dify Dify DSL,创建应用后直接导入 下载

每日精选 Skill 推荐,免费送到你邮箱

输入邮箱,每天接收一个精选 AI Agent 技能推荐。完全免费,持续更新。

提交后我们会发送一封确认邮件,点击邮件里的链接才会开始收信。

完全免费,取消任意时间。我们不会发送垃圾邮件。