Instruction file imported from TakMczk/copilot-cli-ecc (
.github/instructions/golang.instructions.md). Copyright stays with the author.
Source: coding-style.md
Go Coding Style
Formatting
- gofmt and goimports are mandatory — no style debates
Design Principles
- Accept interfaces, return structs
- Keep interfaces small (1-3 methods)
Error Handling
Always wrap errors with context:
if err != nil {
return fmt.Errorf("failed to create user: %w", err)
}
Reference
See skill: golang-patterns for comprehensive Go idioms and patterns.
Source: patterns.md
Go Patterns
Functional Options
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
}
Small Interfaces
Define interfaces where they are used, not where they are implemented.
Dependency Injection
Use constructor functions to inject dependencies:
func NewUserService(repo UserRepository, logger Logger) *UserService {
return &UserService{repo: repo, logger: logger}
}
Reference
See skill: golang-patterns for comprehensive Go patterns including concurrency, error handling, and package organization.
Source: security.md
Go Security
Secret Management
apiKey := os.Getenv("OPENAI_API_KEY")
if apiKey == "" {
log.Fatal("OPENAI_API_KEY not configured")
}
Security Scanning
- Use gosec for static security analysis:
gosec ./...
Context & Timeouts
Always use context.Context for timeout control:
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
Source: testing.md
Go Testing
Framework
Use the standard go test with table-driven tests.
Race Detection
Always run with the -race flag:
go test -race ./...
Coverage
go test -cover ./...
Reference
See skill: golang-testing for detailed Go testing patterns and helpers.