Loading...
Loading...
Go coding standards and style conventions grounded in Effective Go, Go Code Review Comments, and production-proven idioms. Use when writing or reviewing Go code, enforcing naming conventions, import ordering, variable declarations, struct initialization, or formatting rules. Trigger examples: "check Go style", "fix formatting", "review naming", "Go conventions". Do NOT use for architecture decisions, concurrency patterns, or performance tuning — use go-architecture-review, go-concurrency-review, or go-performance-review instead.
npx skill4agent add eduardo-sl/go-agent-skills go-coding-standardsgoimportsgolintgo vetimport (
// 1. Standard library
"context"
"fmt"
"net/http"
// 2. External packages
"github.com/gorilla/mux"
"go.uber.org/zap"
// 3. Internal/project packages
"github.com/myorg/myproject/internal/service"
)utilcommonhelpersmiscbaseName()GetName()SetName()NewFoo()*FooNew()inerrctxuserCountretryTimeout_var _defaultTimeout = 5 * time.Seconderrorlencapnewmakeclose-erReaderWriterCloservar// ✅ Good
var _defaultPort = 8080
var _logger = zap.NewNop()
// ❌ Bad — redundant type
var _defaultPort int = 8080:=var// ✅ Good — zero value is meaningful
var buf bytes.Buffer
// ✅ Good — short declaration
name := getUserName()// ✅ Good
user := User{
Name: "Alice",
Email: "alice@example.com",
Age: 30,
}
// ❌ Bad — positional, breaks on field reordering
user := User{"Alice", "alice@example.com", 30}// ✅ Good — zero values omitted
user := User{
Name: "Alice",
}// ✅ Good — early return
func process(data []Item) error {
for _, v := range data {
if !v.IsValid() {
log.Printf("invalid item: %v", v)
continue
}
if err := v.Process(); err != nil {
return err
}
v.Send()
}
return nil
}else// ✅ Good
a := 10
if condition {
a = 20
}
// ❌ Bad
var a int
if condition {
a = 20
} else {
a = 10
}const (
_defaultPort = 8080
_defaultTimeout = 30 * time.Second
)
var (
_validTypes = map[string]bool{"json": true, "xml": true}
_defaultUser = User{Name: "guest"}
)New()func (s *Store) CreateUser(
ctx context.Context,
name string,
email string,
opts ...CreateOption,
) (*User, error) {defermu.Lock()
defer mu.Unlock()
f, err := os.Open(path)
if err != nil {
return err
}
defer f.Close()type Status int
const (
StatusUnknown Status = iota
StatusActive
StatusInactive
)timetime.Durationtime.Timetime.Since(start)time.Now().Sub(start)intfloat64// ✅ Good
func poll(interval time.Duration) { ... }
poll(10 * time.Second)
// ❌ Bad
func poll(intervalSecs int) { ... }
poll(10)goimportsgo vet ./...golangci-lint run