| name | developing-go-code |
| description | Provides Go development standards and best practices for the gopipe codebase.
Apply when writing or reviewing Go code: testing patterns, godoc, error handling,
API conventions, and common anti-patterns to avoid.
|
| user-invocable | false |
Developing Go Code
Build Commands
make test
make build
make vet
make check
API Conventions
| Context | Pattern | Example |
|---|
| Constructors | Config struct | NewEngine(EngineConfig{}) |
| Methods | Direct parameters | AddHandler("name", matcher, h) |
| Optional filtering | nil = match all | AddOutput("out", nil) |
Godoc Standards
First sentence starts with the function name and describes what it does. Include a usage example for non-trivial functions:
func GroupBy[K comparable, V any](...) <-chan Group[K, V]
Testing
- Table-driven tests preferred
- Use
t.Parallel() where safe
- Test both success and error paths
- Mock external dependencies
- Run with
-race flag: go test -race ./...
Error Handling
- Return errors, don't panic (except in
Must* functions)
- Wrap with context:
fmt.Errorf("operation: %w", err)
- Check errors immediately after call
Common Mistakes to Avoid
Using channel.Process for filtering
channel.Process(in, func(msg) []*Message {
if match { return []*Message{msg} }
return nil
})
channel.Filter(in, func(msg) bool {
if matcher.Match(msg) { return true }
errorHandler(msg, ErrRejected)
return false
})
Creating components in Start()
func (e *Engine) Start() {
e.distributor = NewDistributor()
}
func NewEngine() *Engine {
return &Engine{distributor: NewDistributor()}
}
Handler.Name() method
Handler should NOT own its name — name is a wiring concern:
type Handler interface { Name() string }
engine.AddHandler("process-orders", matcher, handler)
Copy() sharing Attributes map
return &Message{Attributes: msg.Attributes}
return &Message{Attributes: maps.Clone(msg.Attributes)}
Reference Procedures
- @../docs/procedures/go.md — full Go standards, deprecation, error handling
- @../AGENTS.md — architecture decisions, common mistakes, naming decisions