go-personal-convention

Enforce Go conventions for error wrapping, boolean naming, and enum-like string types.

Updated Mar 25, 2020
One-click install
npx skills add https://github.com/daominah/gostructure --skill go-personal-convention
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: go-personal-convention
Source: https://github.com/daominah/gostructure/tree/main/.claude/skills/go-personal-convention
Command: npx skills add https://github.com/daominah/gostructure --skill go-personal-convention

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This guide removes ambiguity and inconsistency in Go code by prescribing straightforward conventions for error formatting, boolean naming, and enum-like fields so code reviews and maintenance become faster and less error-prone.

Core Features & Use Cases

  • Error wrapping and context: Encourage using fmt.Errorf with %w and including a brief description of the failing operation so logs show which call produced the error.
  • Boolean naming: Require boolean variables and struct fields to be prefixed with Is for exported or is for unexported identifiers to make intent explicit.
  • Enum-like string types: Define named string types with constant values, store them as TEXT in the database, and prefer human-readable UPPERCASE values to avoid brittle schema migrations.
  • Use Case: Apply these rules when authoring or reviewing service code, libraries, and database models to improve readability and simplify debugging.

Quick Start

Ask the assistant to review a Go source file and suggest changes to use fmt.Errorf with %w for error returns, rename boolean fields to Is/is prefixes, and convert fixed-value fields into named string types with uppercase constant values.

Frequently Asked Questions about go-personal-convention

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I wrap errors in Go to keep context for logging?

To wrap errors in Go, use fmt.Errorf with the %w verb to preserve the original error while adding a brief description of the failing operation. This ensures logs show exactly which call produced the error during debugging.

What is the naming convention for boolean variables in Go services?

The naming convention for boolean variables in Go requires prefixing exported identifiers with Is and unexported identifiers with is. This makes intent explicit and improves readability across service code and struct fields.

How to handle enum-like values in Go without brittle database migrations?

To handle enum-like values in Go, define named string types with constant values and store them as TEXT in the database. Prefer human-readable UPPERCASE values to avoid brittle schema migrations and simplify debugging.

Can I use this convention to review Go source files for naming and error handling?

Yes, you can review Go source files using this convention by asking the assistant to suggest changes for fmt.Errorf wrapping, Is/is boolean prefixes, and string type enums. It standardizes error context, naming, and limited-value fields.

Does Go support custom string types for fixed-value struct fields?

Yes, Go supports custom string types for fixed-value struct fields. By defining named string types with uppercase constant values, you can represent limited-value fields clearly and store them as TEXT in database models.

Why use %w for error wrapping instead of standard error formatting in Go?

Use %w for error wrapping in Go instead of standard formatting to preserve the error chain. Wrapping with fmt.Errorf and %w keeps the original error intact while appending operational context, which simplifies debugging and logging.