go-expert
Skill2 starsChanged 4 months agoMITView on GitHub
Use when writing or reviewing Go code: implementing APIs, CLI tools, or microservices; applying Go idioms for error handling, goroutines, interfaces, and modules; writing table-driven tests; using context propagation; structuring Go projects.
In this repository9 other files it gives its agents.
- code-reviewSkill
- dotnet-expertSkill
- git-flowSkill
- nextjs-devSkill
- nuxt-devSkill
- security-auditSkill
- tailwind-uiSkill
- tddSkill
- typescript-astroSkill
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 228
Before completing Go work, verify:
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Go Expert Skill
You are a senior Go engineer who writes idiomatic, production-ready Go code.
When to Use
Activate this skill when the user:
- Writes or reviews Go code
- Implements HTTP servers (stdlib, chi, gin, echo)
- Builds CLI tools (cobra, urfave/cli)
- Works with goroutines, channels, sync primitives
- Handles errors idiomatically
- Structures Go modules and packages
- Writes table-driven tests
- Uses PostgreSQL with pgx, SQLite, or MongoDB
Core Go Idioms
Error Handling
// ✅ Always handle errors explicitly
result, err := doSomething()
if err != nil {
return fmt.Errorf("doSomething: %w", err) // wrap with context
}
// ✅ Sentinel errors for known cases
var ErrNotFound = errors.New("not found")
var ErrConflict = errors.New("conflict")
// ✅ Custom error types for rich context
type ValidationError struct {
Field string
Message string
}
func (e *ValidationError) Error() string {
return fmt.Sprintf("validation error: %s — %s", e.Field, e.Message)
}
// ❌ Never ignore errors
result, _ = doSomething()Context Propagation
// ✅ Always accept context as first parameter
func (s *UserService) GetUser(ctx context.Context, id int64) (*User, error) {
return s.repo.FindByID(ctx, id)
}
// ✅ Check context cancellation in loops
for _, item := range items {
select {
case <-ctx.Done():
return ctx.Err()
default:
}
if err := process(ctx, item); err != nil {
return err
}
}Interfaces
// ✅ Define interfaces where they are used, not where implemented
// In the consumer package:
type UserRepository interface {
FindByID(ctx context.Context, id int64) (*User, error)
Save(ctx context.Context, u *User) error
}
// ✅ Keep interfaces small
type Saver interface { Save(ctx context.Context, u *User) error }
type Finder interface { FindByID(ctx context.Context, id int64) (*User, error) }Concurrency
// ✅ Use errgroup for concurrent work with cancellation
g, ctx := errgroup.WithContext(ctx)
for _, id := range ids {
id := id // capture loop variable (pre-Go 1.22)
g.Go(func() error {
return process(ctx, id)
})
}
if err := g.Wait(); err != nil {
return err
}
// ✅ Always close channels in the sender, not the receiver
ch := make(chan Result, len(items))
go func() {
defer close(ch)
for _, item := range items {
ch <- process(item)
}
}()Structs and Constructors
// ✅ Use functional options for optional config
type Server struct {
addr string
timeout time.Duration
logger *slog.Logger
}
type Option func(*Server)
func WithTimeout(d time.Duration) Option {
return func(s *Server) { s.timeout = d }
}
func NewServer(addr string, opts ...Option) *Server {
s := &Server{addr: addr, timeout: 30 * time.Second, logger: slog.Default()}
for _, o := range opts { o(s) }
return s
}HTTP Server Patterns
// ✅ Standard library HTTP with chi router
func NewRouter(h *Handler) http.Handler {
r := chi.NewRouter()
r.Use(middleware.RequestID)
r.Use(middleware.RealIP)
r.Use(middleware.Logger)
r.Use(middleware.Recoverer)
r.Route("/api/v1", func(r chi.Router) {
r.Use(h.AuthMiddleware)
r.Get("/users/{id}", h.GetUser)
r.Post("/users", h.CreateUser)
})
return r
}
// ✅ Handler struct with dependencies
type Handler struct {
users UserService
logger *slog.Logger
}
func (h *Handler) GetUser(w http.ResponseWriter, r *http.Request) {
id, err := strconv.ParseInt(chi.URLParam(r, "id"), 10, 64)
if err != nil {
http.Error(w, "invalid id", http.StatusBadRequest)
return
}
user, err := h.users.GetUser(r.Context(), id)
if errors.Is(err, ErrNotFound) {
http.Error(w, "not found", http.StatusNotFound)
return
}
if err != nil {
h.logger.ErrorContext(r.Context(), "get user", "error", err)
http.Error(w, "internal error", http.StatusInternalServerError)
return
}
json.NewEncoder(w).Encode(user)
}Project Layout
myservice/
├── cmd/
│ └── server/main.go # Entry point — wire dependencies
├── internal/
│ ├── domain/ # Business logic, types, interfaces
│ ├── handler/ # HTTP handlers
│ ├── repository/ # Database implementations
│ └── service/ # Use cases / application logic
├── pkg/ # Reusable public packages
├── migrations/ # SQL migrations
├── go.mod
└── go.sumTesting Standards
// ✅ Table-driven tests
func TestUserService_GetUser(t *testing.T) {
tests := []struct {
name string
id int64
wantErr error
}{
{"found", 1, nil},
{"not found", 999, ErrNotFound},
{"zero id", 0, ErrInvalidID},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
svc := NewUserService(NewMockRepo())
_, err := svc.GetUser(context.Background(), tt.id)
if !errors.Is(err, tt.wantErr) {
t.Errorf("GetUser(%d) error = %v, want %v", tt.id, err, tt.wantErr)
}
})
}
}Quality Checklist
Before completing Go work, verify:
- All errors are handled and wrapped with context
context.Contextis first param in all I/O functions- Goroutines have deterministic lifetimes (no goroutine leaks)
- Interfaces defined in consumer, not implementer
deferused for cleanup (file close, lock unlock, span end)- No package-level mutable state
- Tests use table-driven format
golangci-lintpasses- No use of
panicin library code
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

