oh-my-customcode 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +287 -0
- package/dist/cli/index.js +13299 -0
- package/dist/index.js +927 -0
- package/package.json +74 -0
- package/templates/.claude/contexts/dev.md +20 -0
- package/templates/.claude/contexts/ecomode.md +63 -0
- package/templates/.claude/contexts/index.yaml +41 -0
- package/templates/.claude/contexts/research.md +28 -0
- package/templates/.claude/contexts/review.md +23 -0
- package/templates/.claude/hooks/hooks.json +185 -0
- package/templates/.claude/hooks/hud/index.yaml +27 -0
- package/templates/.claude/hooks/hud/update-status.sh +32 -0
- package/templates/.claude/hooks/index.yaml +46 -0
- package/templates/.claude/hooks/memory-persistence/pre-compact.sh +37 -0
- package/templates/.claude/hooks/memory-persistence/session-end.sh +64 -0
- package/templates/.claude/hooks/memory-persistence/session-start.sh +41 -0
- package/templates/.claude/hooks/strategic-compact/suggest-compact.sh +50 -0
- package/templates/.claude/install-hooks.sh +100 -0
- package/templates/.claude/rules/MAY-optimization.md +93 -0
- package/templates/.claude/rules/MUST-agent-design.md +107 -0
- package/templates/.claude/rules/MUST-agent-identification.md +108 -0
- package/templates/.claude/rules/MUST-continuous-improvement.md +132 -0
- package/templates/.claude/rules/MUST-intent-transparency.md +199 -0
- package/templates/.claude/rules/MUST-language-policy.md +62 -0
- package/templates/.claude/rules/MUST-orchestrator-coordination.md +266 -0
- package/templates/.claude/rules/MUST-parallel-execution.md +341 -0
- package/templates/.claude/rules/MUST-permissions.md +84 -0
- package/templates/.claude/rules/MUST-safety.md +69 -0
- package/templates/.claude/rules/MUST-sync-verification.md +219 -0
- package/templates/.claude/rules/MUST-tool-identification.md +112 -0
- package/templates/.claude/rules/SHOULD-ecomode.md +145 -0
- package/templates/.claude/rules/SHOULD-error-handling.md +102 -0
- package/templates/.claude/rules/SHOULD-hud-statusline.md +89 -0
- package/templates/.claude/rules/SHOULD-interaction.md +103 -0
- package/templates/.claude/rules/SHOULD-memory-integration.md +114 -0
- package/templates/.claude/rules/SHOULD-pipeline-mode.md +165 -0
- package/templates/.claude/rules/index.yaml +125 -0
- package/templates/.claude/uninstall-hooks.sh +52 -0
- package/templates/CLAUDE.md.en +259 -0
- package/templates/CLAUDE.md.ko +259 -0
- package/templates/agents/index.yaml +237 -0
- package/templates/agents/infra-engineer/aws-expert/AGENT.md +47 -0
- package/templates/agents/infra-engineer/aws-expert/index.yaml +27 -0
- package/templates/agents/infra-engineer/docker-expert/AGENT.md +47 -0
- package/templates/agents/infra-engineer/docker-expert/index.yaml +27 -0
- package/templates/agents/manager/creator/AGENT.md +274 -0
- package/templates/agents/manager/creator/index.yaml +66 -0
- package/templates/agents/manager/gitnerd/AGENT.md +91 -0
- package/templates/agents/manager/gitnerd/index.yaml +55 -0
- package/templates/agents/manager/sauron/AGENT.md +153 -0
- package/templates/agents/manager/sauron/index.yaml +52 -0
- package/templates/agents/manager/supplier/AGENT.md +142 -0
- package/templates/agents/manager/supplier/index.yaml +31 -0
- package/templates/agents/manager/sync-checker/AGENT.md +34 -0
- package/templates/agents/manager/sync-checker/index.yaml +32 -0
- package/templates/agents/manager/updater/AGENT.md +125 -0
- package/templates/agents/manager/updater/index.yaml +31 -0
- package/templates/agents/orchestrator/dev-lead/AGENT.md +116 -0
- package/templates/agents/orchestrator/dev-lead/index.yaml +73 -0
- package/templates/agents/orchestrator/planner/AGENT.md +102 -0
- package/templates/agents/orchestrator/planner/index.yaml +38 -0
- package/templates/agents/orchestrator/qa-lead/AGENT.md +92 -0
- package/templates/agents/orchestrator/qa-lead/index.yaml +40 -0
- package/templates/agents/orchestrator/secretary/AGENT.md +132 -0
- package/templates/agents/orchestrator/secretary/index.yaml +55 -0
- package/templates/agents/qa-team/qa-engineer/AGENT.md +98 -0
- package/templates/agents/qa-team/qa-engineer/index.yaml +59 -0
- package/templates/agents/qa-team/qa-planner/AGENT.md +75 -0
- package/templates/agents/qa-team/qa-planner/index.yaml +47 -0
- package/templates/agents/qa-team/qa-writer/AGENT.md +98 -0
- package/templates/agents/qa-team/qa-writer/index.yaml +44 -0
- package/templates/agents/sw-architect/documenter/AGENT.md +120 -0
- package/templates/agents/sw-architect/documenter/index.yaml +39 -0
- package/templates/agents/sw-architect/speckit-agent/AGENT.md +127 -0
- package/templates/agents/sw-architect/speckit-agent/index.yaml +78 -0
- package/templates/agents/sw-engineer/backend/express-expert/AGENT.md +132 -0
- package/templates/agents/sw-engineer/backend/express-expert/index.yaml +36 -0
- package/templates/agents/sw-engineer/backend/fastapi-expert/AGENT.md +47 -0
- package/templates/agents/sw-engineer/backend/fastapi-expert/index.yaml +27 -0
- package/templates/agents/sw-engineer/backend/go-backend-expert/AGENT.md +47 -0
- package/templates/agents/sw-engineer/backend/go-backend-expert/index.yaml +27 -0
- package/templates/agents/sw-engineer/backend/nestjs-expert/AGENT.md +107 -0
- package/templates/agents/sw-engineer/backend/nestjs-expert/index.yaml +43 -0
- package/templates/agents/sw-engineer/backend/springboot-expert/AGENT.md +103 -0
- package/templates/agents/sw-engineer/backend/springboot-expert/index.yaml +69 -0
- package/templates/agents/sw-engineer/frontend/svelte-agent/AGENT.md +71 -0
- package/templates/agents/sw-engineer/frontend/svelte-agent/index.yaml +41 -0
- package/templates/agents/sw-engineer/frontend/vercel-agent/AGENT.md +67 -0
- package/templates/agents/sw-engineer/frontend/vercel-agent/index.yaml +43 -0
- package/templates/agents/sw-engineer/frontend/vuejs-agent/AGENT.md +71 -0
- package/templates/agents/sw-engineer/frontend/vuejs-agent/index.yaml +48 -0
- package/templates/agents/sw-engineer/language/golang-expert/AGENT.md +47 -0
- package/templates/agents/sw-engineer/language/golang-expert/index.yaml +27 -0
- package/templates/agents/sw-engineer/language/java21-expert/AGENT.md +122 -0
- package/templates/agents/sw-engineer/language/java21-expert/index.yaml +51 -0
- package/templates/agents/sw-engineer/language/kotlin-expert/AGENT.md +47 -0
- package/templates/agents/sw-engineer/language/kotlin-expert/index.yaml +27 -0
- package/templates/agents/sw-engineer/language/python-expert/AGENT.md +47 -0
- package/templates/agents/sw-engineer/language/python-expert/index.yaml +27 -0
- package/templates/agents/sw-engineer/language/rust-expert/AGENT.md +47 -0
- package/templates/agents/sw-engineer/language/rust-expert/index.yaml +27 -0
- package/templates/agents/sw-engineer/language/typescript-expert/AGENT.md +47 -0
- package/templates/agents/sw-engineer/language/typescript-expert/index.yaml +27 -0
- package/templates/agents/sw-engineer/tooling/bun-expert/AGENT.md +73 -0
- package/templates/agents/sw-engineer/tooling/bun-expert/index.yaml +46 -0
- package/templates/agents/sw-engineer/tooling/npm-expert/AGENT.md +160 -0
- package/templates/agents/sw-engineer/tooling/npm-expert/index.yaml +45 -0
- package/templates/agents/sw-engineer/tooling/optimizer/AGENT.md +170 -0
- package/templates/agents/sw-engineer/tooling/optimizer/index.yaml +45 -0
- package/templates/agents/system/memory-keeper/AGENT.md +126 -0
- package/templates/agents/system/memory-keeper/index.yaml +45 -0
- package/templates/agents/system/naggy/AGENT.md +72 -0
- package/templates/agents/system/naggy/index.yaml +35 -0
- package/templates/commands/COMMANDS.md +136 -0
- package/templates/commands/creator/agent.md +121 -0
- package/templates/commands/dev/refactor.md +126 -0
- package/templates/commands/dev/review.md +82 -0
- package/templates/commands/git/branch.yaml +8 -0
- package/templates/commands/git/commit.yaml +4 -0
- package/templates/commands/git/pr.yaml +4 -0
- package/templates/commands/git/status.yaml +4 -0
- package/templates/commands/git/sync.yaml +4 -0
- package/templates/commands/index.yaml +225 -0
- package/templates/commands/intent/explain.md +144 -0
- package/templates/commands/memory/recall.md +164 -0
- package/templates/commands/memory/save.md +128 -0
- package/templates/commands/naggy/add.yaml +8 -0
- package/templates/commands/naggy/done.yaml +8 -0
- package/templates/commands/naggy/list.yaml +4 -0
- package/templates/commands/naggy/priority.yaml +11 -0
- package/templates/commands/naggy/remind.yaml +4 -0
- package/templates/commands/npm/audit.yaml +62 -0
- package/templates/commands/npm/publish.yaml +52 -0
- package/templates/commands/npm/version.yaml +62 -0
- package/templates/commands/optimize/analyze.yaml +34 -0
- package/templates/commands/optimize/bundle.yaml +50 -0
- package/templates/commands/optimize/report.yaml +56 -0
- package/templates/commands/pipeline/list.md +81 -0
- package/templates/commands/pipeline/run.md +127 -0
- package/templates/commands/sauron/quick.yaml +4 -0
- package/templates/commands/sauron/report.yaml +4 -0
- package/templates/commands/sauron/watch.yaml +4 -0
- package/templates/commands/supplier/audit.md +133 -0
- package/templates/commands/supplier/fix.md +121 -0
- package/templates/commands/sync/agents.yaml +4 -0
- package/templates/commands/sync/check.yaml +4 -0
- package/templates/commands/sync/commands.yaml +4 -0
- package/templates/commands/sync/docs.yaml +4 -0
- package/templates/commands/sync/fix.yaml +4 -0
- package/templates/commands/system/help.md +137 -0
- package/templates/commands/system/lists.md +86 -0
- package/templates/commands/system/status.md +163 -0
- package/templates/commands/updater/docs.md +165 -0
- package/templates/commands/updater/external.md +214 -0
- package/templates/guides/aws/common-patterns.md +169 -0
- package/templates/guides/aws/index.yaml +26 -0
- package/templates/guides/aws/well-architected.md +143 -0
- package/templates/guides/claude-code/01-overview.md +42 -0
- package/templates/guides/claude-code/03-tools.md +107 -0
- package/templates/guides/claude-code/04-agent-skills.md +90 -0
- package/templates/guides/claude-code/05-agent-sdk.md +129 -0
- package/templates/guides/claude-code/06-mcp.md +165 -0
- package/templates/guides/claude-code/07-prompt-engineering.md +100 -0
- package/templates/guides/claude-code/08-testing.md +58 -0
- package/templates/guides/claude-code/09-guardrails.md +80 -0
- package/templates/guides/claude-code/10-monitoring.md +89 -0
- package/templates/guides/claude-code/index.yaml +51 -0
- package/templates/guides/docker/compose-best-practices.md +284 -0
- package/templates/guides/docker/dockerfile-best-practices.md +262 -0
- package/templates/guides/docker/index.yaml +26 -0
- package/templates/guides/fastapi/best-practices.md +232 -0
- package/templates/guides/fastapi/index.yaml +21 -0
- package/templates/guides/go-backend/index.yaml +26 -0
- package/templates/guides/go-backend/project-layout.md +243 -0
- package/templates/guides/go-backend/uber-style.md +212 -0
- package/templates/guides/golang/concurrency.md +282 -0
- package/templates/guides/golang/effective-go.md +309 -0
- package/templates/guides/golang/error-handling.md +250 -0
- package/templates/guides/golang/index.yaml +27 -0
- package/templates/guides/index.yaml +101 -0
- package/templates/guides/kotlin/coding-conventions.md +247 -0
- package/templates/guides/kotlin/idioms.md +234 -0
- package/templates/guides/kotlin/index.yaml +26 -0
- package/templates/guides/python/index.yaml +26 -0
- package/templates/guides/python/pep8-style-guide.md +202 -0
- package/templates/guides/python/zen-of-python.md +79 -0
- package/templates/guides/rust/error-handling.md +262 -0
- package/templates/guides/rust/index.yaml +26 -0
- package/templates/guides/rust/ownership.md +180 -0
- package/templates/guides/springboot/best-practices.md +361 -0
- package/templates/guides/springboot/index.yaml +22 -0
- package/templates/guides/typescript/advanced-types.md +225 -0
- package/templates/guides/typescript/index.yaml +26 -0
- package/templates/guides/typescript/type-system.md +219 -0
- package/templates/guides/web-design/accessibility.md +66 -0
- package/templates/guides/web-design/index.yaml +20 -0
- package/templates/guides/web-design/performance.md +102 -0
- package/templates/pipelines/examples/code-review.yaml +66 -0
- package/templates/pipelines/index.yaml +18 -0
- package/templates/pipelines/templates/pipeline-template.yaml +50 -0
- package/templates/skills/backend/fastapi-best-practices/SKILL.md +269 -0
- package/templates/skills/backend/fastapi-best-practices/index.yaml +25 -0
- package/templates/skills/backend/go-backend-best-practices/SKILL.md +337 -0
- package/templates/skills/backend/go-backend-best-practices/index.yaml +26 -0
- package/templates/skills/backend/springboot-best-practices/SKILL.md +356 -0
- package/templates/skills/backend/springboot-best-practices/index.yaml +27 -0
- package/templates/skills/development/go-best-practices/SKILL.md +202 -0
- package/templates/skills/development/go-best-practices/index.yaml +25 -0
- package/templates/skills/development/kotlin-best-practices/SKILL.md +255 -0
- package/templates/skills/development/kotlin-best-practices/index.yaml +27 -0
- package/templates/skills/development/python-best-practices/SKILL.md +221 -0
- package/templates/skills/development/python-best-practices/index.yaml +25 -0
- package/templates/skills/development/react-best-practices/SKILL.md +100 -0
- package/templates/skills/development/react-best-practices/index.yaml +39 -0
- package/templates/skills/development/rust-best-practices/SKILL.md +266 -0
- package/templates/skills/development/rust-best-practices/index.yaml +26 -0
- package/templates/skills/development/typescript-best-practices/SKILL.md +320 -0
- package/templates/skills/development/typescript-best-practices/index.yaml +28 -0
- package/templates/skills/development/vercel-deploy/SKILL.md +73 -0
- package/templates/skills/development/vercel-deploy/index.yaml +30 -0
- package/templates/skills/development/web-design-guidelines/SKILL.md +117 -0
- package/templates/skills/development/web-design-guidelines/index.yaml +34 -0
- package/templates/skills/index.yaml +129 -0
- package/templates/skills/infrastructure/aws-best-practices/SKILL.md +279 -0
- package/templates/skills/infrastructure/aws-best-practices/index.yaml +27 -0
- package/templates/skills/infrastructure/docker-best-practices/SKILL.md +274 -0
- package/templates/skills/infrastructure/docker-best-practices/index.yaml +26 -0
- package/templates/skills/orchestration/intent-detection/SKILL.md +214 -0
- package/templates/skills/orchestration/intent-detection/index.yaml +30 -0
- package/templates/skills/orchestration/intent-detection/patterns/agent-triggers.yaml +333 -0
- package/templates/skills/orchestration/pipeline-execution/SKILL.md +188 -0
- package/templates/skills/orchestration/pipeline-execution/index.yaml +27 -0
- package/templates/skills/system/memory-management/SKILL.md +194 -0
- package/templates/skills/system/memory-management/index.yaml +30 -0
- package/templates/skills/system/result-aggregation/SKILL.md +163 -0
- package/templates/skills/system/result-aggregation/index.yaml +36 -0
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
# Effective Go Reference
|
|
2
|
+
|
|
3
|
+
> Source: https://go.dev/doc/effective_go
|
|
4
|
+
|
|
5
|
+
## Introduction
|
|
6
|
+
|
|
7
|
+
Go is a new language. Although it borrows ideas from existing languages, it has unusual properties that make effective Go programs different in character from programs written in its relatives. A straightforward translation of a C++ or Java program into Go is unlikely to produce a satisfactory result—Java programs are written in Java, not Go.
|
|
8
|
+
|
|
9
|
+
## Formatting
|
|
10
|
+
|
|
11
|
+
Use `gofmt` (or `goimports`) to format all Go code. This eliminates formatting debates and ensures consistency.
|
|
12
|
+
|
|
13
|
+
Key points:
|
|
14
|
+
- Indentation: tabs, not spaces
|
|
15
|
+
- No line length limit (but break long lines sensibly)
|
|
16
|
+
- Fewer parentheses than C/Java
|
|
17
|
+
|
|
18
|
+
## Commentary
|
|
19
|
+
|
|
20
|
+
Go provides C-style `/* */` block comments and C++-style `//` line comments.
|
|
21
|
+
|
|
22
|
+
- Package comments: precede package clause, block comment for multi-line
|
|
23
|
+
- Doc comments: precede declarations, complete sentences starting with name
|
|
24
|
+
- `godoc` extracts documentation from comments
|
|
25
|
+
|
|
26
|
+
Example:
|
|
27
|
+
```go
|
|
28
|
+
// Package regexp implements a simple library for regular expressions.
|
|
29
|
+
package regexp
|
|
30
|
+
|
|
31
|
+
// Compile parses a regular expression and returns, if successful,
|
|
32
|
+
// a Regexp that can be used to match against text.
|
|
33
|
+
func Compile(str string) (*Regexp, error) {
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Names
|
|
37
|
+
|
|
38
|
+
### Package Names
|
|
39
|
+
|
|
40
|
+
- Short, concise, lowercase, single-word names
|
|
41
|
+
- No underscores or mixedCaps
|
|
42
|
+
- Name is the base name of its source directory
|
|
43
|
+
- Don't stutter: `bufio.Reader`, not `bufio.BufReader`
|
|
44
|
+
|
|
45
|
+
### Getters
|
|
46
|
+
|
|
47
|
+
- Don't use "Get" prefix
|
|
48
|
+
- `owner := obj.Owner()` not `obj.GetOwner()`
|
|
49
|
+
- Setters can use "Set": `obj.SetOwner(user)`
|
|
50
|
+
|
|
51
|
+
### Interface Names
|
|
52
|
+
|
|
53
|
+
- One-method interfaces: method name + "-er" suffix
|
|
54
|
+
- `Reader`, `Writer`, `Formatter`, `Notifier`
|
|
55
|
+
|
|
56
|
+
### MixedCaps
|
|
57
|
+
|
|
58
|
+
- Use `MixedCaps` or `mixedCaps` rather than underscores
|
|
59
|
+
- Exported: `MixedCaps` (capital first letter)
|
|
60
|
+
- Unexported: `mixedCaps` (lowercase first letter)
|
|
61
|
+
|
|
62
|
+
## Control Structures
|
|
63
|
+
|
|
64
|
+
### If
|
|
65
|
+
|
|
66
|
+
```go
|
|
67
|
+
// With initialization statement
|
|
68
|
+
if err := file.Chmod(0664); err != nil {
|
|
69
|
+
log.Print(err)
|
|
70
|
+
return err
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Avoid unnecessary else
|
|
74
|
+
if err != nil {
|
|
75
|
+
return err
|
|
76
|
+
}
|
|
77
|
+
// continue normal flow
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### For
|
|
81
|
+
|
|
82
|
+
```go
|
|
83
|
+
// Like C's for
|
|
84
|
+
for init; condition; post { }
|
|
85
|
+
|
|
86
|
+
// Like C's while
|
|
87
|
+
for condition { }
|
|
88
|
+
|
|
89
|
+
// Like C's for(;;)
|
|
90
|
+
for { }
|
|
91
|
+
|
|
92
|
+
// Range over slice
|
|
93
|
+
for key, value := range oldMap {
|
|
94
|
+
newMap[key] = value
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Range over string (runes)
|
|
98
|
+
for pos, char := range "日本語" {
|
|
99
|
+
fmt.Printf("character %c starts at byte position %d\n", char, pos)
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Switch
|
|
104
|
+
|
|
105
|
+
```go
|
|
106
|
+
// No automatic fallthrough
|
|
107
|
+
switch c {
|
|
108
|
+
case ' ', '?', '&', '=', '#', '+', '%':
|
|
109
|
+
return true
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Type switch
|
|
113
|
+
switch t := t.(type) {
|
|
114
|
+
case bool:
|
|
115
|
+
fmt.Printf("boolean %t\n", t)
|
|
116
|
+
case int:
|
|
117
|
+
fmt.Printf("integer %d\n", t)
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Functions
|
|
122
|
+
|
|
123
|
+
### Multiple Return Values
|
|
124
|
+
|
|
125
|
+
```go
|
|
126
|
+
func (file *File) Write(b []byte) (n int, err error)
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Named Result Parameters
|
|
130
|
+
|
|
131
|
+
```go
|
|
132
|
+
func ReadFull(r Reader, buf []byte) (n int, err error) {
|
|
133
|
+
for len(buf) > 0 && err == nil {
|
|
134
|
+
var nr int
|
|
135
|
+
nr, err = r.Read(buf)
|
|
136
|
+
n += nr
|
|
137
|
+
buf = buf[nr:]
|
|
138
|
+
}
|
|
139
|
+
return
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Defer
|
|
144
|
+
|
|
145
|
+
```go
|
|
146
|
+
func Contents(filename string) (string, error) {
|
|
147
|
+
f, err := os.Open(filename)
|
|
148
|
+
if err != nil {
|
|
149
|
+
return "", err
|
|
150
|
+
}
|
|
151
|
+
defer f.Close() // f.Close will run when we're finished.
|
|
152
|
+
// ...
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Data
|
|
157
|
+
|
|
158
|
+
### Allocation with new
|
|
159
|
+
|
|
160
|
+
`new(T)` allocates zeroed storage for a new item of type `T` and returns its address, a value of type `*T`.
|
|
161
|
+
|
|
162
|
+
```go
|
|
163
|
+
p := new(SyncedBuffer) // type *SyncedBuffer
|
|
164
|
+
var v SyncedBuffer // type SyncedBuffer
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Allocation with make
|
|
168
|
+
|
|
169
|
+
`make(T, args)` creates slices, maps, and channels only. It returns an initialized (not zeroed) value of type `T` (not `*T`).
|
|
170
|
+
|
|
171
|
+
```go
|
|
172
|
+
make([]int, 10, 100) // slice with len=10, cap=100
|
|
173
|
+
make(map[string]int) // map
|
|
174
|
+
make(chan int, 100) // buffered channel
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Arrays and Slices
|
|
178
|
+
|
|
179
|
+
```go
|
|
180
|
+
// Array - fixed size, value type
|
|
181
|
+
var a [10]int
|
|
182
|
+
|
|
183
|
+
// Slice - dynamic size, reference to array
|
|
184
|
+
s := make([]int, 10)
|
|
185
|
+
s = append(s, 1, 2, 3)
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### Maps
|
|
189
|
+
|
|
190
|
+
```go
|
|
191
|
+
m := make(map[string]int)
|
|
192
|
+
m["key"] = 42
|
|
193
|
+
|
|
194
|
+
// Comma ok idiom
|
|
195
|
+
if val, ok := m["key"]; ok {
|
|
196
|
+
// key exists
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
delete(m, "key")
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## Methods
|
|
203
|
+
|
|
204
|
+
### Pointer vs Value Receivers
|
|
205
|
+
|
|
206
|
+
```go
|
|
207
|
+
// Value receiver - operates on copy
|
|
208
|
+
func (s MyStruct) ValueMethod() { }
|
|
209
|
+
|
|
210
|
+
// Pointer receiver - can modify, avoids copy
|
|
211
|
+
func (s *MyStruct) PointerMethod() { }
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Rule: If any method needs a pointer receiver, all methods on that type should have pointer receivers.
|
|
215
|
+
|
|
216
|
+
## Interfaces
|
|
217
|
+
|
|
218
|
+
```go
|
|
219
|
+
type Reader interface {
|
|
220
|
+
Read(p []byte) (n int, err error)
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
type Writer interface {
|
|
224
|
+
Write(p []byte) (n int, err error)
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// Composition
|
|
228
|
+
type ReadWriter interface {
|
|
229
|
+
Reader
|
|
230
|
+
Writer
|
|
231
|
+
}
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## Embedding
|
|
235
|
+
|
|
236
|
+
```go
|
|
237
|
+
type ReadWriter struct {
|
|
238
|
+
*Reader // embedded
|
|
239
|
+
*Writer // embedded
|
|
240
|
+
}
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
## Concurrency
|
|
244
|
+
|
|
245
|
+
### Goroutines
|
|
246
|
+
|
|
247
|
+
```go
|
|
248
|
+
go list.Sort() // run list.Sort concurrently
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
### Channels
|
|
252
|
+
|
|
253
|
+
```go
|
|
254
|
+
ci := make(chan int) // unbuffered channel of integers
|
|
255
|
+
cj := make(chan int, 0) // unbuffered channel of integers
|
|
256
|
+
cs := make(chan *os.File, 100) // buffered channel of pointers to Files
|
|
257
|
+
|
|
258
|
+
c <- 1 // send
|
|
259
|
+
v := <-c // receive
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
### Select
|
|
263
|
+
|
|
264
|
+
```go
|
|
265
|
+
select {
|
|
266
|
+
case v := <-ch1:
|
|
267
|
+
fmt.Println("received from ch1:", v)
|
|
268
|
+
case ch2 <- 42:
|
|
269
|
+
fmt.Println("sent to ch2")
|
|
270
|
+
default:
|
|
271
|
+
fmt.Println("no communication")
|
|
272
|
+
}
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
## Errors
|
|
276
|
+
|
|
277
|
+
```go
|
|
278
|
+
type error interface {
|
|
279
|
+
Error() string
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// Creating errors
|
|
283
|
+
errors.New("message")
|
|
284
|
+
fmt.Errorf("operation failed: %w", err)
|
|
285
|
+
|
|
286
|
+
// Checking errors
|
|
287
|
+
if err != nil {
|
|
288
|
+
return err
|
|
289
|
+
}
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
## Panic and Recover
|
|
293
|
+
|
|
294
|
+
```go
|
|
295
|
+
func server(workChan <-chan *Work) {
|
|
296
|
+
for work := range workChan {
|
|
297
|
+
go safelyDo(work)
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
func safelyDo(work *Work) {
|
|
302
|
+
defer func() {
|
|
303
|
+
if err := recover(); err != nil {
|
|
304
|
+
log.Println("work failed:", err)
|
|
305
|
+
}
|
|
306
|
+
}()
|
|
307
|
+
do(work)
|
|
308
|
+
}
|
|
309
|
+
```
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
# Go Error Handling
|
|
2
|
+
|
|
3
|
+
> Reference for error handling patterns in Go
|
|
4
|
+
|
|
5
|
+
## Error Interface
|
|
6
|
+
|
|
7
|
+
```go
|
|
8
|
+
type error interface {
|
|
9
|
+
Error() string
|
|
10
|
+
}
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Errors are values. They can be stored, passed, and compared.
|
|
14
|
+
|
|
15
|
+
## Creating Errors
|
|
16
|
+
|
|
17
|
+
### Simple Errors
|
|
18
|
+
|
|
19
|
+
```go
|
|
20
|
+
import "errors"
|
|
21
|
+
|
|
22
|
+
err := errors.New("something went wrong")
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Formatted Errors
|
|
26
|
+
|
|
27
|
+
```go
|
|
28
|
+
import "fmt"
|
|
29
|
+
|
|
30
|
+
err := fmt.Errorf("failed to process %s: %v", filename, err)
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Custom Error Types
|
|
34
|
+
|
|
35
|
+
```go
|
|
36
|
+
type MyError struct {
|
|
37
|
+
Code int
|
|
38
|
+
Message string
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
func (e *MyError) Error() string {
|
|
42
|
+
return fmt.Sprintf("error %d: %s", e.Code, e.Message)
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Handling Errors
|
|
47
|
+
|
|
48
|
+
### Basic Pattern
|
|
49
|
+
|
|
50
|
+
```go
|
|
51
|
+
result, err := doSomething()
|
|
52
|
+
if err != nil {
|
|
53
|
+
return err
|
|
54
|
+
}
|
|
55
|
+
// use result
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Adding Context
|
|
59
|
+
|
|
60
|
+
```go
|
|
61
|
+
result, err := doSomething()
|
|
62
|
+
if err != nil {
|
|
63
|
+
return fmt.Errorf("doSomething failed: %w", err)
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Multiple Returns
|
|
68
|
+
|
|
69
|
+
```go
|
|
70
|
+
func divide(a, b float64) (float64, error) {
|
|
71
|
+
if b == 0 {
|
|
72
|
+
return 0, errors.New("division by zero")
|
|
73
|
+
}
|
|
74
|
+
return a / b, nil
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Error Wrapping (Go 1.13+)
|
|
79
|
+
|
|
80
|
+
### Wrapping Errors
|
|
81
|
+
|
|
82
|
+
```go
|
|
83
|
+
// Use %w verb to wrap
|
|
84
|
+
if err != nil {
|
|
85
|
+
return fmt.Errorf("operation failed: %w", err)
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Unwrapping Errors
|
|
90
|
+
|
|
91
|
+
```go
|
|
92
|
+
// errors.Unwrap returns the wrapped error
|
|
93
|
+
inner := errors.Unwrap(err)
|
|
94
|
+
|
|
95
|
+
// errors.Is checks if any error in chain matches
|
|
96
|
+
if errors.Is(err, os.ErrNotExist) {
|
|
97
|
+
// handle file not found
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// errors.As finds first error matching type
|
|
101
|
+
var pathErr *os.PathError
|
|
102
|
+
if errors.As(err, &pathErr) {
|
|
103
|
+
fmt.Println("failed path:", pathErr.Path)
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Sentinel Errors
|
|
108
|
+
|
|
109
|
+
```go
|
|
110
|
+
var (
|
|
111
|
+
ErrNotFound = errors.New("not found")
|
|
112
|
+
ErrUnauthorized = errors.New("unauthorized")
|
|
113
|
+
ErrInvalid = errors.New("invalid input")
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
func fetch(id string) (*Item, error) {
|
|
117
|
+
item, ok := store[id]
|
|
118
|
+
if !ok {
|
|
119
|
+
return nil, ErrNotFound
|
|
120
|
+
}
|
|
121
|
+
return item, nil
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Usage
|
|
125
|
+
item, err := fetch("123")
|
|
126
|
+
if errors.Is(err, ErrNotFound) {
|
|
127
|
+
// handle not found
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Error Handling Strategies
|
|
132
|
+
|
|
133
|
+
### Fail Fast
|
|
134
|
+
|
|
135
|
+
```go
|
|
136
|
+
func process() error {
|
|
137
|
+
if err := step1(); err != nil {
|
|
138
|
+
return err
|
|
139
|
+
}
|
|
140
|
+
if err := step2(); err != nil {
|
|
141
|
+
return err
|
|
142
|
+
}
|
|
143
|
+
return step3()
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Deferred Cleanup
|
|
148
|
+
|
|
149
|
+
```go
|
|
150
|
+
func processFile(path string) (err error) {
|
|
151
|
+
f, err := os.Open(path)
|
|
152
|
+
if err != nil {
|
|
153
|
+
return err
|
|
154
|
+
}
|
|
155
|
+
defer func() {
|
|
156
|
+
if cerr := f.Close(); cerr != nil && err == nil {
|
|
157
|
+
err = cerr
|
|
158
|
+
}
|
|
159
|
+
}()
|
|
160
|
+
// process file
|
|
161
|
+
return nil
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Error Aggregation
|
|
166
|
+
|
|
167
|
+
```go
|
|
168
|
+
type MultiError []error
|
|
169
|
+
|
|
170
|
+
func (m MultiError) Error() string {
|
|
171
|
+
var msgs []string
|
|
172
|
+
for _, err := range m {
|
|
173
|
+
msgs = append(msgs, err.Error())
|
|
174
|
+
}
|
|
175
|
+
return strings.Join(msgs, "; ")
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
func validateAll(items []Item) error {
|
|
179
|
+
var errs MultiError
|
|
180
|
+
for _, item := range items {
|
|
181
|
+
if err := validate(item); err != nil {
|
|
182
|
+
errs = append(errs, err)
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
if len(errs) > 0 {
|
|
186
|
+
return errs
|
|
187
|
+
}
|
|
188
|
+
return nil
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## Panic and Recover
|
|
193
|
+
|
|
194
|
+
### When to Panic
|
|
195
|
+
|
|
196
|
+
- Unrecoverable errors during initialization
|
|
197
|
+
- Programming errors (nil pointer, out of bounds)
|
|
198
|
+
- Violation of invariants
|
|
199
|
+
|
|
200
|
+
```go
|
|
201
|
+
func MustCompile(pattern string) *Regexp {
|
|
202
|
+
re, err := Compile(pattern)
|
|
203
|
+
if err != nil {
|
|
204
|
+
panic(err)
|
|
205
|
+
}
|
|
206
|
+
return re
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### Recovering from Panic
|
|
211
|
+
|
|
212
|
+
```go
|
|
213
|
+
func safeCall(fn func()) (err error) {
|
|
214
|
+
defer func() {
|
|
215
|
+
if r := recover(); r != nil {
|
|
216
|
+
err = fmt.Errorf("panic recovered: %v", r)
|
|
217
|
+
}
|
|
218
|
+
}()
|
|
219
|
+
fn()
|
|
220
|
+
return nil
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### Package Boundary Rule
|
|
225
|
+
|
|
226
|
+
- Convert panics to errors at package boundaries
|
|
227
|
+
- Don't let panics escape your API
|
|
228
|
+
|
|
229
|
+
```go
|
|
230
|
+
func (s *Server) handleRequest(w http.ResponseWriter, r *http.Request) {
|
|
231
|
+
defer func() {
|
|
232
|
+
if err := recover(); err != nil {
|
|
233
|
+
log.Printf("panic: %v\n%s", err, debug.Stack())
|
|
234
|
+
http.Error(w, "Internal Server Error", 500)
|
|
235
|
+
}
|
|
236
|
+
}()
|
|
237
|
+
// handle request
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## Best Practices
|
|
242
|
+
|
|
243
|
+
1. **Handle errors immediately** after the call
|
|
244
|
+
2. **Add context** when propagating errors
|
|
245
|
+
3. **Use error wrapping** with `%w` for error chains
|
|
246
|
+
4. **Define sentinel errors** for known conditions
|
|
247
|
+
5. **Don't ignore errors** (at minimum, log them)
|
|
248
|
+
6. **Prefer errors over panics** in library code
|
|
249
|
+
7. **Document error returns** in function comments
|
|
250
|
+
8. **Test error paths** as thoroughly as success paths
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Golang Guide
|
|
2
|
+
|
|
3
|
+
metadata:
|
|
4
|
+
name: golang
|
|
5
|
+
description: Go language reference documentation
|
|
6
|
+
|
|
7
|
+
source:
|
|
8
|
+
type: external
|
|
9
|
+
origin: go.dev
|
|
10
|
+
url: https://go.dev/doc/effective_go
|
|
11
|
+
last_fetched: "2026-01-22"
|
|
12
|
+
|
|
13
|
+
documents:
|
|
14
|
+
- name: effective-go
|
|
15
|
+
path: ./effective-go.md
|
|
16
|
+
description: Effective Go - official best practices guide
|
|
17
|
+
|
|
18
|
+
- name: concurrency
|
|
19
|
+
path: ./concurrency.md
|
|
20
|
+
description: Concurrency patterns and practices
|
|
21
|
+
|
|
22
|
+
- name: error-handling
|
|
23
|
+
path: ./error-handling.md
|
|
24
|
+
description: Error handling patterns
|
|
25
|
+
|
|
26
|
+
used_by:
|
|
27
|
+
- golang-expert
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# Baekgom Agents - Guides Index
|
|
2
|
+
|
|
3
|
+
guides:
|
|
4
|
+
# Internal
|
|
5
|
+
- name: claude-code
|
|
6
|
+
description: Claude Code and agent development guide
|
|
7
|
+
path: ./claude-code/
|
|
8
|
+
source:
|
|
9
|
+
type: internal
|
|
10
|
+
|
|
11
|
+
# Frontend
|
|
12
|
+
- name: web-design
|
|
13
|
+
description: Web design best practices and accessibility reference
|
|
14
|
+
path: ./web-design/
|
|
15
|
+
source:
|
|
16
|
+
type: external
|
|
17
|
+
origin: github
|
|
18
|
+
url: https://github.com/vercel-labs/agent-skills
|
|
19
|
+
|
|
20
|
+
# Languages
|
|
21
|
+
- name: golang
|
|
22
|
+
description: Go language reference from Effective Go
|
|
23
|
+
path: ./golang/
|
|
24
|
+
source:
|
|
25
|
+
type: external
|
|
26
|
+
origin: go.dev
|
|
27
|
+
url: https://go.dev/doc/effective_go
|
|
28
|
+
|
|
29
|
+
- name: python
|
|
30
|
+
description: Python reference from PEP 8 and PEP 20
|
|
31
|
+
path: ./python/
|
|
32
|
+
source:
|
|
33
|
+
type: external
|
|
34
|
+
origin: python.org
|
|
35
|
+
url: https://peps.python.org/pep-0008/
|
|
36
|
+
|
|
37
|
+
- name: rust
|
|
38
|
+
description: Rust reference from The Book and API Guidelines
|
|
39
|
+
path: ./rust/
|
|
40
|
+
source:
|
|
41
|
+
type: external
|
|
42
|
+
origin: rust-lang.org
|
|
43
|
+
url: https://doc.rust-lang.org/book/
|
|
44
|
+
|
|
45
|
+
- name: kotlin
|
|
46
|
+
description: Kotlin reference from JetBrains documentation
|
|
47
|
+
path: ./kotlin/
|
|
48
|
+
source:
|
|
49
|
+
type: external
|
|
50
|
+
origin: kotlinlang.org
|
|
51
|
+
url: https://kotlinlang.org/docs/coding-conventions.html
|
|
52
|
+
|
|
53
|
+
- name: typescript
|
|
54
|
+
description: TypeScript reference from official handbook
|
|
55
|
+
path: ./typescript/
|
|
56
|
+
source:
|
|
57
|
+
type: external
|
|
58
|
+
origin: typescriptlang.org
|
|
59
|
+
url: https://www.typescriptlang.org/docs/handbook/
|
|
60
|
+
|
|
61
|
+
# Backend
|
|
62
|
+
- name: fastapi
|
|
63
|
+
description: FastAPI framework reference
|
|
64
|
+
path: ./fastapi/
|
|
65
|
+
source:
|
|
66
|
+
type: external
|
|
67
|
+
origin: fastapi.tiangolo.com
|
|
68
|
+
url: https://fastapi.tiangolo.com/
|
|
69
|
+
|
|
70
|
+
- name: springboot
|
|
71
|
+
description: Spring Boot framework reference
|
|
72
|
+
path: ./springboot/
|
|
73
|
+
source:
|
|
74
|
+
type: external
|
|
75
|
+
origin: spring.io
|
|
76
|
+
url: https://docs.spring.io/spring-boot/docs/current/reference/html/
|
|
77
|
+
|
|
78
|
+
- name: go-backend
|
|
79
|
+
description: Go backend development patterns
|
|
80
|
+
path: ./go-backend/
|
|
81
|
+
source:
|
|
82
|
+
type: external
|
|
83
|
+
origin: various
|
|
84
|
+
url: https://github.com/golang-standards/project-layout
|
|
85
|
+
|
|
86
|
+
# Infrastructure
|
|
87
|
+
- name: docker
|
|
88
|
+
description: Docker containerization reference
|
|
89
|
+
path: ./docker/
|
|
90
|
+
source:
|
|
91
|
+
type: external
|
|
92
|
+
origin: docker.com
|
|
93
|
+
url: https://docs.docker.com/
|
|
94
|
+
|
|
95
|
+
- name: aws
|
|
96
|
+
description: AWS cloud architecture reference
|
|
97
|
+
path: ./aws/
|
|
98
|
+
source:
|
|
99
|
+
type: external
|
|
100
|
+
origin: aws.amazon.com
|
|
101
|
+
url: https://docs.aws.amazon.com/wellarchitected/
|