golang-base-practices

Go language best practices guide covering frameworks (Gin/Go-Kratos), ORM (GORM), database migrations (Goose), DDD project structure, error handling, concurrency patterns, testing (99% coverage target), and Lint tools. This skill should be used when writing, reviewing, or refactoring Go code to ensure best practices are followed. Triggers on Go project development, code review, performance optimization, or architecture design.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "golang-base-practices" with this command: npx skills add cexll/golang-base-practices-skills/cexll-golang-base-practices-skills-golang-base-practices

Golang Base Practices

Comprehensive Go development best practices guide, organized by priority for code generation, review, and refactoring. Contains 53 rules referenced from Effective Go, Google Go Style Guide, Uber Go Style Guide, and Go Code Review Comments.

When to Apply

Reference these guidelines when:

  • Creating new Go projects or microservices
  • Building API interfaces (REST/gRPC)
  • Performing database operations and migrations
  • Conducting code reviews and refactoring
  • Optimizing performance and concurrency
  • Improving test coverage

Rule Categories by Priority

PriorityCategoryImpactPrefix
1Framework SelectionCRITICALframework-
2Database & ORMCRITICALdb-
3DDD Project StructureHIGHddd-
4Error HandlingHIGHerror-
5Concurrency PatternsHIGHconcurrency-
6Idiomatic GoMEDIUMidiomatic-
7Testing PracticesCRITICALtesting-
8Performance OptimizationMEDIUMperformance-
9Lint & ToolchainMEDIUMlint-

Quick Reference

1. Framework Selection (CRITICAL)

  • framework-gin-simple - Use Gin for simple projects
  • framework-kratos-complex - Use Go-Kratos for complex microservices
  • framework-middleware - Middleware design patterns
  • framework-graceful-shutdown - Graceful server shutdown

2. Database & ORM (CRITICAL)

  • db-gorm-setup - GORM initialization and configuration
  • db-gorm-hooks - GORM Hook usage guidelines
  • db-gorm-transactions - Transaction handling patterns
  • db-goose-migrations - Database migrations with Goose
  • db-connection-pool - Connection pool configuration

3. DDD Project Structure (HIGH)

  • ddd-project-layout - Standard project directory structure
  • ddd-domain-layer - Domain layer design
  • ddd-application-layer - Application layer design
  • ddd-infrastructure-layer - Infrastructure layer design
  • ddd-interface-layer - Interface layer design
  • ddd-dependency-injection - Dependency injection patterns

4. Error Handling (HIGH)

  • error-wrap-context - Error wrapping with context
  • error-sentinel - Sentinel error definitions
  • error-custom-types - Custom error types
  • error-handling-check - Always check error returns
  • error-api-response - API error response standards
  • error-panic-recover - Panic and recover usage guidelines

5. Concurrency Patterns (HIGH)

  • concurrency-goroutine-lifecycle - Goroutine lifecycle management
  • concurrency-channel-patterns - Channel usage patterns
  • concurrency-channel-size - Channel buffer size selection
  • concurrency-context-cancel - Context cancellation propagation
  • concurrency-errgroup - errgroup concurrency control
  • concurrency-sync-primitives - sync package primitives usage
  • concurrency-race-detection - Race condition detection

6. Idiomatic Go (MEDIUM)

  • idiomatic-naming - Naming conventions
  • idiomatic-comment - Doc Comments guidelines
  • idiomatic-interface - Interface design (prefer small interfaces)
  • idiomatic-receiver - Receiver naming and selection
  • idiomatic-struct-init - Struct initialization
  • idiomatic-functional-options - Functional options pattern
  • idiomatic-defer - defer usage guidelines
  • idiomatic-slice-map - Slice and Map operations
  • idiomatic-zero-value - Zero value utilization
  • idiomatic-embedding - Type embedding
  • idiomatic-blank-identifier - Blank identifier usage

7. Testing Practices (CRITICAL)

  • testing-coverage-99 - 99% test coverage target
  • testing-table-driven - Table-driven tests
  • testing-mock - Mocking and interface abstraction
  • testing-helper - Test helper function guidelines
  • testing-benchmark - Benchmark testing
  • testing-integration - Integration testing standards
  • testing-testify - testify assertion library usage

8. Performance Optimization (MEDIUM)

  • performance-strconv - Use strconv instead of fmt
  • performance-prealloc - Container preallocation

9. Lint & Toolchain (MEDIUM)

  • lint-golangci - golangci-lint configuration
  • lint-gofmt - Code formatting
  • lint-govet - Static analysis
  • lint-staticcheck - Advanced static checking
  • lint-revive - Customizable linter

How to Use

Consult specific rule files in the rules/ directory for detailed explanations and code examples:

rules/framework-gin-simple.md
rules/db-gorm-setup.md
rules/testing-table-driven.md

Each rule file contains:

  • Rule explanation and importance
  • Incorrect example with analysis
  • Correct example with explanation
  • Additional context and references

Core Principles

  1. KISS - Keep it simple, avoid over-engineering
  2. YAGNI - Only implement what is currently needed
  3. Explicit over Implicit - Code intent should be clear
  4. Handle All Errors - Never ignore error returns
  5. 99% Test Coverage - Foundation for high-quality code

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Coding

codeagent

No summary provided by upstream source.

Repository SourceNeeds Review
127-cexll
Coding

dev

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

codex

No summary provided by upstream source.

Repository SourceNeeds Review
General

product-requirements

No summary provided by upstream source.

Repository SourceNeeds Review
409-cexll