{
    "format": "skillpro/v1",
    "skill_id": "affaan-m-ecc-kiro-skills-golang-patterns-skill-md",
    "name": "golang-patterns",
    "version": "1.0.0",
    "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.",
    "category": [
        "开发编程"
    ],
    "trigger_words": [],
    "tags": [
        "design"
    ],
    "source": "DeepseekModel",
    "source_url": "https://deepseekmodel.com/skill?id=affaan-m-ecc-kiro-skills-golang-patterns-skill-md",
    "exported_at": "2026-09-16T08:27:04+08:00",
    "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",
    "model_config": {
        "provider": "deepseek",
        "model": "deepseek-chat",
        "temperature": 0.7,
        "max_tokens": 4096,
        "top_p": 0.9
    },
    "examples": [
        {
            "input": "请用golang-patterns帮我处理问题",
            "output": "好的，我是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. 我会根据你的需求提供专业帮助。"
        },
        {
            "input": "介绍一下你的能力",
            "output": "我是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."
        }
    ],
    "install_guide": {
        "coze": "在 Coze 平台创建 Bot -> 技能配置 -> 导入此 .skill 文件",
        "dify": "在 Dify 平台创建应用 -> 添加知识库 -> 导入此 .skill 配置",
        "claude": "将 system_prompt 字段内容复制到 Claude 自定义指令中",
        "custom": "将此 .skill 文件加载到你的 AI Agent 框架中，解析 system_prompt 和 model_config 即可使用"
    },
    "scripts": {
        "python": "# golang-patterns - Python extension\n# Add custom Python logic here\ndef process(input_data):\n    return input_data\n",
        "javascript": "// golang-patterns - JavaScript extension\n// Add custom JS logic here\nfunction process(inputData) {\n    return inputData;\n}\n"
    },
    "tools": {
        "mcp_servers": [],
        "api_endpoints": []
    },
    "dependencies": {
        "python": [],
        "node": []
    },
    "hooks": {
        "on_load": "echo \"Skill loaded: golang-patterns\"",
        "on_call": "",
        "on_error": "echo \"Skill error: please check logs\""
    }
}