Skip to content
Back to skills

Go Services

ASecurity

Write idiomatic Go services: errors, context, goroutines, interfaces, table tests and the race detector

  • 5 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 30, 2026
developmentgobash

Works with

  • cli

Security analysis

A100/100

Scanned November 30, 2026

npx -y skills add AdityaaaTiwari/ANVIL --skill go-services --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Go Services?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Go Services
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/adityaaatiwari-go-services/badge)](https://www.skillsdirectory.com/skills/adityaaatiwari-go-services)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: go-services
description: "Write idiomatic Go services: errors, context, goroutines, interfaces, table tests and the race detector"
---

<!-- Generated by `anvil plugin build` from catalog/. Edit the catalog, not this file. -->

# Go services

Use in modules with `go.mod`.

## Errors
- Return errors; do not panic for expected failures. Wrap with context: `fmt.Errorf("load user %d: %w", id, err)`.
- Compare with `errors.Is` / `errors.As`, never by string.
- Handle every error or explicitly discard it with a comment explaining why.

## Context and concurrency
- Accept `ctx context.Context` as the first parameter of anything that does I/O, and pass it down. Respect cancellation in loops.
- Every goroutine needs a clear owner and exit condition. Use `errgroup.WithContext` for fan-out with cancellation.
- Protect shared state with a mutex or confine it to one goroutine; check with `go test -race`.
- Close resources with `defer` right after a successful open (`defer rows.Close()`), and check `rows.Err()` after iterating.

## Design
- Accept interfaces, return concrete types. Define small interfaces where they are consumed.
- Keep `main` thin: parse config, wire dependencies, start the server, handle shutdown with `signal.NotifyContext`.
- HTTP servers need timeouts (`ReadHeaderTimeout`, `ReadTimeout`, `WriteTimeout`); `http.ListenAndServe` with no server struct has none.
- Outbound HTTP: reuse one `http.Client` with a timeout, and always close response bodies.

## Tests
Table-driven tests with `t.Run(tc.name, ...)`, `t.Helper()` in helpers, `t.TempDir()` for files, and `httptest` for handlers.

## Verify
```bash
gofmt -l . && go vet ./...
go test -race ./...
```
Plus `golangci-lint run` or `staticcheck ./...` if the repo configures them.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.