$npx -y skills add saifoelloh/golang-best-practices-skill --skill idiomatic-goIdiomatic Go style and best practices review. Use when checking interface design, pointer usage, or Go-specific idioms. Ensures code follows standard Go conventions and readability principles.
| 1 | # Golang Idiomatic Patterns |
| 2 | |
| 3 | Expert-level review for idiomatic Go patterns. Ensures code follows Go conventions, proper interface design, and appropriate pointer usage. |
| 4 | |
| 5 | ## When to Apply |
| 6 | |
| 7 | Use this skill when: |
| 8 | - Ensuring code follows Go idioms |
| 9 | - Reviewing interface design patterns |
| 10 | - Checking pointer vs value usage |
| 11 | - Verifying "Accept interfaces, return structs" pattern |
| 12 | - Auditing usecase complexity |
| 13 | - Ensuring small, focused interfaces |
| 14 | |
| 15 | ## Rule Categories by Priority |
| 16 | |
| 17 | | Priority | Count | Focus | |
| 18 | |----------|-------|-------| |
| 19 | | High | 1 | Method receivers | |
| 20 | | Medium | 5 | Go idioms and patterns | |
| 21 | |
| 22 | ## Rules Covered (6 total) |
| 23 | |
| 24 | ### High-Impact Patterns (1) |
| 25 | |
| 26 | - `high-pointer-receiver` - Use pointer receivers for mutations |
| 27 | |
| 28 | ### Medium Improvements (5) |
| 29 | |
| 30 | - `medium-interface-pollution` - Keep interfaces small (<5 methods) |
| 31 | - `medium-accept-interface-return-struct` - API flexibility pattern |
| 32 | - `medium-pointer-overuse` - Don't overuse pointers for small types |
| 33 | - `medium-usecase-complexity` - Move business logic to domain entities |
| 34 | - `medium-interface-in-implementation` - Define interfaces where used |
| 35 | |
| 36 | ## Common Idiomatic Patterns |
| 37 | |
| 38 | ### Accept Interfaces, Return Structs |
| 39 | ```go |
| 40 | // ✅ GOOD: Accept interface, return struct |
| 41 | func Process(r io.Reader) (*Result, error) { |
| 42 | // ... |
| 43 | return &Result{}, nil |
| 44 | } |
| 45 | ``` |
| 46 | |
| 47 | ### Small Interfaces |
| 48 | ```go |
| 49 | // ✅ GOOD: Small, focused interface |
| 50 | type Reader interface { |
| 51 | Read(p []byte) (n int, err error) |
| 52 | } |
| 53 | ``` |
| 54 | |
| 55 | ### Pointer Receivers for Mutations |
| 56 | ```go |
| 57 | // ✅ GOOD: Pointer receiver modifies state |
| 58 | func (u *User) UpdateEmail(email string) { |
| 59 | u.Email = email |
| 60 | } |
| 61 | ``` |
| 62 | |
| 63 | ## Trigger Phrases |
| 64 | |
| 65 | This skill activates when you say: |
| 66 | - "Is this idiomatic Go?" |
| 67 | - "Review Go style" |
| 68 | - "Check interface design" |
| 69 | - "Verify pointer usage" |
| 70 | - "Review Go conventions" |
| 71 | - "Check for Go anti-patterns" |
| 72 | |
| 73 | ## How to Use |
| 74 | |
| 75 | ### For Idiomatic Review |
| 76 | |
| 77 | 1. Check method receivers (pointer vs value) |
| 78 | 2. Verify interface sizes and locations |
| 79 | 3. Review pointer usage appropriateness |
| 80 | 4. Check "accept interfaces, return structs" pattern |
| 81 | |
| 82 | ## Output Format |
| 83 | |
| 84 | ``` |
| 85 | ## Idiomatic Go Improvements: X |
| 86 | |
| 87 | ### [Rule Name] (Line Y) |
| 88 | **Pattern**: Interface Design / Pointer Usage / Method Receiver |
| 89 | **Issue**: Violates Go idiom |
| 90 | **Fix**: Suggested correction |
| 91 | **Example**: |
| 92 | ```go |
| 93 | // Idiomatic Go code |
| 94 | ``` |
| 95 | |
| 96 | ## Related Skills |
| 97 | |
| 98 | - [golang-clean-architecture](../clean-architecture/SKILL.md) - For interface segregation |
| 99 | - [golang-design-patterns](../design-patterns/SKILL.md) - For usecase complexity |
| 100 | |
| 101 | ## Philosophy |
| 102 | |
| 103 | Based on "Learning Go" and Effective Go: |
| 104 | |
| 105 | - **Simplicity over cleverness** - Boring code is good code |
| 106 | - **Interfaces are satisfied implicitly** - Define where used |
| 107 | - **Composition over inheritance** - Embed types, don't extend |
| 108 | - **Clear is better than clever** - Readability wins |
| 109 | |
| 110 | ## Notes |
| 111 | |
| 112 | - Focus on Go-specific patterns |
| 113 | - Not general programming practices |
| 114 | - Emphasizes Go conventions and idioms |
| 115 | - Based on Effective Go and community standards |