Token导航 LogoToken导航TokenDH.com
研究检索需要联网github未标认证来源可访问许可证需确认审计通过

backend-go-code-style后端 Go 代码风格

Agent Skill

backend-go-code-style 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

261

周安装

11

GitHub Stars

4

下载量

92
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:backend-go-code-style(后端 Go 代码风格)
来源仓库:https://github.com/jimnguyendev/jimmy-skills
仓库路径:skills/backend-go-code-style
安装命令:
npx skills add https://github.com/jimnguyendev/jimmy-skills --skill backend-go-code-style
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/jimnguyendev/jimmy-skills --skill backend-go-code-style

简介

用于查找、检索和筛选相关信息,适合根据关键词、任务场景或来源线索快速定位候选结果。

  • 适用于需要从大量技术资料中提取有用信息的场景。
  • 通过系统化的搜索策略,帮助 Agent 发现最佳实践、安全漏洞或性能瓶颈。
  • 使用时需明确搜索目标和范围,避免无效查询。
  • 建议结合项目实际技术栈调整检索关键词和过滤条件。

SKILL.md

Community default. A company skill that explicitly supersedes jimmy-skills@backend-go-code-style skill takes precedence.

Go Code Style

Style rules that require human judgment. Linters handle mechanical enforcement; this skill handles clarity, locality, and readable package boundaries. For naming see jimmy-skills@backend-go-naming skill; for design patterns see jimmy-skills@backend-go-design-patterns skill; for struct/interface design see jimmy-skills@backend-go-structs-interfaces skill.

"Clear is better than clever." — Go Proverbs

When ignoring a rule, add a comment to the code.

Line Length & Breaking

No rigid line limit, but lines beyond ~120 characters MUST be broken. Break at semantic boundaries, not arbitrary column counts. Function calls with 4+ arguments MUST use one argument per line — even when the prompt asks for single-line code:

// Good — each argument on its own line, closing paren separate
mux.HandleFunc("/api/users", func(w http.ResponseWriter, r *http.Request) {
    handleUsers(
        w,
        r,
        serviceName,
        cfg,
        logger,
        authMiddleware,
    )
})

When a function signature is too long, the real fix is often fewer parameters (use an options struct) rather than better line wrapping. For multi-line signatures, put each parameter on its own line.

Variable Declarations

SHOULD use := for non-zero values, var for zero-value initialization. The form signals intent: var means "this starts at zero."

var count int              // zero value, set later
name := "default"          // non-zero, := is appropriate
var buf bytes.Buffer       // zero value is ready to use

Slice & Map Initialization

Slices and maps MUST be initialized explicitly, never nil. Nil maps panic on write; nil slices serialize to null in JSON (vs [] for empty slices), surprising API consumers.

users := []User{}                       // always initialized
m := map[string]int{}                   // always initialized
users := make([]User, 0, len(ids))      // preallocate when capacity is known
m := make(map[string]int, len(items))   // preallocate when size is known

Do not preallocate speculatively — make([]T, 0, 1000) wastes memory when the common case is 10 items.

Composite Literals

Composite literals MUST use field names — positional fields break when the type adds or reorders fields:

srv := &http.Server{
    Addr:         ":8080",
    ReadTimeout:  5 * time.Second,
    WriteTimeout: 10 * time.Second,
}

Control Flow

Reduce Nesting

Errors and edge cases MUST be handled first (early return). Keep the happy path at minimal indentation:

func process(data []byte) (*Result, error) {
    if len(data) == 0 {
        return nil, errors.New("empty data")
    }

    parsed, err := parse(data)
    if err != nil {
        return nil, fmt.Errorf("parsing: %w", err)
    }

    return transform(parsed), nil
}

Eliminate Unnecessary else

When the if body ends with return/break/continue, the else MUST be dropped. Use default-then-override for simple assignments — assign a default, then override with independent conditions or a switch:

// Good — default-then-override with switch (cleanest for mutually exclusive overrides)
level := zap.InfoLevel
switch {
case debug:
    level = zap.DebugLevel
case verbose:
    level = zap.WarnLevel
}

// Bad — else-if chain hides that there's a default
if debug {
    level = zap.DebugLevel
} else if verbose {
    level = zap.WarnLevel
} else {
    level = zap.InfoLevel
}

Complex Conditions & Init Scope

When an if condition has 3+ operands, MUST extract into named booleans — a wall of || is unreadable and hides business logic. Keep expensive checks inline for short-circuit benefit. Details

// Good — named booleans make intent clear
isAdmin := user.Role == RoleAdmin
isOwner := resource.OwnerID == user.ID
isPublicVerified := resource.IsPublic && user.IsVerified
if isAdmin || isOwner || isPublicVerified || permissions.Contains(PermOverride) {
    allow()
}

Scope variables to if blocks when only needed for the check:

if err := validate(input); err != nil {
    return err
}

Switch Over If-Else Chains

When comparing the same variable multiple times, prefer switch:

switch status {
case StatusActive:
    activate()
case StatusInactive:
    deactivate()
default:
    panic(fmt.Sprintf("unexpected status: %d", status))
}

Function Design

  • Functions SHOULD be short and focused — one function, one job.
  • Functions SHOULD have ≤4 parameters. Beyond that, use an options struct (see jimmy-skills@backend-go-design-patterns skill).
  • Parameter order: context.Context first, then inputs, then output destinations.
  • Naked returns help in very short functions (1-3 lines) where return values are obvious, but become confusing when readers must scroll to find what's returned — name returns explicitly in longer functions.
func FetchUser(ctx context.Context, id string) (*User, error)
func SendEmail(ctx context.Context, msg EmailMessage) error  // grouped into struct

Prefer range for Iteration

SHOULD use range over index-based loops. Use range n (Go 1.22+) for simple counting.

for _, user := range users {
    process(user)
}

Value vs Pointer Arguments

Pass small types (string, int, bool, time.Time) by value. Use pointers when mutating, for large structs (~128+ bytes), or when nil is meaningful. Details

Code Organization Within Files

  • Group related declarations: type, constructor, methods together
  • Order: package doc, imports, constants, types, constructors, methods, helpers
  • One primary type per file when it has significant methods
  • Blank imports (_ "pkg") register side effects (init functions). Restricting them to main and test packages makes side effects visible at the application root, not hidden in library code
  • Dot imports pollute the namespace and make it impossible to tell where a name comes from — never use in library code
  • Unexport aggressively — you can always export later; unexporting is a breaking change

Package Boundaries & Locality

For APIs and services, prioritize feature-first packages over technical-layer packages. A business capability should mostly live in one package or one directory tree, not be split across handlers/, services/, repository/, and models/ buckets.

  • Prefer internal/users/, internal/invoices/, internal/posts/ over internal/handlers/, internal/services/, internal/repository/
  • Keep handler, service, repository, routes, and feature-local types near each other when they belong to one feature
  • Start with fewer packages than you think you need; split only when the package has multiple unrelated reasons to change
  • If changing one feature forces edits across many packages, the boundaries are probably wrong

This is a readability concern, not just an architecture concern: locality is one of the fastest ways to reduce maintenance cost.

Naming Noise

  • File names SHOULD NOT repeat the package name unless needed for clarity
  • Type names SHOULD NOT repeat the package name
  • Method names SHOULD NOT repeat the receiver type name
// Good
package users

type Service struct{}

func (s *Service) Create(ctx context.Context, in CreateInput) error { ... }

// Bad
package users

type UserService struct{}

func (s *UserService) CreateUser(ctx context.Context, in UserCreateInput) error { ... }

Keep names short once package and type context already tell the story.

Keep Types Near Usage

Do not create giant models.go buckets by default. Keep types close to the feature and use case they serve.

  • Request/response DTOs stay near the handler or transport boundary that owns them
  • Persistence-only structs stay near the repository that uses them
  • Domain types shared by multiple files in the same feature can stay in types.go
  • Extract a shared package only when the type is truly shared across multiple features

Avoid Circular Dependencies

Package imports must stay one-way. If two packages start depending on each other:

  1. Move behavior to the package that truly owns the concern
  2. Merge the packages if they are really one concept
  3. Define a small interface at the consumer side and inject the concrete implementation from wiring code

Do not let users import billing while billing imports users. That is almost always a sign that the package split is wrong.

String Handling

Use strconv for simple conversions (faster), fmt.Sprintf for complex formatting. Use %q in error messages to make string boundaries visible. Use strings.Builder for loops, + for simple concatenation.

Type Conversions

Prefer explicit, narrow conversions. Use generics over any when a concrete type will do:

func Contains[T comparable](slice []T, target T) bool  // not []any

Philosophy

  • "A little copying is better than a little dependency"
  • Use slices and maps standard packages; for filter/group-by/chunk, prefer plain loops or small local helpers before adding a dependency
  • "Reflection is never clear" — avoid reflect unless necessary
  • Don't abstract prematurely — extract when the pattern is stable
  • Minimize public surface — every exported name is a commitment

Parallelizing Code Style Reviews

When reviewing code style across a large codebase, use up to 5 parallel sub-agents (via the Agent tool), each targeting an independent style concern (e.g. control flow, function design, variable declarations, string handling, code organization).

Enforce with Linters

Many rules are enforced automatically: gofmt, gofumpt, goimports, gocritic, revive, wsl_v5. → See the jimmy-skills@backend-go-linter skill.

Cross-References

  • → See the jimmy-skills@backend-go-naming skill for identifier naming conventions
  • → See the jimmy-skills@backend-go-structs-interfaces skill for pointer vs value receivers, interface design
  • → See the jimmy-skills@backend-go-design-patterns skill for functional options, builders, constructors
  • → See the jimmy-skills@backend-go-linter skill for automated formatting enforcement
  • → See the jimmy-skills@backend-go-project-layout skill for feature-first package trees and circular dependency prevention

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

35.24%
按下载量换算32

Claude

26.06%
按下载量换算24

Cursor

19.19%
按下载量换算18

Gemini CLI

9.75%
按下载量换算9

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills