[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6E3ZSBCDXVVSCHFV262XSE3":3,"skill-same:01M6E3ZSBCDXVVSCHFV262XSE3":52},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":23,"linkOnly":24,"markdownContent":25,"markdownBody":26,"frontMatter":27,"refName":29,"commitSha":30,"skillDirectory":31,"forksCount":32,"repositoryHtmlUrl":33,"repositoryHomepageUrl":34,"ownerHtmlUrl":35,"ownerBlogUrl":6,"ownerDescription":36,"updatedAt":37,"install":38,"resources":51},"01M6E3ZSBCDXVVSCHFV262XSE3","golang-patterns",null,"??????????????Go???????Go???????????","1024XEngineer\u002Fbytemind","1024XEngineer","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F268547415?v=4","01M6E269SXV33P2PN20YB4GKXS","XEngineer Camp","01M6E3ZBC2YEQVSRCAZK449022",27,"MIT","https:\u002F\u002Fgithub.com\u002F1024XEngineer\u002Fbytemind\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fgolang-patterns\u002FSKILL.md",[],[19,20,21,22],"golang","golang patterns","patterns","go","2026-11-10 10:12:30",false,"---\r\nname: golang-patterns\r\ndescription: ??????????????Go???????Go???????????\r\norigin: ECC\r\n---\r\n\r\n# Go ????\r\n\r\n???????????????????? Go ????????\r\n\r\n## ????\r\n\r\n* ???? Go ???\r\n* ?? Go ???\r\n* ???? Go ???\r\n* ?? Go ?\u002F???\r\n\r\n## ????\r\n\r\n### 1. ?????\r\n\r\nGo ???????????????????????\r\n\r\n```go\r\n\u002F\u002F Good: Clear and direct\r\nfunc GetUser(id string) (*User, error) {\r\n    user, err := db.FindUser(id)\r\n    if err != nil {\r\n        return nil, fmt.Errorf(\"get user %s: %w\", id, err)\r\n    }\r\n    return user, nil\r\n}\r\n\r\n\u002F\u002F Bad: Overly clever\r\nfunc GetUser(id string) (*User, error) {\r\n    return func() (*User, error) {\r\n        if u, e := db.FindUser(id); e == nil {\r\n            return u, nil\r\n        } else {\r\n            return nil, e\r\n        }\r\n    }()\r\n}\r\n```\r\n\r\n### 2. ???????\r\n\r\n???????????????????????\r\n\r\n```go\r\n\u002F\u002F Good: Zero value is useful\r\ntype Counter struct {\r\n    mu    sync.Mutex\r\n    count int \u002F\u002F zero value is 0, ready to use\r\n}\r\n\r\nfunc (c *Counter) Inc() {\r\n    c.mu.Lock()\r\n    c.count++\r\n    c.mu.Unlock()\r\n}\r\n\r\n\u002F\u002F Good: bytes.Buffer works with zero value\r\nvar buf bytes.Buffer\r\nbuf.WriteString(\"hello\")\r\n\r\n\u002F\u002F Bad: Requires initialization\r\ntype BadCounter struct {\r\n    counts map[string]int \u002F\u002F nil map will panic\r\n}\r\n```\r\n\r\n### 3. ??????????\r\n\r\n??????????????????\r\n\r\n```go\r\n\u002F\u002F Good: Accepts interface, returns concrete type\r\nfunc ProcessData(r io.Reader) (*Result, error) {\r\n    data, err := io.ReadAll(r)\r\n    if err != nil {\r\n        return nil, err\r\n    }\r\n    return &Result{Data: data}, nil\r\n}\r\n\r\n\u002F\u002F Bad: Returns interface (hides implementation details unnecessarily)\r\nfunc ProcessData(r io.Reader) (io.Reader, error) {\r\n    \u002F\u002F ...\r\n}\r\n```\r\n\r\n## ??????\r\n\r\n### ?????????\r\n\r\n```go\r\n\u002F\u002F Good: Wrap errors with context\r\nfunc LoadConfig(path string) (*Config, error) {\r\n    data, err := os.ReadFile(path)\r\n    if err != nil {\r\n        return nil, fmt.Errorf(\"load config %s: %w\", path, err)\r\n    }\r\n\r\n    var cfg Config\r\n    if err := json.Unmarshal(data, &cfg); err != nil {\r\n        return nil, fmt.Errorf(\"parse config %s: %w\", path, err)\r\n    }\r\n\r\n    return &cfg, nil\r\n}\r\n```\r\n\r\n### ???????\r\n\r\n```go\r\n\u002F\u002F Define domain-specific errors\r\ntype ValidationError struct {\r\n    Field   string\r\n    Message string\r\n}\r\n\r\nfunc (e *ValidationError) Error() string {\r\n    return fmt.Sprintf(\"validation failed on %s: %s\", e.Field, e.Message)\r\n}\r\n\r\n\u002F\u002F Sentinel errors for common cases\r\nvar (\r\n    ErrNotFound     = errors.New(\"resource not found\")\r\n    ErrUnauthorized = errors.New(\"unauthorized\")\r\n    ErrInvalidInput = errors.New(\"invalid input\")\r\n)\r\n```\r\n\r\n### ?? errors.Is ? errors.As ????\r\n\r\n```go\r\nfunc HandleError(err error) {\r\n    \u002F\u002F Check for specific error\r\n    if errors.Is(err, sql.ErrNoRows) {\r\n        log.Println(\"No records found\")\r\n        return\r\n    }\r\n\r\n    \u002F\u002F Check for error type\r\n    var validationErr *ValidationError\r\n    if errors.As(err, &validationErr) {\r\n        log.Printf(\"Validation error on field %s: %s\",\r\n            validationErr.Field, validationErr.Message)\r\n        return\r\n    }\r\n\r\n    \u002F\u002F Unknown error\r\n    log.Printf(\"Unexpected error: %v\", err)\r\n}\r\n```\r\n\r\n### ??????\r\n\r\n```go\r\n\u002F\u002F Bad: Ignoring error with blank identifier\r\nresult, _ := doSomething()\r\n\r\n\u002F\u002F Good: Handle or explicitly document why it's safe to ignore\r\nresult, err := doSomething()\r\nif err != nil {\r\n    return err\r\n}\r\n\r\n\u002F\u002F Acceptable: When error truly doesn't matter (rare)\r\n_ = writer.Close() \u002F\u002F Best-effort cleanup, error logged elsewhere\r\n```\r\n\r\n## ????\r\n\r\n### ???\r\n\r\n```go\r\nfunc WorkerPool(jobs \u003C-chan Job, results chan\u003C- Result, numWorkers int) {\r\n    var wg sync.WaitGroup\r\n\r\n    for i := 0; i \u003C numWorkers; i++ {\r\n        wg.Add(1)\r\n        go func() {\r\n            defer wg.Done()\r\n            for job := range jobs {\r\n                results \u003C- process(job)\r\n            }\r\n        }()\r\n    }\r\n\r\n    wg.Wait()\r\n    close(results)\r\n}\r\n```\r\n\r\n### ???????? Context\r\n\r\n```go\r\nfunc FetchWithTimeout(ctx context.Context, url string) ([]byte, error) {\r\n    ctx, cancel := context.WithTimeout(ctx, 5*time.Second)\r\n    defer cancel()\r\n\r\n    req, err := http.NewRequestWithContext(ctx, \"GET\", url, nil)\r\n    if err != nil {\r\n        return nil, fmt.Errorf(\"create request: %w\", err)\r\n    }\r\n\r\n    resp, err := http.DefaultClient.Do(req)\r\n    if err != nil {\r\n        return nil, fmt.Errorf(\"fetch %s: %w\", url, err)\r\n    }\r\n    defer resp.Body.Close()\r\n\r\n    return io.ReadAll(resp.Body)\r\n}\r\n```\r\n\r\n### ????\r\n\r\n```go\r\nfunc GracefulShutdown(server *http.Server) {\r\n    quit := make(chan os.Signal, 1)\r\n    signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)\r\n\r\n    \u003C-quit\r\n    log.Println(\"Shutting down server...\")\r\n\r\n    ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)\r\n    defer cancel()\r\n\r\n    if err := server.Shutdown(ctx); err != nil {\r\n        log.Fatalf(\"Server forced to shutdown: %v\", err)\r\n    }\r\n\r\n    log.Println(\"Server exited\")\r\n}\r\n```\r\n\r\n### ???? Goroutine ? errgroup\r\n\r\n```go\r\nimport \"golang.org\u002Fx\u002Fsync\u002Ferrgroup\"\r\n\r\nfunc FetchAll(ctx context.Context, urls []string) ([][]byte, error) {\r\n    g, ctx := errgroup.WithContext(ctx)\r\n    results := make([][]byte, len(urls))\r\n\r\n    for i, url := range urls {\r\n        i, url := i, url \u002F\u002F Capture loop variables\r\n        g.Go(func() error {\r\n            data, err := FetchWithTimeout(ctx, url)\r\n            if err != nil {\r\n                return err\r\n            }\r\n            results[i] = data\r\n            return nil\r\n        })\r\n    }\r\n\r\n    if err := g.Wait(); err != nil {\r\n        return nil, err\r\n    }\r\n    return results, nil\r\n}\r\n```\r\n\r\n### ?? Goroutine ??\r\n\r\n```go\r\n\u002F\u002F Bad: Goroutine leak if context is cancelled\r\nfunc leakyFetch(ctx context.Context, url string) \u003C-chan []byte {\r\n    ch := make(chan []byte)\r\n    go func() {\r\n        data, _ := fetch(url)\r\n        ch \u003C- data \u002F\u002F Blocks forever if no receiver\r\n    }()\r\n    return ch\r\n}\r\n\r\n\u002F\u002F Good: Properly handles cancellation\r\nfunc safeFetch(ctx context.Context, url string) \u003C-chan []byte {\r\n    ch := make(chan []byte, 1) \u002F\u002F Buffered channel\r\n    go func() {\r\n        data, err := fetch(url)\r\n        if err != nil {\r\n            return\r\n        }\r\n        select {\r\n        case ch \u003C- data:\r\n        case \u003C-ctx.Done():\r\n        }\r\n    }()\r\n    return ch\r\n}\r\n```\r\n\r\n## ????\r\n\r\n### ???????\r\n\r\n```go\r\n\u002F\u002F Good: Single-method interfaces\r\ntype Reader interface {\r\n    Read(p []byte) (n int, err error)\r\n}\r\n\r\ntype Writer interface {\r\n    Write(p []byte) (n int, err error)\r\n}\r\n\r\ntype Closer interface {\r\n    Close() error\r\n}\r\n\r\n\u002F\u002F Compose interfaces as needed\r\ntype ReadWriteCloser interface {\r\n    Reader\r\n    Writer\r\n    Closer\r\n}\r\n```\r\n\r\n### ??????????\r\n\r\n```go\r\n\u002F\u002F In the consumer package, not the provider\r\npackage service\r\n\r\n\u002F\u002F UserStore defines what this service needs\r\ntype UserStore interface {\r\n    GetUser(id string) (*User, error)\r\n    SaveUser(user *User) error\r\n}\r\n\r\ntype Service struct {\r\n    store UserStore\r\n}\r\n\r\n\u002F\u002F Concrete implementation can be in another package\r\n\u002F\u002F It doesn't need to know about this interface\r\n```\r\n\r\n### ????????????\r\n\r\n```go\r\ntype Flusher interface {\r\n    Flush() error\r\n}\r\n\r\nfunc WriteAndFlush(w io.Writer, data []byte) error {\r\n    if _, err := w.Write(data); err != nil {\r\n        return err\r\n    }\r\n\r\n    \u002F\u002F Flush if supported\r\n    if f, ok := w.(Flusher); ok {\r\n        return f.Flush()\r\n    }\r\n    return nil\r\n}\r\n```\r\n\r\n## ???\r\n\r\n### ??????\r\n\r\n```text\r\nmyproject\u002F\r\n??? cmd\u002F\r\n?   ??? myapp\u002F\r\n?       ??? main.go           # ???\r\n??? internal\u002F\r\n?   ??? handler\u002F              # HTTP ???\r\n?   ??? service\u002F              # ????\r\n?   ??? repository\u002F           # ????\r\n?   ??? config\u002F               # ??\r\n??? pkg\u002F\r\n?   ??? client\u002F               # ?? API ???\r\n??? api\u002F\r\n?   ??? v1\u002F                   # API ???proto, OpenAPI?\r\n??? testdata\u002F                 # ????\r\n??? go.mod\r\n??? go.sum\r\n??? Makefile\r\n```\r\n\r\n### ???\r\n\r\n```go\r\n\u002F\u002F Good: Short, lowercase, no underscores\r\npackage http\r\npackage json\r\npackage user\r\n\r\n\u002F\u002F Bad: Verbose, mixed case, or redundant\r\npackage httpHandler\r\npackage json_parser\r\npackage userService \u002F\u002F Redundant 'Service' suffix\r\n```\r\n\r\n### ??????\r\n\r\n```go\r\n\u002F\u002F Bad: Global mutable state\r\nvar db *sql.DB\r\n\r\nfunc init() {\r\n    db, _ = sql.Open(\"postgres\", os.Getenv(\"DATABASE_URL\"))\r\n}\r\n\r\n\u002F\u002F Good: Dependency injection\r\ntype Server struct {\r\n    db *sql.DB\r\n}\r\n\r\nfunc NewServer(db *sql.DB) *Server {\r\n    return &Server{db: db}\r\n}\r\n```\r\n\r\n## ?????\r\n\r\n### ???????\r\n\r\n```go\r\ntype Server struct {\r\n    addr    string\r\n    timeout time.Duration\r\n    logger  *log.Logger\r\n}\r\n\r\ntype Option func(*Server)\r\n\r\nfunc WithTimeout(d time.Duration) Option {\r\n    return func(s *Server) {\r\n        s.timeout = d\r\n    }\r\n}\r\n\r\nfunc WithLogger(l *log.Logger) Option {\r\n    return func(s *Server) {\r\n        s.logger = l\r\n    }\r\n}\r\n\r\nfunc NewServer(addr string, opts ...Option) *Server {\r\n    s := &Server{\r\n        addr:    addr,\r\n        timeout: 30 * time.Second, \u002F\u002F default\r\n        logger:  log.Default(),    \u002F\u002F default\r\n    }\r\n    for _, opt := range opts {\r\n        opt(s)\r\n    }\r\n    return s\r\n}\r\n\r\n\u002F\u002F Usage\r\nserver := NewServer(\":8080\",\r\n    WithTimeout(60*time.Second),\r\n    WithLogger(customLogger),\r\n)\r\n```\r\n\r\n### ????????\r\n\r\n```go\r\ntype Logger struct {\r\n    prefix string\r\n}\r\n\r\nfunc (l *Logger) Log(msg string) {\r\n    fmt.Printf(\"[%s] %s\\n\", l.prefix, msg)\r\n}\r\n\r\ntype Server struct {\r\n    *Logger \u002F\u002F Embedding - Server gets Log method\r\n    addr    string\r\n}\r\n\r\nfunc NewServer(addr string) *Server {\r\n    return &Server{\r\n        Logger: &Logger{prefix: \"SERVER\"},\r\n        addr:   addr,\r\n    }\r\n}\r\n\r\n\u002F\u002F Usage\r\ns := NewServer(\":8080\")\r\ns.Log(\"Starting...\") \u002F\u002F Calls embedded Logger.Log\r\n```\r\n\r\n## ?????\r\n\r\n### ???????????\r\n\r\n```go\r\n\u002F\u002F Bad: Grows slice multiple times\r\nfunc processItems(items []Item) []Result {\r\n    var results []Result\r\n    for _, item := range items {\r\n        results = append(results, process(item))\r\n    }\r\n    return results\r\n}\r\n\r\n\u002F\u002F Good: Single allocation\r\nfunc processItems(items []Item) []Result {\r\n    results := make([]Result, 0, len(items))\r\n    for _, item := range items {\r\n        results = append(results, process(item))\r\n    }\r\n    return results\r\n}\r\n```\r\n\r\n### ??????? sync.Pool\r\n\r\n```go\r\nvar bufferPool = sync.Pool{\r\n    New: func() interface{} {\r\n        return new(bytes.Buffer)\r\n    },\r\n}\r\n\r\nfunc ProcessRequest(data []byte) []byte {\r\n    buf := bufferPool.Get().(*bytes.Buffer)\r\n    defer func() {\r\n        buf.Reset()\r\n        bufferPool.Put(buf)\r\n    }()\r\n\r\n    buf.Write(data)\r\n    \u002F\u002F Process...\r\n    return buf.Bytes()\r\n}\r\n```\r\n\r\n### ?????????????\r\n\r\n```go\r\n\u002F\u002F Bad: Creates many string allocations\r\nfunc join(parts []string) string {\r\n    var result string\r\n    for _, p := range parts {\r\n        result += p + \",\"\r\n    }\r\n    return result\r\n}\r\n\r\n\u002F\u002F Good: Single allocation with strings.Builder\r\nfunc join(parts []string) string {\r\n    var sb strings.Builder\r\n    for i, p := range parts {\r\n        if i > 0 {\r\n            sb.WriteString(\",\")\r\n        }\r\n        sb.WriteString(p)\r\n    }\r\n    return sb.String()\r\n}\r\n\r\n\u002F\u002F Best: Use standard library\r\nfunc join(parts []string) string {\r\n    return strings.Join(parts, \",\")\r\n}\r\n```\r\n\r\n## Go ????\r\n\r\n### ????\r\n\r\n```bash\r\n# Build and run\r\ngo build .\u002F...\r\ngo run .\u002Fcmd\u002Fmyapp\r\n\r\n# Testing\r\ngo test .\u002F...\r\ngo test -race .\u002F...\r\ngo test -cover .\u002F...\r\n\r\n# Static analysis\r\ngo vet .\u002F...\r\nstaticcheck .\u002F...\r\ngolangci-lint run\r\n\r\n# Module management\r\ngo mod tidy\r\ngo mod verify\r\n\r\n# Formatting\r\ngofmt -w .\r\ngoimports -w .\r\n```\r\n\r\n### ??? Linter ?? (.golangci.yml)\r\n\r\n```yaml\r\nlinters:\r\n  enable:\r\n    - errcheck\r\n    - gosimple\r\n    - govet\r\n    - ineffassign\r\n    - staticcheck\r\n    - unused\r\n    - gofmt\r\n    - goimports\r\n    - misspell\r\n    - unconvert\r\n    - unparam\r\n\r\nlinters-settings:\r\n  errcheck:\r\n    check-type-assertions: true\r\n  govet:\r\n    check-shadowing: true\r\n\r\nissues:\r\n  exclude-use-default: false\r\n```\r\n\r\n## ?????Go ???\r\n\r\n| ??? | ?? |\r\n|-------|-------------|\r\n| ?????????? | ??????????????? |\r\n| ???? | ????????????? |\r\n| ??????????? | ????? goroutine ?????? |\r\n| ??????? | ?????????????? |\r\n| ?????????? | ?????????? |\r\n| ?????? | ???????????? |\r\n| gofmt ?????????????? | ???? gofmt\u002Fgoimports ????? |\r\n| ???? | ???????????????? |\r\n\r\n## ???????\r\n\r\n```go\r\n\u002F\u002F Bad: Naked returns in long functions\r\nfunc process() (result int, err error) {\r\n    \u002F\u002F ... 50 lines ...\r\n    return \u002F\u002F What is being returned?\r\n}\r\n\r\n\u002F\u002F Bad: Using panic for control flow\r\nfunc GetUser(id string) *User {\r\n    user, err := db.Find(id)\r\n    if err != nil {\r\n        panic(err) \u002F\u002F Don't do this\r\n    }\r\n    return user\r\n}\r\n\r\n\u002F\u002F Bad: Passing context in struct\r\ntype Request struct {\r\n    ctx context.Context \u002F\u002F Context should be first param\r\n    ID  string\r\n}\r\n\r\n\u002F\u002F Good: Context as first parameter\r\nfunc ProcessRequest(ctx context.Context, id string) error {\r\n    \u002F\u002F ...\r\n}\r\n\r\n\u002F\u002F Bad: Mixing value and pointer receivers\r\ntype Counter struct{ n int }\r\nfunc (c Counter) Value() int { return c.n }    \u002F\u002F Value receiver\r\nfunc (c *Counter) Increment() { c.n++ }        \u002F\u002F Pointer receiver\r\n\u002F\u002F Pick one style and be consistent\r\n```\r\n\r\n**??**?Go ????????????????????????????????????????\r\n","# Go ????\r\n\r\n???????????????????? Go ????????\r\n\r\n## ????\r\n\r\n* ???? Go ???\r\n* ?? Go ???\r\n* ???? Go ???\r\n* ?? Go ?\u002F???\r\n\r\n## ????\r\n\r\n### 1. ?????\r\n\r\nGo ???????????????????????\r\n\r\n```go\r\n\u002F\u002F Good: Clear and direct\r\nfunc GetUser(id string) (*User, error) {\r\n    user, err := db.FindUser(id)\r\n    if err != nil {\r\n        return nil, fmt.Errorf(\"get user %s: %w\", id, err)\r\n    }\r\n    return user, nil\r\n}\r\n\r\n\u002F\u002F Bad: Overly clever\r\nfunc GetUser(id string) (*User, error) {\r\n    return func() (*User, error) {\r\n        if u, e := db.FindUser(id); e == nil {\r\n            return u, nil\r\n        } else {\r\n            return nil, e\r\n        }\r\n    }()\r\n}\r\n```\r\n\r\n### 2. ???????\r\n\r\n???????????????????????\r\n\r\n```go\r\n\u002F\u002F Good: Zero value is useful\r\ntype Counter struct {\r\n    mu    sync.Mutex\r\n    count int \u002F\u002F zero value is 0, ready to use\r\n}\r\n\r\nfunc (c *Counter) Inc() {\r\n    c.mu.Lock()\r\n    c.count++\r\n    c.mu.Unlock()\r\n}\r\n\r\n\u002F\u002F Good: bytes.Buffer works with zero value\r\nvar buf bytes.Buffer\r\nbuf.WriteString(\"hello\")\r\n\r\n\u002F\u002F Bad: Requires initialization\r\ntype BadCounter struct {\r\n    counts map[string]int \u002F\u002F nil map will panic\r\n}\r\n```\r\n\r\n### 3. ??????????\r\n\r\n??????????????????\r\n\r\n```go\r\n\u002F\u002F Good: Accepts interface, returns concrete type\r\nfunc ProcessData(r io.Reader) (*Result, error) {\r\n    data, err := io.ReadAll(r)\r\n    if err != nil {\r\n        return nil, err\r\n    }\r\n    return &Result{Data: data}, nil\r\n}\r\n\r\n\u002F\u002F Bad: Returns interface (hides implementation details unnecessarily)\r\nfunc ProcessData(r io.Reader) (io.Reader, error) {\r\n    \u002F\u002F ...\r\n}\r\n```\r\n\r\n## ??????\r\n\r\n### ?????????\r\n\r\n```go\r\n\u002F\u002F Good: Wrap errors with context\r\nfunc LoadConfig(path string) (*Config, error) {\r\n    data, err := os.ReadFile(path)\r\n    if err != nil {\r\n        return nil, fmt.Errorf(\"load config %s: %w\", path, err)\r\n    }\r\n\r\n    var cfg Config\r\n    if err := json.Unmarshal(data, &cfg); err != nil {\r\n        return nil, fmt.Errorf(\"parse config %s: %w\", path, err)\r\n    }\r\n\r\n    return &cfg, nil\r\n}\r\n```\r\n\r\n### ???????\r\n\r\n```go\r\n\u002F\u002F Define domain-specific errors\r\ntype ValidationError struct {\r\n    Field   string\r\n    Message string\r\n}\r\n\r\nfunc (e *ValidationError) Error() string {\r\n    return fmt.Sprintf(\"validation failed on %s: %s\", e.Field, e.Message)\r\n}\r\n\r\n\u002F\u002F Sentinel errors for common cases\r\nvar (\r\n    ErrNotFound     = errors.New(\"resource not found\")\r\n    ErrUnauthorized = errors.New(\"unauthorized\")\r\n    ErrInvalidInput = errors.New(\"invalid input\")\r\n)\r\n```\r\n\r\n### ?? errors.Is ? errors.As ????\r\n\r\n```go\r\nfunc HandleError(err error) {\r\n    \u002F\u002F Check for specific error\r\n    if errors.Is(err, sql.ErrNoRows) {\r\n        log.Println(\"No records found\")\r\n        return\r\n    }\r\n\r\n    \u002F\u002F Check for error type\r\n    var validationErr *ValidationError\r\n    if errors.As(err, &validationErr) {\r\n        log.Printf(\"Validation error on field %s: %s\",\r\n            validationErr.Field, validationErr.Message)\r\n        return\r\n    }\r\n\r\n    \u002F\u002F Unknown error\r\n    log.Printf(\"Unexpected error: %v\", err)\r\n}\r\n```\r\n\r\n### ??????\r\n\r\n```go\r\n\u002F\u002F Bad: Ignoring error with blank identifier\r\nresult, _ := doSomething()\r\n\r\n\u002F\u002F Good: Handle or explicitly document why it's safe to ignore\r\nresult, err := doSomething()\r\nif err != nil {\r\n    return err\r\n}\r\n\r\n\u002F\u002F Acceptable: When error truly doesn't matter (rare)\r\n_ = writer.Close() \u002F\u002F Best-effort cleanup, error logged elsewhere\r\n```\r\n\r\n## ????\r\n\r\n### ???\r\n\r\n```go\r\nfunc WorkerPool(jobs \u003C-chan Job, results chan\u003C- Result, numWorkers int) {\r\n    var wg sync.WaitGroup\r\n\r\n    for i := 0; i \u003C numWorkers; i++ {\r\n        wg.Add(1)\r\n        go func() {\r\n            defer wg.Done()\r\n            for job := range jobs {\r\n                results \u003C- process(job)\r\n            }\r\n        }()\r\n    }\r\n\r\n    wg.Wait()\r\n    close(results)\r\n}\r\n```\r\n\r\n### ???????? Context\r\n\r\n```go\r\nfunc FetchWithTimeout(ctx context.Context, url string) ([]byte, error) {\r\n    ctx, cancel := context.WithTimeout(ctx, 5*time.Second)\r\n    defer cancel()\r\n\r\n    req, err := http.NewRequestWithContext(ctx, \"GET\", url, nil)\r\n    if err != nil {\r\n        return nil, fmt.Errorf(\"create request: %w\", err)\r\n    }\r\n\r\n    resp, err := http.DefaultClient.Do(req)\r\n    if err != nil {\r\n        return nil, fmt.Errorf(\"fetch %s: %w\", url, err)\r\n    }\r\n    defer resp.Body.Close()\r\n\r\n    return io.ReadAll(resp.Body)\r\n}\r\n```\r\n\r\n### ????\r\n\r\n```go\r\nfunc GracefulShutdown(server *http.Server) {\r\n    quit := make(chan os.Signal, 1)\r\n    signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)\r\n\r\n    \u003C-quit\r\n    log.Println(\"Shutting down server...\")\r\n\r\n    ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)\r\n    defer cancel()\r\n\r\n    if err := server.Shutdown(ctx); err != nil {\r\n        log.Fatalf(\"Server forced to shutdown: %v\", err)\r\n    }\r\n\r\n    log.Println(\"Server exited\")\r\n}\r\n```\r\n\r\n### ???? Goroutine ? errgroup\r\n\r\n```go\r\nimport \"golang.org\u002Fx\u002Fsync\u002Ferrgroup\"\r\n\r\nfunc FetchAll(ctx context.Context, urls []string) ([][]byte, error) {\r\n    g, ctx := errgroup.WithContext(ctx)\r\n    results := make([][]byte, len(urls))\r\n\r\n    for i, url := range urls {\r\n        i, url := i, url \u002F\u002F Capture loop variables\r\n        g.Go(func() error {\r\n            data, err := FetchWithTimeout(ctx, url)\r\n            if err != nil {\r\n                return err\r\n            }\r\n            results[i] = data\r\n            return nil\r\n        })\r\n    }\r\n\r\n    if err := g.Wait(); err != nil {\r\n        return nil, err\r\n    }\r\n    return results, nil\r\n}\r\n```\r\n\r\n### ?? Goroutine ??\r\n\r\n```go\r\n\u002F\u002F Bad: Goroutine leak if context is cancelled\r\nfunc leakyFetch(ctx context.Context, url string) \u003C-chan []byte {\r\n    ch := make(chan []byte)\r\n    go func() {\r\n        data, _ := fetch(url)\r\n        ch \u003C- data \u002F\u002F Blocks forever if no receiver\r\n    }()\r\n    return ch\r\n}\r\n\r\n\u002F\u002F Good: Properly handles cancellation\r\nfunc safeFetch(ctx context.Context, url string) \u003C-chan []byte {\r\n    ch := make(chan []byte, 1) \u002F\u002F Buffered channel\r\n    go func() {\r\n        data, err := fetch(url)\r\n        if err != nil {\r\n            return\r\n        }\r\n        select {\r\n        case ch \u003C- data:\r\n        case \u003C-ctx.Done():\r\n        }\r\n    }()\r\n    return ch\r\n}\r\n```\r\n\r\n## ????\r\n\r\n### ???????\r\n\r\n```go\r\n\u002F\u002F Good: Single-method interfaces\r\ntype Reader interface {\r\n    Read(p []byte) (n int, err error)\r\n}\r\n\r\ntype Writer interface {\r\n    Write(p []byte) (n int, err error)\r\n}\r\n\r\ntype Closer interface {\r\n    Close() error\r\n}\r\n\r\n\u002F\u002F Compose interfaces as needed\r\ntype ReadWriteCloser interface {\r\n    Reader\r\n    Writer\r\n    Closer\r\n}\r\n```\r\n\r\n### ??????????\r\n\r\n```go\r\n\u002F\u002F In the consumer package, not the provider\r\npackage service\r\n\r\n\u002F\u002F UserStore defines what this service needs\r\ntype UserStore interface {\r\n    GetUser(id string) (*User, error)\r\n    SaveUser(user *User) error\r\n}\r\n\r\ntype Service struct {\r\n    store UserStore\r\n}\r\n\r\n\u002F\u002F Concrete implementation can be in another package\r\n\u002F\u002F It doesn't need to know about this interface\r\n```\r\n\r\n### ????????????\r\n\r\n```go\r\ntype Flusher interface {\r\n    Flush() error\r\n}\r\n\r\nfunc WriteAndFlush(w io.Writer, data []byte) error {\r\n    if _, err := w.Write(data); err != nil {\r\n        return err\r\n    }\r\n\r\n    \u002F\u002F Flush if supported\r\n    if f, ok := w.(Flusher); ok {\r\n        return f.Flush()\r\n    }\r\n    return nil\r\n}\r\n```\r\n\r\n## ???\r\n\r\n### ??????\r\n\r\n```text\r\nmyproject\u002F\r\n??? cmd\u002F\r\n?   ??? myapp\u002F\r\n?       ??? main.go           # ???\r\n??? internal\u002F\r\n?   ??? handler\u002F              # HTTP ???\r\n?   ??? service\u002F              # ????\r\n?   ??? repository\u002F           # ????\r\n?   ??? config\u002F               # ??\r\n??? pkg\u002F\r\n?   ??? client\u002F               # ?? API ???\r\n??? api\u002F\r\n?   ??? v1\u002F                   # API ???proto, OpenAPI?\r\n??? testdata\u002F                 # ????\r\n??? go.mod\r\n??? go.sum\r\n??? Makefile\r\n```\r\n\r\n### ???\r\n\r\n```go\r\n\u002F\u002F Good: Short, lowercase, no underscores\r\npackage http\r\npackage json\r\npackage user\r\n\r\n\u002F\u002F Bad: Verbose, mixed case, or redundant\r\npackage httpHandler\r\npackage json_parser\r\npackage userService \u002F\u002F Redundant 'Service' suffix\r\n```\r\n\r\n### ??????\r\n\r\n```go\r\n\u002F\u002F Bad: Global mutable state\r\nvar db *sql.DB\r\n\r\nfunc init() {\r\n    db, _ = sql.Open(\"postgres\", os.Getenv(\"DATABASE_URL\"))\r\n}\r\n\r\n\u002F\u002F Good: Dependency injection\r\ntype Server struct {\r\n    db *sql.DB\r\n}\r\n\r\nfunc NewServer(db *sql.DB) *Server {\r\n    return &Server{db: db}\r\n}\r\n```\r\n\r\n## ?????\r\n\r\n### ???????\r\n\r\n```go\r\ntype Server struct {\r\n    addr    string\r\n    timeout time.Duration\r\n    logger  *log.Logger\r\n}\r\n\r\ntype Option func(*Server)\r\n\r\nfunc WithTimeout(d time.Duration) Option {\r\n    return func(s *Server) {\r\n        s.timeout = d\r\n    }\r\n}\r\n\r\nfunc WithLogger(l *log.Logger) Option {\r\n    return func(s *Server) {\r\n        s.logger = l\r\n    }\r\n}\r\n\r\nfunc NewServer(addr string, opts ...Option) *Server {\r\n    s := &Server{\r\n        addr:    addr,\r\n        timeout: 30 * time.Second, \u002F\u002F default\r\n        logger:  log.Default(),    \u002F\u002F default\r\n    }\r\n    for _, opt := range opts {\r\n        opt(s)\r\n    }\r\n    return s\r\n}\r\n\r\n\u002F\u002F Usage\r\nserver := NewServer(\":8080\",\r\n    WithTimeout(60*time.Second),\r\n    WithLogger(customLogger),\r\n)\r\n```\r\n\r\n### ????????\r\n\r\n```go\r\ntype Logger struct {\r\n    prefix string\r\n}\r\n\r\nfunc (l *Logger) Log(msg string) {\r\n    fmt.Printf(\"[%s] %s\\n\", l.prefix, msg)\r\n}\r\n\r\ntype Server struct {\r\n    *Logger \u002F\u002F Embedding - Server gets Log method\r\n    addr    string\r\n}\r\n\r\nfunc NewServer(addr string) *Server {\r\n    return &Server{\r\n        Logger: &Logger{prefix: \"SERVER\"},\r\n        addr:   addr,\r\n    }\r\n}\r\n\r\n\u002F\u002F Usage\r\ns := NewServer(\":8080\")\r\ns.Log(\"Starting...\") \u002F\u002F Calls embedded Logger.Log\r\n```\r\n\r\n## ?????\r\n\r\n### ???????????\r\n\r\n```go\r\n\u002F\u002F Bad: Grows slice multiple times\r\nfunc processItems(items []Item) []Result {\r\n    var results []Result\r\n    for _, item := range items {\r\n        results = append(results, process(item))\r\n    }\r\n    return results\r\n}\r\n\r\n\u002F\u002F Good: Single allocation\r\nfunc processItems(items []Item) []Result {\r\n    results := make([]Result, 0, len(items))\r\n    for _, item := range items {\r\n        results = append(results, process(item))\r\n    }\r\n    return results\r\n}\r\n```\r\n\r\n### ??????? sync.Pool\r\n\r\n```go\r\nvar bufferPool = sync.Pool{\r\n    New: func() interface{} {\r\n        return new(bytes.Buffer)\r\n    },\r\n}\r\n\r\nfunc ProcessRequest(data []byte) []byte {\r\n    buf := bufferPool.Get().(*bytes.Buffer)\r\n    defer func() {\r\n        buf.Reset()\r\n        bufferPool.Put(buf)\r\n    }()\r\n\r\n    buf.Write(data)\r\n    \u002F\u002F Process...\r\n    return buf.Bytes()\r\n}\r\n```\r\n\r\n### ?????????????\r\n\r\n```go\r\n\u002F\u002F Bad: Creates many string allocations\r\nfunc join(parts []string) string {\r\n    var result string\r\n    for _, p := range parts {\r\n        result += p + \",\"\r\n    }\r\n    return result\r\n}\r\n\r\n\u002F\u002F Good: Single allocation with strings.Builder\r\nfunc join(parts []string) string {\r\n    var sb strings.Builder\r\n    for i, p := range parts {\r\n        if i > 0 {\r\n            sb.WriteString(\",\")\r\n        }\r\n        sb.WriteString(p)\r\n    }\r\n    return sb.String()\r\n}\r\n\r\n\u002F\u002F Best: Use standard library\r\nfunc join(parts []string) string {\r\n    return strings.Join(parts, \",\")\r\n}\r\n```\r\n\r\n## Go ????\r\n\r\n### ????\r\n\r\n```bash\r\n# Build and run\r\ngo build .\u002F...\r\ngo run .\u002Fcmd\u002Fmyapp\r\n\r\n# Testing\r\ngo test .\u002F...\r\ngo test -race .\u002F...\r\ngo test -cover .\u002F...\r\n\r\n# Static analysis\r\ngo vet .\u002F...\r\nstaticcheck .\u002F...\r\ngolangci-lint run\r\n\r\n# Module management\r\ngo mod tidy\r\ngo mod verify\r\n\r\n# Formatting\r\ngofmt -w .\r\ngoimports -w .\r\n```\r\n\r\n### ??? Linter ?? (.golangci.yml)\r\n\r\n```yaml\r\nlinters:\r\n  enable:\r\n    - errcheck\r\n    - gosimple\r\n    - govet\r\n    - ineffassign\r\n    - staticcheck\r\n    - unused\r\n    - gofmt\r\n    - goimports\r\n    - misspell\r\n    - unconvert\r\n    - unparam\r\n\r\nlinters-settings:\r\n  errcheck:\r\n    check-type-assertions: true\r\n  govet:\r\n    check-shadowing: true\r\n\r\nissues:\r\n  exclude-use-default: false\r\n```\r\n\r\n## ?????Go ???\r\n\r\n| ??? | ?? |\r\n|-------|-------------|\r\n| ?????????? | ??????????????? |\r\n| ???? | ????????????? |\r\n| ??????????? | ????? goroutine ?????? |\r\n| ??????? | ?????????????? |\r\n| ?????????? | ?????????? |\r\n| ?????? | ???????????? |\r\n| gofmt ?????????????? | ???? gofmt\u002Fgoimports ????? |\r\n| ???? | ???????????????? |\r\n\r\n## ???????\r\n\r\n```go\r\n\u002F\u002F Bad: Naked returns in long functions\r\nfunc process() (result int, err error) {\r\n    \u002F\u002F ... 50 lines ...\r\n    return \u002F\u002F What is being returned?\r\n}\r\n\r\n\u002F\u002F Bad: Using panic for control flow\r\nfunc GetUser(id string) *User {\r\n    user, err := db.Find(id)\r\n    if err != nil {\r\n        panic(err) \u002F\u002F Don't do this\r\n    }\r\n    return user\r\n}\r\n\r\n\u002F\u002F Bad: Passing context in struct\r\ntype Request struct {\r\n    ctx context.Context \u002F\u002F Context should be first param\r\n    ID  string\r\n}\r\n\r\n\u002F\u002F Good: Context as first parameter\r\nfunc ProcessRequest(ctx context.Context, id string) error {\r\n    \u002F\u002F ...\r\n}\r\n\r\n\u002F\u002F Bad: Mixing value and pointer receivers\r\ntype Counter struct{ n int }\r\nfunc (c Counter) Value() int { return c.n }    \u002F\u002F Value receiver\r\nfunc (c *Counter) Increment() { c.n++ }        \u002F\u002F Pointer receiver\r\n\u002F\u002F Pick one style and be consistent\r\n```\r\n\r\n**??**?Go ????????????????????????????????????????\r\n",{"name":5,"origin":28,"description":7},"ECC","main","f259496ed7f959b3400c57e2d3d4d0a548d4b6a3",".agents\u002Fskills\u002Fgolang-patterns",6,"https:\u002F\u002Fgithub.com\u002F1024XEngineer\u002Fbytemind","https:\u002F\u002F1024xengineer.github.io\u002Fbytemind\u002F","https:\u002F\u002Fgithub.com\u002F1024XEngineer","An open, hands-on platform where engineers grow through real projects, open-source collaboration, and architectural thinking.","2026-07-29 12:33:51",{"source":8,"skillName":5,"commands":39,"prompt":49,"zipAvailable":50},[40,43,46],{"tool":41,"command":42},"npx","npx skills add 1024XEngineer\u002Fbytemind --skill golang-patterns",{"tool":44,"command":45},"bunx","bunx skills add 1024XEngineer\u002Fbytemind --skill golang-patterns",{"tool":47,"command":48},"pnpm","pnpm dlx skills add 1024XEngineer\u002Fbytemind --skill golang-patterns","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002F1024XEngineer\u002Fbytemind\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fgolang-patterns\u002FSKILL.md",true,[],[53,75,98,114,139,153],{"skillNo":54,"name":55,"nameZh":6,"description":56,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":57,"categories":58,"keywords":59,"publishedAt":23},"01M6E40DD4NH8R8JYQEVN4RVQJ","write-rfc","Produce reviewable technical proposals with explicit decision rationale and rollout.","https:\u002F\u002Fgithub.com\u002F1024XEngineer\u002Fbytemind\u002Fblob\u002Fmain\u002Finternal\u002Fskills\u002Fwrite-rfc\u002FSKILL.md",[],[60,61,62,63,64,65,66,67,68,69,70,71,72,73,74],"write","RFC","write rfc","planning","technical design","options","migration","rollout","proposals","user","technical","decision","produce","architecture","design",{"skillNo":76,"name":77,"nameZh":6,"description":78,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":79,"categories":80,"keywords":81,"publishedAt":23},"01M6E407WDFPFMZ3NFNPBVC0GJ","skill-creator","Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.","https:\u002F\u002Fgithub.com\u002F1024XEngineer\u002Fbytemind\u002Fblob\u002Fmain\u002Finternal\u002Fskills\u002Fskill-creator\u002FSKILL.md",[],[82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97],"skill creator","create","benchmark","run","variance analysis","test","run evals","performance","analysis","users","existing skill","optimize","evals","use","edit","improve",{"skillNo":99,"name":100,"nameZh":6,"description":101,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":102,"categories":103,"keywords":104,"publishedAt":23},"01M6E40415NE0DJB3WS0QK68M6","review","Review current code changes with focus on correctness, regressions, and missing tests.","https:\u002F\u002Fgithub.com\u002F1024XEngineer\u002Fbytemind\u002Fblob\u002Fmain\u002Finternal\u002Fskills\u002Freview\u002FSKILL.md",[],[100,105,106,107,108,69,109,110,111,112,113],"risk assessment","missing","tests","focus","risk","code","assessment","code review","merge",{"skillNo":115,"name":116,"nameZh":6,"description":117,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":118,"categories":119,"keywords":120,"publishedAt":23},"01M6E400ME5ZDK25R08AR3Q2TA","repo-onboarding","Build repository context quickly: structure, entrypoints, build chain, and core modules.","https:\u002F\u002Fgithub.com\u002F1024XEngineer\u002Fbytemind\u002Fblob\u002Fmain\u002Finternal\u002Fskills\u002Frepo-onboarding\u002FSKILL.md",[],[121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138],"repo","onboarding","repo onboarding","context setup","team","chain","time","structure","build","implementation","modules","context","first","repository","core","setup","team handoff","handoff",{"skillNo":140,"name":141,"nameZh":6,"description":142,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":143,"categories":144,"keywords":145,"publishedAt":23},"01M6E3ZXZJTNBZ22Q0S1M9D5JD","github-pr","Analyze pull request context and highlight merge risks from diffs and comments.","https:\u002F\u002Fgithub.com\u002F1024XEngineer\u002Fbytemind\u002Fblob\u002Fmain\u002Finternal\u002Fskills\u002Fgithub-pr\u002FSKILL.md",[],[146,147,148,90,109,149,111,150,105,113,151,100,152,69,132],"pr","github","github pr","pull","pull request","diffs","analyze",{"skillNo":154,"name":155,"nameZh":6,"description":156,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":157,"categories":158,"keywords":159,"publishedAt":23},"01M6E3ZVAAQ2GVJH46BPC75C9R","bug-investigation","Diagnose issues with reproducible evidence before proposing a fix.","https:\u002F\u002Fgithub.com\u002F1024XEngineer\u002Fbytemind\u002Fblob\u002Fmain\u002Finternal\u002Fskills\u002Fbug-investigation\u002FSKILL.md",[],[160,161,162,163,164,165,166,167,69,168,169,170,171,87],"Bug Investigation","bug","investigation","production incident","incident","reports","evidence","fix","Production","Reproducible","issues","diagnose"]