
Go
- 2 installs
- 8 repo stars
- Updated February 25, 2026
- testdino-hq/google-styleguides-skills
Applies Google's official Go style guide for formatting, naming, error handling, and idiomatic package organization.
About
Google's official Go style guide covering gofmt formatting, naming, error handling, interfaces, and concurrency. A developer uses it to write and review idiomatic, maintainable Go code.
- Google's official Go style guide: gofmt, naming, error handling
- Idiomatic patterns for interfaces, concurrency, and package organization
Go by the numbers
- 2 all-time installs (skills.sh)
- Ranked #74 of 98 Go skills by installs in the Skillselion catalog
- Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/testdino-hq/google-styleguides-skills --skill goAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 2 |
|---|---|
| repo stars | ★ 8 |
| Last updated | February 25, 2026 |
| Repository | testdino-hq/google-styleguides-skills ↗ |
What it does
Applies Google's official Go style guide for formatting, naming, error handling, and idiomatic package organization.
Files
Google Go Style Guide
Official Google Go coding standards for idiomatic, maintainable code.
Golden Rules
1. Run `gofmt` before commit — formatting is non-negotiable 2. Short variable names in small scopes — i, err, ctx 3. Error handling, not exceptions — check every error 4. Interfaces for abstraction — accept interfaces, return structs 5. Defer for cleanup — ensure resources are released 6. Explicit is better — avoid magic, prefer clarity 7. Package names: lowercase, single word — no underscores
Quick Reference
Naming Conventions
| Element | Convention | Example |
|---|---|---|
| Packages | lowercase | package user |
| Files | lowercase_underscore | user_service.go |
| Types | UpperCamelCase | UserService |
| Functions/Methods | UpperCamelCase (exported) | GetUser |
| Functions/Methods | lowerCamelCase (unexported) | getUserByID |
| Variables | lowerCamelCase | userCount |
| Constants | UpperCamelCase or UPPER_SNAKE | MaxRetries |
| Interfaces | UpperCamelCase + -er suffix | Reader, Writer |
Variables
// ✓ CORRECT - short names in small scopes
for i := 0; i < 10; i++ {
// ...
}
// ✓ CORRECT - descriptive names in larger scopes
func ProcessUserData(userRepository UserRepository) error {
// ...
}
// ✗ INCORRECT - unnecessarily long
for index := 0; index < 10; index++ {
// ...
}Error Handling
// ✓ CORRECT - check every error
user, err := getUser(id)
if err != nil {
return nil, fmt.Errorf("failed to get user: %w", err)
}
// ✗ INCORRECT - ignoring errors
user, _ := getUser(id)Functions
// ✓ CORRECT - multiple return values
func GetUser(id int) (*User, error) {
// ...
}
// ✓ CORRECT - named return values for clarity
func ParseConfig(path string) (cfg *Config, err error) {
// ...
}Interfaces
// ✓ CORRECT - small, focused interfaces
type Reader interface {
Read(p []byte) (n int, err error)
}
// ✓ CORRECT - accept interfaces, return structs
func ProcessData(r Reader) (*Result, error) {
// ...
}Defer
// ✓ CORRECT - defer for cleanup
func ReadFile(path string) ([]byte, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
return io.ReadAll(f)
}Goroutines and Channels
// ✓ CORRECT - use context for cancellation
func ProcessItems(ctx context.Context, items []Item) error {
for _, item := range items {
select {
case <-ctx.Done():
return ctx.Err()
default:
if err := process(item); err != nil {
return err
}
}
}
return nil
}
// ✓ CORRECT - buffered channels when appropriate
results := make(chan Result, len(items))Package Organization
// ✓ CORRECT - package comment
// Package user provides user management functionality.
package user
// ✓ CORRECT - group imports
import (
"context"
"fmt"
"github.com/pkg/errors"
"myapp/internal/db"
)Common Mistakes
| Mistake | Correct Approach |
|---|---|
| Ignoring errors | Check every error |
| Long variable names in loops | Use short names (i, j) |
| Panic for normal errors | Return errors |
| Naked returns | Use explicit returns |
| Not running gofmt | Always format code |
| Underscores in package names | Use single lowercase word |
When to Use This Guide
- Writing new Go code
- Refactoring existing Go
- Code reviews
- Setting up linting rules (golangci-lint)
- Onboarding new team members
Install
npx skills add testdino-hq/google-styleguides-skills/goFull Guide
See go.md for complete details, examples, and edge cases.
Google Go Style Guide
Source: https://google.github.io/styleguide/go/
Golden Rules
1. Run `gofmt` — all code must be formatted with gofmt 2. Handle errors explicitly — never ignore returned errors with _ 3. Comment exported identifiers — all exported names must have doc comment 4. Return early — prefer guard clauses over deep nesting 5. Keep interfaces small — one or two methods is ideal 6. Name things clearly — short names for short scopes
---
1. Naming
// packages: lowercase, no underscores
package userservice
// exported: UpperCamelCase
type UserService struct { }
func GetUser(id int) (*User, error) { return nil, nil }
// unexported: lowerCamelCase
type userRepository struct { }
func getUserByID(id int) (*User, error) { return nil, nil }
// constants: UpperCamelCase (not UPPER_SNAKE_CASE)
const MaxRetries = 3
const defaultTimeout = 30
// acronyms: all uppercase
type HTTPClient struct { }
func parseURL(raw string) string { return raw }---
2. Error Handling
// CORRECT - always handle errors
file, err := os.Open("data.txt")
if err != nil {
return fmt.Errorf("opening data file: %w", err)
}
defer file.Close()
// CORRECT - wrap errors with context
func processUser(id int) error {
user, err := getUser(id)
if err != nil {
return fmt.Errorf("processUser(%d): %w", id, err)
}
return nil
}
// INCORRECT - ignoring errors
file, _ := os.Open("data.txt") // never ignore errors---
3. Interfaces
// CORRECT - small, focused interfaces
type Reader interface {
Read(p []byte) (n int, err error)
}
// CORRECT - interface composition
type ReadWriter interface {
Reader
Writer
}
// AVOID - large interfaces (too many methods)---
4. Structs
// CORRECT
type User struct {
ID int
Name string
Email string
}
// CORRECT - struct literal with field names
user := User{
ID: 1,
Name: "Alice",
Email: "alice@example.com",
}
// INCORRECT - positional struct literal
user := User{1, "Alice", "alice@example.com"} // fragile---
5. Goroutines
// CORRECT - always synchronize
var wg sync.WaitGroup
for _, item := range items {
wg.Add(1)
go func(item Item) {
defer wg.Done()
process(item)
}(item)
}
wg.Wait()---
6. Testing (Table-Driven)
// CORRECT - table-driven tests
func TestAdd(t *testing.T) {
tests := []struct {
name string
a, b int
expected int
}{
{"positive", 1, 2, 3},
{"negative", -1, -2, -3},
{"zero", 0, 0, 0},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := add(tt.a, tt.b)
if got != tt.expected {
t.Errorf("add(%d, %d) = %d; want %d", tt.a, tt.b, got, tt.expected)
}
})
}
}---
Common Mistakes
| Mistake | Correct Approach |
|---|---|
| Ignoring errors with _ | Always handle returned errors |
| Large interfaces | Keep to 1-2 methods |
| Positional struct literals | Use field names |
| No doc comments on exports | Add doc comment to every export |
| UPPER_SNAKE_CASE constants | Use UpperCamelCase |
| Leaking goroutines | Always ensure goroutines terminate |