Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

go-coding-standards

БесплатноЗапускает вложенные скриптыНе проверен

Go coding standards following idiomatic Go patterns, error handling, concurrency best practices, and modern Go tooling. Use for Go projects requiring clean…

williamzujkowskiот williamzujkowski★ 23 звезды на GitHub27 установок в других каталогах

Об этом скилле

Go Coding Standards

Quick Navigation: Level 1: Quick Start (5 min) → Level 2: Implementation (30 min) → Level 3: Mastery (Extended)


Level 1: Quick Start (<2,000 tokens, 5 minutes)

Core Principles

  1. Idiomatic Go: Write code that follows Go idioms - simple, clear, and effective
  2. Explicit Errors: Return errors explicitly, handle them properly, no exceptions
  3. Interfaces: Accept interfaces, return concrete types
  4. Concurrency: Goroutines and channels for concurrent operations
  5. Testing: Table-driven tests with >80% coverage

Essential Checklist

  • Formatting: Code formatted with gofmt, imports organized with goimports
  • Naming: Follow Go conventions (MixedCaps, camelCase, short names in limited scope)
  • Error Handling: All errors checked and wrapped with context
  • Testing: _test.go files with table-driven tests, benchmarks
  • Documentation: Package and exported function documentation
  • Modules: go.mod with semantic versioning, tidy dependencies
  • Linting: Pass golangci-lint with strict configuration
  • Security: Input validation, no hardcoded secrets, secure defaults

Quick Example

// Package auth provides user authentication services.
package auth

import (
	"context"
	"errors"
	"fmt"
)

var (
	// ErrInvalidCredentials indicates authentication failure.
	ErrInvalidCredentials = errors.New("invalid credentials")
	// ErrUserNotFound indicates user does not exist.
	ErrUserNotFound = errors.New("user not found")
)

// User represents an authenticated user.
type User struct {
	ID       string
	Username string
	Email    string
}

// Repository defines user storage operations.
type Repository interface {
	FindByUsername(ctx context.Context, username string) (*User, error)
	VerifyPassword(ctx context.Context, userID, password string) bool
}

// Service handles authentication operations.
type Service struct {
	repo Repository
}

// NewService creates a new authentication service.
func NewService(repo Repository) *Service {
	return &Service{repo: repo}
}

// Authenticate verifies credentials and returns the authenticated user.
//
// Returns ErrInvalidCredentials if authentication fails,
// ErrUserNotFound if user doesn't exist, or wrapped errors for other failures.
func (s *Service) Authenticate(ctx context.Context, username, password string) (*User, error) {
	if username == "" || password == "" {
		return nil, fmt.Errorf("username and password required")
	}

	user, err := s.repo.FindByUsername(ctx, username)
	if err != nil {
		if errors.Is(err, ErrUserNotFound) {
			return nil, ErrInvalidCredentials // Don't reveal user existence
		}
		return nil, fmt.Errorf("find user: %w", err)
	}

	if !s.repo.VerifyPassword(ctx, user.ID, password) {
		return nil, ErrInvalidCredentials
	}

	return user, nil
}

Quick Links to Level 2


Level 2: Implementation (<5,000 tokens, 30 minutes)

Code Style & Organization

Idiomatic Go Naming

// ✅ Good: Clear, concise Go naming
type UserService struct {
	db    *sql.DB
	cache Cache
}

func (s *UserService) Get(ctx context.Context, id string) (*User, error) {
	// Short names in limited scope
	u, err := s.cache.Get(ctx, id)
	if err == nil {
		return u, nil
	}
	return s.db.QueryUser(ctx, id)
}

// ❌ Bad: Verbose, non-idiomatic
type UserServiceInterface struct {
	databaseConnection *sql.DB
	cacheImplementation Cache
}

Package Structure

myapp/
├── cmd/
│   └── server/
│       └── main.go          # Entry point
├── internal/
│   ├── auth/                # Authentication domain
│   │   ├── service.go
│   │   ├── repository.go
│   │   └── service_test.go
│   └── user/                # User domain
│       ├── user.go
│       └── postgres.go
├── pkg/
│   └── middleware/          # Reusable components
│       └── logging.go
├── go.mod
└── go.sum

Error Handling Patterns

Sentinel Errors and Wrapping

import (
	"errors"
	"fmt"
)

// Sentinel errors
var (
	ErrNotFound     = errors.New("not found")
	ErrUnauthorized = errors.New("unauthorized")
	ErrValidation   = errors.New("validation failed")
)

// Custom error types
type ValidationError struct {
	Field   string
	Message string
}

func (e *ValidationError) Error() string {
	return fmt.Sprintf("%s: %s", e.Field, e.Message)
}

// Error wrapping with context
func (s *Service) GetUser(ctx context.Context, id string) (*User, error) {
	user, err := s.repo.FindByID(ctx, id)
	if err != nil {
		if errors.Is(err, sql.ErrNoRows) {
			return nil, fmt.Errorf("user %s: %w", id, ErrNotF
Полный SKILL.md на GitHub

Установить go-coding-standards в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

resources/README.mdresources/configs/.golangci.ymlscripts/README.mdtemplates/README.md

FAQ

Что делает скилл go-coding-standards?

Go coding standards following idiomatic Go patterns, error handling, concurrency best practices, and modern Go tooling. Use for Go projects requiring clean, efficient, production-ready code with comprehensive testing.

Как установить скилл go-coding-standards?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл go-coding-standards запускает скрипты?

Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.

Похожие скиллы

Сравнить go-coding-standards с