golang-naming

Applies Go naming conventions to packages, identifiers, errors, enums, and tests.

1|Updated May 25, 2020
One-click install
npx skills add https://github.com/titaneric/dotfiles --skill golang-naming-titaneric
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-naming
Source: https://github.com/titaneric/dotfiles/tree/main/dot_agents/skills/golang-naming
Command: npx skills add https://github.com/titaneric/dotfiles --skill golang-naming-titaneric

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Go codebases often accumulate inconsistent or non-idiomatic names — stuttering constructors like NewClient, ALL_CAPS constants, Get-prefixed getters, or generic util packages — that hurt readability and violate community conventions. This Skill provides the complete set of Go naming rules so new code, reviews, and refactors follow idiomatic MixedCaps conventions consistently. ## Core Features & Use Cases - Comprehensive naming rules: Covers packages, files, constructors, structs, interfaces, constants, enums, errors, booleans, receivers, getters/setters, functional options, acronyms, and test names with correct and incorrect examples. - Frequently missed conventions: Highlights subtle rules like New() vs NewTypeName(), is/has prefixes on boolean fields, fully lowercase error strings including acronyms, and zero-value Unknown sentinels for iota enums. - Common mistakes table: Maps over 20 anti-patterns (snake_case, type-in-name variables, import alias abuse, inconsistent concept names) to their idiomatic fixes. - Use Case: When writing a new Go package like dbpool, use this Skill to name the constructor New() instead of NewPool(), define StatusUnknown at iota 0, and write sentinel errors as "dbpool: pool exhausted". ## Quick Start Ask the agent to review the naming in your Go file or generate a new package following Go naming conventions.

Frequently Asked Questions about golang-naming

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

FAQPage Schema
How should I name a Go constructor function?

Name the constructor New() when the package exports a single primary type, so callers write apiclient.New(). Use NewTypeName() only when the package has multiple constructible types, like http.NewRequest and http.NewServeMux.

Should Go getters use the Get prefix?

Go getters omit the Get prefix, so user.Name() instead of user.GetName(). Boolean predicates are the exception and keep Is/Has/Can prefixes, such as IsHealthy() bool, following standard library patterns like net.IP.IsLoopback().

Why must Go error strings be lowercase including acronyms?

Error strings are often wrapped with fmt.Errorf and appear mid-sentence, so they must be fully lowercase with no trailing punctuation. Acronyms like ID and URL become lowercase too: write "invalid message id", not "invalid message ID".

What is wrong with naming a Go package utils or helpers?

Generic names like util, helper, common, or base communicate nothing about the package's purpose and cause import collisions. Use specific singular lowercase names that describe the abstraction, such as email, currency, or jsonfile.

How do I define enum values with iota in Go safely?

Prefix enum values with the type name, like StatusReady, and protect the zero value by placing an Unknown sentinel at iota 0 or starting at iota+1. Otherwise an uninitialized variable silently maps to a real state like StatusReady.

When should I use import aliases in Go?

Use import aliases only to resolve name collisions, such as mrand for math/rand alongside crypto/rand. Aliasing for readability or brevity adds cognitive load without resolving any collision and should be avoided.