Go Stdlib Style logo

Go Stdlib Style

Community
happydog-intj
go-stdlib-style

Go 标准库编码风格 Skill。蒸馏自 golang/go 标准库源码、Effective Go、 Rob Pike 的 Go Proverbs、Russ Cox 的设计文档、Go Code Review Comments 官方指南。 触发词:「Go 标准库风格」「idiomatic Go」「地道 Go」「go stdlib style」「Rob Pike 风格」。 适用:Go 库开发、CLI 工具、网络服务、系统工具。

Overview

Publisherhappydog-intj
Repositoryluban-skill
Skill namego-stdlib-style
Stars
32
Forks
3
Bundled files
Instructions only
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by happydog-intj on GitHub. Read the source before you install it.

Installation

Install the Go Stdlib Style AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/happydog-intj/luban-skill/tree/master/skills/go-stdlib.skill
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/happydog-intj/luban-skill.git /tmp/luban-skill
mkdir -p .claude/skills
cp -r /tmp/luban-skill/skills/go-stdlib.skill .claude/skills/go-stdlib-style
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Go Stdlib Style in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Go Stdlib Style on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Go Stdlib Style is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Go 标准库 · 编码 DNA

"Clear is better than clever." — Rob Pike, Go Proverbs "A little copying is better than a little dependency." — Rob Pike

角色定义

此 Skill 激活后,你写出的 Go 代码应该让标准库 contributor 在 code review 时感觉 「这代码像是从 net/http 里拿出来的」,而不是「这是 Java 开发者写的 Go」。

这意味着:简单、显式、接口小、无魔法。


命名 DNA

6 条直觉规则:

  1. 包名:单词、小写、不下划线、不 camelCase

    go
    // ✅
    package http
    package json
    package sync
    
    // ❌
    package httpUtils
    package http_client
    package HTTPServer

    包名是命名空间,使用时 http.Get,不是 httpClient.Get。

  2. 导出名不重复包名

    go
    // ✅ 使用时是 http.Request,不是 http.HTTPRequest
    package http
    type Request struct { ... }
    func Get(url string) (*Response, error) { ... }
    
    // ❌ 冗余
    type HTTPRequest struct { ... }
    func HTTPGet(url string) (*HTTPResponse, error) { ... }
  3. 接口名 = 方法名 + er(单方法接口)

    go
    // ✅ Go 的核心约定
    type Reader interface { Read(p []byte) (n int, err error) }
    type Writer interface { Write(p []byte) (n int, err error) }
    type Stringer interface { String() string }
    type Handler interface { ServeHTTP(ResponseWriter, *Request) }
    
    // ❌ 动词/形容词命名接口
    type Readable interface { ... }
    type DataProcessor interface { ... }
  4. 变量名短而精,作用域小则短

    go
    // ✅ 局部变量
    for i, v := range items { ... }
    r, err := http.Get(url)
    buf := make([]byte, 1024)
    
    // ✅ 包级变量
    var defaultClient = &Client{}
    var ErrNotFound = errors.New("not found")
    
    // ❌ 过长(Go 不是 Java)
    for index, value := range itemList { ... }
    httpResponseReader, requestError := httpClient.MakeGetRequest(requestUrl)
  5. 错误变量叫 err,不叫 error 或 e

    go
    // ✅
    n, err := r.Read(buf)
    if err != nil {
        return err
    }
  6. 常量和包级变量不用全大写(除了真正的常量)

    go
    // ✅
    const maxRetries = 3
    var defaultTimeout = 30 * time.Second
    
    // ❌ (Go 不是 C)
    const MAX_RETRIES = 3
    var DEFAULT_TIMEOUT = 30 * time.Second

结构偏好

接口设计:接口越小越好

go
// ✅ 单方法接口,组合使用
type Reader interface { Read(p []byte) (n int, err error) }
type Writer interface { Write(p []byte) (n int, err error) }
type ReadWriter interface {
    Reader
    Writer
}

// ❌ 胖接口(难以实现,难以测试)
type Storage interface {
    Read() ([]byte, error)
    Write([]byte) error
    Delete(key string) error
    List() ([]string, error)
    Stats() Stats
    Flush() error
}

函数设计:

go
// ✅ 接受接口,返回具体类型
func NewScanner(r io.Reader) *Scanner { ... }  // 接受 Reader 接口

// ✅ 错误永远是最后一个返回值
func Open(name string) (*File, error) { ... }

// ✅ 选项用 struct,不用过多参数
type DialOption struct {
    Timeout   time.Duration
    KeepAlive time.Duration
    Resolver  Resolver
}
func DialContext(ctx context.Context, network, address string, opt ...DialOption) (Conn, error)
// 或更 Go 风格的 functional options

错误处理:显式、不忽略、包上下文

go
// ✅ 每个错误都处理
f, err := os.Open(filename)
if err != nil {
    return fmt.Errorf("open config file: %w", err)  // 用 %w 包装,保留原始错误
}
defer f.Close()

// ✅ 错误信息小写,不加标点(它是被包装的,不是最终输出)
return fmt.Errorf("parse response: %w", err)   // ✅
return fmt.Errorf("Parse Response: %w", err)   // ❌ 大写
return fmt.Errorf("parse response: %w.", err)  // ❌ 加句号

// ❌ 忽略错误(除非真的不重要且有注释说明)
f, _ := os.Open(filename)

并发:

go
// ✅ 用 channel 传数据,不共享内存
func producer(ch chan<- int) {
    for i := 0; i < 10; i++ {
        ch <- i
    }
    close(ch)
}

// ✅ sync.Mutex 保护共享状态,锁和被保护的数据放一起
type Cache struct {
    mu    sync.Mutex  // 锁紧跟着被保护的字段
    items map[string]Item
}

// ✅ context 作为第一个参数传递
func (c *Client) Do(ctx context.Context, req *Request) (*Response, error) { ... }

注释哲学

Go 的注释规则极其简单,但要求严格:

go
// ✅ 导出符号必须有注释,且以符号名开头
// Reader is the interface that wraps the basic Read method.
type Reader interface { ... }

// Open opens the named file for reading.
// If successful, methods on the returned file can be used for reading;
// the associated file descriptor has mode O_RDONLY.
// If there is an error, it will be of type *PathError.
func Open(name string) (*File, error) { ... }

// ErrNotExist indicates that a file or directory does not exist.
var ErrNotExist = errors.New("file does not exist")
go
// ❌ 注释不以符号名开头(go doc 解析失败)
// This opens a file.
func Open(name string) (*File, error) { ... }

// ❌ 废话注释
// i is an integer counter
i := 0

//go: 指令注释:

go
//go:generate stringer -type=Weekday
//go:noescape  // 告诉编译器参数不逃逸到堆
//nolint:errcheck  // 关闭 linter(要有充分理由)

反模式(绝不这样写)

  1. panic 用于业务逻辑

    go
    // ❌ panic 不是错误处理
    func GetUser(id int) *User {
        user := db.Find(id)
        if user == nil {
            panic("user not found")
        }
        return user
    }
    // ✅ 返回 error
    func GetUser(id int) (*User, error) { ... }
  2. 接受具体类型而不是接口(限制了可测试性)

    go
    // ❌ 接受具体类型,无法 mock
    func Process(c *http.Client) { ... }
    // ✅ 接受接口
    func Process(c interface { Do(*http.Request) (*http.Response, error) }) { ... }
  3. init() 函数做复杂初始化 — init 难以测试、难以控制执行顺序

  4. 全局变量暴露可变状态 — 包级全局变量应该是不可变的(常量或配置)

  5. interface{} / any 满天飞 — Go 1.18+ 用泛型,不用空接口甩锅

    go
    // ❌
    func Store(key string, value interface{}) { ... }
    // ✅ 泛型
    func Store[V any](key string, value V) { ... }
  6. 忽略 defer 的错误

    go
    defer f.Close()  // ❌ 文件写入后 Close 出错会丢数据
    defer func() {
        if err := f.Close(); err != nil {
            log.Printf("close file: %v", err)
        }
    }()  // ✅
  7. 错误信息大写或加句号 — 会破坏 fmt.Errorf("open: %w", err) 的拼接效果


校验测试

  1. gofmt 检查:gofmt -d . 有输出吗?有就是格式不对(gofmt 是宗教)
  2. 接口检查:接收参数能换成接口吗?换了之后可测试性提升吗?
  3. 错误路径检查:grep -n "_, err" *.go —— 有没有忽略的错误?

来源

Frequently asked questions

What does the Go Stdlib Style AI skill do?

Go 标准库编码风格 Skill。蒸馏自 golang/go 标准库源码、Effective Go、 Rob Pike 的 Go Proverbs、Russ Cox 的设计文档、Go Code Review Comments 官方指南。 触发词:「Go 标准库风格」「idiomatic Go」「地道 Go」「go stdlib style」「Rob Pike 风格」。 适用:Go 库开发、CLI 工具、网络服务、系统工具。

Why use Go Stdlib Style on TypingMind?

Because you install it once and use it with any model. Go Stdlib Style is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Go Stdlib Style in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/happydog-intj/luban-skill/tree/master/skills/go-stdlib.skill. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Go Stdlib Style?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Go Stdlib Style?

As many as you like. As long as a model supports skills, you can use Go Stdlib Style with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Go Stdlib Style AI skill free?

It is published on GitHub by happydog-intj. Check the repository for licensing terms. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇