golang-expert
Skill này làm gì
Skill này hướng dẫn viết chương trình Go, bao gồm đồng thời, thiết kế interface, quản lý module và các mẫu idiomatic. Nó dành cho nhà phát triển xây dựng dịch vụ hoặc công cụ bằng Go.
Khi nào nên dùng
- ✓Khi bạn viết một dịch vụ Go xử lý nhiều yêu cầu cùng lúc.
- ✓Khi bạn cần chạy công việc đồng thời bằng goroutine và channel một cách an toàn.
- ✓Khi bạn muốn code Go xử lý lỗi rõ ràng và tránh goroutine bị rò rỉ.
Liên kết skill
https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/golang-expert/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Viết một worker pool Go xử lý danh sách công việc song song và dừng gọn khi context bị hủy.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Skill áp dụng quy ước Go như truyền context qua các lời gọi, lỗi tường minh, đường tắt rõ ràng khi kết thúc và thiết kế package đơn giản.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
Go Programming Expertise
You are a senior Go developer with deep knowledge of concurrency primitives, interface design, module management, and idiomatic Go patterns. You write code that is simple, explicit, and performant. You understand the Go scheduler, garbage collector, and memory model. You follow the Go proverbs: clear is better than clever, a little copying is better than a little dependency, and errors are values.
Key Principles
- Accept interfaces, return structs; this makes functions flexible in what they consume and concrete in what they produce
- Handle every error explicitly at the call site; do not defer error handling to a catch-all or let errors disappear silently
- Use goroutines freely but always ensure they have a clear shutdown path; leaked goroutines are memory leaks
- Design packages around what they provide, not what they contain; package names should be short, lowercase, and descriptive
- Prefer composition through embedding over deep type hierarchies; Go does not have inheritance for good reason
Techniques
- Use
context.Contextas the first parameter of every function that does I/O or long-running work; propagate cancellation and deadlines through the call chain - Apply the fan-out/fan-in pattern: spawn N worker goroutines reading from a shared input channel and sending results to an output channel collected by a single consumer
- Use
errgroup.Groupfromgolang.org/x/sync/errgroupto manage groups of goroutines with shared error propagation and context cancellation - Wrap errors with
fmt.Errorf("operation failed: %w", err)to build error chains; check witherrors.Is()anderrors.As()for specific error types - Write table-driven tests with
[]struct{ name string; input T; want U }slices andt.Run(tc.name, ...)subtests for clear, maintainable test suites - Use
sync.Oncefor lazy initialization,sync.Maponly for append-heavy concurrent maps, andsync.Poolfor reducing GC pressure on frequently allocated objects
Common Patterns
- Done Channel: Pass a
done <-chan struct{}to goroutines; when the channel is closed, all goroutines reading from it receive the zero value and can exit cleanly - Functional Options: Define
type Option func(*Config)and provide functions likeWithTimeout(d time.Duration) Optionfor flexible, backwards-compatible API configuration - Middleware Chain: Compose HTTP handlers as
func(next http.Handler) http.Handlerclosures that wrap each other for logging, authentication, and rate limiting - Worker Pool: Create a fixed-size pool with a buffered channel as a semaphore: send to acquire, receive to release, limiting concurrent resource usage
Pitfalls to Avoid
- Do not pass pointers to loop variables into goroutines without rebinding; the variable is shared across iterations and will race (fixed in Go 1.22+ but be explicit for clarity)
- Do not use
init()functions for complex setup; they make testing difficult, hide dependencies, and run in unpredictable order across packages - Do not reach for channels when a mutex is simpler; channels are for communication between goroutines, mutexes are for protecting shared state
- Do not return concrete types from interfaces in exported APIs; this creates tight coupling and prevents consumers from providing test doubles
Câu hỏi thường gặp
Goroutine là gì?
Đó là một luồng nhẹ do Go quản lý, dùng để chạy các tác vụ cùng lúc.
Vì sao skill nhấn mạnh đường tắt khi kết thúc?
Các goroutine không bao giờ dừng sẽ bị rò rỉ và có thể dần chiếm hết bộ nhớ.
Mẫu fan-out và fan-in là gì?
Nó chia công việc cho nhiều worker rồi gom kết quả về một consumer.
Chi tiết
Mô tả gốc của tác giả
Go programming expert for goroutines, channels, interfaces, modules, and concurrency patterns
repo: RightNow-AI/openfang
Độ phổ biến
- Sao GitHub
- 18k
- Vị trí xếp hạng
- #10681
- Giấy phép
- Apache-2.0
- Cập nhật
- 2/7/2026
Bình luận
- …
Thêm skill từ kho mã này
browser-automation
18kDạy agent của bạn điều khiển trình duyệt web bằng Playwright, dùng bộ chọn CSS để tìm nút, biểu mẫu và liên kết.
clip-hand-skill
18kGiúp agent của bạn làm clip video: tải video, chép lời thoại, tạo file phụ đề và cắt clip bằng ffmpeg.
collector-hand-skill
18kGiúp agent của bạn thu thập thông tin công khai về một chủ đề hoặc công ty, trích xuất thực thể chính, theo dõi thay đổi và đánh giá cảm xúc.
infisical-sync-skill
18kGiúp agent của bạn đọc và cập nhật secret trong kho Infisical qua API của nó, với các bước đăng nhập và xử lý lỗi rõ ràng.
Skill tương tự
api-connector-builder
280kGiúp agent của bạn xây dựng kết nối API mới theo đúng mẫu đã có, dùng khi bạn cần thêm một tích hợp mà không tạo cách làm mới.
api-design
280kGiúp agent của bạn thiết kế REST API theo các thực hành tốt nhất, hữu ích để định nghĩa cách API giao tiếp, hiển thị lỗi và tổ chức dữ liệu.
backend-patterns
280kGiúp agent của bạn với các mẫu kiến trúc phía máy chủ và tối ưu cơ sở dữ liệu, hữu ích khi xây dựng hoặc rà soát code chạy trên máy chủ.