一键导入
go
Idiomatic Go 1.25 practices: errors, interfaces, concurrency, generics, testing, security, tooling. Use when writing or reviewing Go code.
菜单
Idiomatic Go 1.25 practices: errors, interfaces, concurrency, generics, testing, security, tooling. Use when writing or reviewing Go code.
Docker best practices: image security, build efficiency, runtime hardening, Compose, local tooling (Colima, OrbStack). Use when writing or reviewing Dockerfiles and Compose files.
AWS best practices: IAM, secrets, networking, security, compute, IaC, ops. Use when building, reviewing, or modifying AWS resources.
GCP best practices: IAM, secrets, networking, security, compute, IaC, ops. Use when building, reviewing, or modifying GCP resources.
Modern Java practices: design, errors, concurrency, security, testing, tooling. Targets Java 21 LTS baseline; Java 25 LTS features called out explicitly. Use when writing or reviewing Java code.
Behavioral guidelines to reduce common LLM coding mistakes. Use when writing, reviewing, or refactoring code to avoid overcomplication, make surgical changes, surface assumptions, and define verifiable success criteria.
Kubernetes best practices: security, workloads, networking, config, operations, GitOps. Use when writing or reviewing K8s manifests and configurations.
| name | go |
| description | Idiomatic Go 1.25 practices: errors, interfaces, concurrency, generics, testing, security, tooling. Use when writing or reviewing Go code. |
go.mod at repo root. Module path matches repo URL: module github.com/org/repogo.mod: go 1.25. Toolchain auto-selects via toolchain directivego.mod tool directives (1.24+). go get -tool golang.org/x/tools/cmd/stringercmd/ for binaries, internal/ for private packages, pkg/ only if genuinely publicinternal/ enforces package boundariesgo.sum committed. Never manually editederror as last return valuefmt.Errorf("op failed: %w", err). Always %w, not %v, when caller may inspectvar ErrNotFound = errors.New("not found"). Use errors.Is to check, not ==Error() string. Use errors.As to extract_ = f() only with explicit justification in commentpanic in library code. Reserve for truly unrecoverable states in mainio.Reader, io.Writerinterface{} → any (Go 1.18+). Use any everywheretype ReadWriter interface { Reader; Writer }[T int | int64] over [T any] when type matterscomparable constraint for map keys and equality checksgolang.org/x/exp/slices and maps patterns now in stdlib (slices, maps packages, 1.21+)iter.Seq and iter.Seq2 for custom iterablestype Set[T comparable] = map[T]struct{}sync for shared statecontext.Context as first arg to every blocking or long-running function. Respect cancellationselect with ctx.Done() in every goroutine that blocks on channel or I/Osync.WaitGroup to wait for goroutine group. errgroup.Group when any error should cancel allsync.Mutex over channels for protecting shared state. Embed mutex with the data it protectsgo test -race ./...goleak in tests for long-running servicescontext.Background() at program entry only (main, top-level server handler, test root)ctx, cancel := context.WithTimeout(...); defer cancel()context.WithValue only for request-scoped metadata (trace ID, auth token). Not for optional function params. Key type must be unexported to avoid collisionsnet/http: always set ReadTimeout, WriteTimeout, IdleTimeout on http.Server. No default serverdefer resp.Body.Close() immediately after nil error checkhttp.NewRequestWithContext — never http.NewRequest in production codenet/url for URL construction, not string concattls.Config with MinVersion: tls.VersionTLS12. Prefer TLS 1.3crypto/rand for all random tokens, IDs, secrets. Never math/randbcrypt or argon2. Never sha256 or md5 for passwordshtml/template bypass (template.HTML, template.JS). Auto-escaping is the pointos/exec: never pass user input directly to shell. Use arg list form, not string formfilepath.Clean and filepath.Join for all path construction. Validate result stays within allowed rootgovulncheck ./... in CI. Scans modules and call graph for known CVEst.Run per caset.Parallel() in all unit tests that don't share mutable statetestify/assert or stdlib cmp for assertions. Avoid rolling custom diff logict.TempDir() for temp files — auto-cleaned. Never os.TempDir() directly in testsfunc FuzzX(f *testing.F)) for parsers, decoders, untrusted input handlersfunc BenchmarkX(b *testing.B)) for hot paths. Run with -benchmemhttptest.NewRecorder and httptest.NewServer for HTTP handler tests. No real network in unit testsgo test -cover ./.... Track but don't cargo-cult 100%//go:build integrationgofmt or goimports on save. No style debatesgolangci-lint with at minimum errcheck, govet, staticcheck, gosec enabledgo vet ./... in CI. Catches real bugs, not stylegovulncheck ./... in CI for supply chain securitygo mod tidy before every commit. Keeps go.sum cleango build -trimpath for reproducible builds. Removes local paths from binariesGOOS=linux GOARCH=amd64 go build. Test on target arch in CIgo tool pprof for CPU/memory profiling. net/http/pprof endpoint in long-running services (behind auth)make([]T, 0, n), make(map[K]V, n)go test -benchmemsync.Pool for frequently allocated short-lived objects (e.g. buffers)strings.Builder for loops. Never += string concat in loopsio.Reader/io.Writer chains over loading full content into memorypprof before any micro-optimization