golang-code-style

Apply human-judgment style conventions to writing and reviewing Go code.

2|Updated Mar 13, 2023
One-click install
npx skills add https://github.com/haipham22/golang-sample --skill golang-code-style-haipham22
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: golang-code-style
Source: https://github.com/haipham22/golang-sample/tree/main/.agents/skills/golang-code-style
Command: npx skills add https://github.com/haipham22/golang-sample --skill golang-code-style-haipham22

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps you write and review Go code for clarity, consistency, and maintainability when formatting alone is not enough.

Core Features & Use Cases

  • Line Breaking and Readability: Break long calls and signatures at meaningful boundaries so code stays easy to scan and diff.
  • Control Flow Clarity: Prefer early returns, remove unnecessary else branches, use switch for repeated comparisons, and extract complex conditions into named booleans.
  • Function and Data Design: Keep functions focused, limit parameter counts, initialize slices and maps explicitly, use named struct fields, and choose value or pointer parameters appropriately.
  • Code Organization: Group related declarations, keep helpers unexported when they are internal, and structure files to make intent obvious.
  • Use Case: Review a Go service, API handler, or library file and rewrite it into a cleaner, more idiomatic form that is easier for teammates to understand and maintain.

Quick Start

Use the golang-code-style skill to review the attached Go code for clarity, control flow, collection initialization, and line breaking.

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 for code review?▼

Improve Go code readability by applying human-judgment style conventions that go beyond standard formatting. The Skill enforces early returns, named booleans for complex conditions, and breaks long function calls at meaningful semantic boundaries for easier scanning and diffing.

What is the best way to structure control flow in Golang?▼

The best way to structure Golang control flow is to prefer early returns, eliminate unnecessary else branches, use switch statements for repeated comparisons, and extract complex conditional logic into clearly named boolean variables for maintainability.

How do I format long Go function signatures and calls?▼

Format long Go function signatures and calls by breaking them at semantic boundaries. This approach keeps multi-line function calls grouped logically, ensuring the code remains easy to scan and diff during reviews.

Should I initialize empty slices and maps explicitly in Go?▼

Yes, you should initialize empty slices and maps explicitly in Go. This Skill requires explicit initialization and the use of named struct literals to make data structures and function parameter intent obvious to teammates.

When should I use pointer vs value parameters in Go functions?▼

Choose pointer or value parameters in Go functions appropriately based on function design. This Skill checks that you keep functions focused, limit parameter counts, and select pointer usage to balance performance and clarity across your service or library.

Does this Skill fix code style issues that gofmt does not cover?▼

Yes, this Skill fixes code style issues that gofmt does not cover. It applies human-judgment conventions to variable declarations, control flow, file organization, and line breaking to standardize Go code when formatting alone is insufficient.