golang-code-style

Enforce Go code clarity conventions for formatting, control flow, and declarations.

Updated May 28, 2026
One-click install
npx skills add https://github.com/vanstinator/semantic-search --skill golang-code-style-vanstinator
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-code-style
Source: https://github.com/vanstinator/semantic-search/tree/main/.agents/skills/golang-code-style
Command: npx skills add https://github.com/vanstinator/semantic-search --skill golang-code-style-vanstinator

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Golang code style guidance often gets inconsistent across teams, causing readability issues, review friction, and subtle behavior bugs. This skill provides concrete, judgment-aware conventions for writing and reviewing Go code with consistent clarity.

Core Features & Use Cases

  • Line breaking and readability: Break long calls and signatures at semantic boundaries so intent stays visible.
  • Intent-signaling variable declarations: Prefer := for non-zero values and var for zero-value initialization to communicate meaning.
  • Safe empty collections and composite literals: Initialize slices/maps to non-nil values and use named fields in struct literals to avoid brittle code.
  • Cleaner control flow: Use early returns, avoid unnecessary else, and prefer switch over multi-branch if-else chains.
  • Function design and organization: Keep functions focused, constrain parameter count, and structure declarations within files for maintainable diffs.

Quick Start

Ask the agent to apply golang-code-style to the Go file you provide and explain any changes it makes.

Frequently Asked Questions about golang-code-style

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

FAQPage Schema
How do I improve Go code readability and consistency beyond what linters check?

To improve Go code readability, apply judgment-aware conventions for semantic line breaking, intent-signaling var versus colon-equals declarations, and named struct fields. These clarity rules target maintainable outcomes that automated linters often miss during code reviews.

What is the best way to format long function signatures and struct literals in Golang?

The best way to format long Golang calls and struct literals is breaking them at semantic boundaries. Using named fields in struct literals and aligning arguments at intent-signaling boundaries keeps code meaning visible and prevents brittle composite literal declarations.

Should I use var or colon-equals for variable declarations in Go?

Use colon-equals for non-zero value assignments and var for zero-value initialization in Go. This intent-signaling declaration style communicates whether a variable is deliberately left empty or actively assigned, improving code clarity for future reviewers.

How do I refactor control flow in Golang to reduce nested if-else chains?

Refactor Golang control flow by using early returns to eliminate unnecessary else blocks and preferring switch statements over multi-branch if-else chains. This approach flattens logic, reduces nesting, and makes function intent easier to follow during reviews.

Why do my Go slices and maps return nil instead of empty after initialization?

Go slices and maps return nil when initialized with var instead of a composite literal. Initialize empty collections to non-nil values using make or literal syntax to avoid subtle behavior bugs when checking length or returning empty collections from functions.

Can I use this Golang code style skill for team-wide standard enforcement?

Yes, you can use this Golang code style skill for team-wide standard enforcement. It provides concrete conventions for function design, parameter count constraints, and declaration organization, making it suitable for producing review-ready diffs and consistent codebases.