Instruction file imported from ruaan-deysel/unraid-management-agent (
.github/instructions/go.instructions.md). Copyright stays with the author.
Go Code Conventions
Reference: AGENTS.md for full project context.
Style
- Standard Go:
gofmtandgoimportsenforced - Zero tolerance for linting errors (
golangci-lint) - PascalCase for exported names, camelCase for unexported
- Group imports: stdlib, external, internal (separated by blank lines)
Error Handling
- Always wrap errors with context:
fmt.Errorf("doing X: %w", err) - Return errors up the call stack; don't swallow them silently
- Use
errors.Is()/errors.As()for error checking - Log at the point of handling, not at every intermediate return
Context Propagation
- Pass
context.Contextas the first parameter to functions that need it - Respect
ctx.Done()in goroutines for graceful shutdown - Never store context in a struct
Security
- Use
lib.ExecCommand()/lib.ExecCommandOutput()for shell commands — neverexec.Command - Validate all user input with
lib.Validate*()functions fromdaemon/lib/validation.go - No secrets in code; no hardcoded credentials
Concurrency
- Use
sync.RWMutexfor shared cache:RLock/RUnlockfor reads,Lock/Unlockfor writes - All goroutines must support context cancellation
- Collectors must wrap work in defer/recover for panic recovery