/prometheus-skill-pack:go-base-patternsfrom prometheus-skill-pack
Canonical Go 1.22 patterns for Prometheus AGS projects. Covers error handling with %w wrapping, context propagation, interface-based dependency injection, structured logging with slog, module layout (cmd/internal/pkg), table-driven tests, and idiomatic Go patterns used across Prometheus infrastructure tooling and MCP servers.
Ships in prometheus-skill-pack. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Go errors are values. Wrap with %w to preserve the chain. Never use panic in
library code. Never swallow errors with _.
import (
"errors"
"fmt"
)
// Sentinel errors for comparison
var (
ErrNotFound = errors.New("not found")
ErrUnauthorized = errors.New("unauthorized")
)
// Wrap with context
func loadConfig(path string) (*Config, error) {
data, err := os.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("loading config from %s: %w", path, err)
}
// ...
}
// Check specific error
config, err := loadConfig(path)
if errors.Is(err, os.ErrNotExist) {
return defaultConfig(), nil
}
if err != nil {
return nil, fmt.Errorf("config initialization: %w", err)
}
Every function that does I/O, makes a network call, or can be cancelled takes
context.Context as its first parameter.
func (c *Client) FetchPost(ctx context.Context, id string) (*Post, error) {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.baseURL+"/posts/"+id, nil)
if err != nil {
return nil, fmt.Errorf("building request: %w", err)
}
resp, err := c.http.Do(req)
// ...
}
Never store context in a struct. Pass it through every call chain.
Define interfaces at the point of use, not at the point of implementation. Keep interfaces small — prefer single-method interfaces.
// Define in the package that uses it
type PostRepository interface {
FindByID(ctx context.Context, id string) (*Post, error)
List(ctx context.Context, filter PostFilter) ([]*Post, error)
Save(ctx context.Context, post *Post) error
}
// Implement separately (infrastructure)
type PostgresPostRepository struct { db *sql.DB }
func (r *PostgresPostRepository) FindByID(ctx context.Context, id string) (*Post, error) { /* ... */ }
// Compose at startup (cmd/server/main.go)
func main() {
db := mustConnectDB()
repo := &infrastructure.PostgresPostRepository{DB: db}
svc := application.NewPostService(repo)
handler := interface_layer.NewPostHandler(svc)
// ...
}
Use log/slog (stdlib since 1.21). Always include relevant context fields.
Never use fmt.Println for operational logging.
import "log/slog"
logger := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
Level: slog.LevelInfo,
}))
// With context fields
logger.Info("inference complete",
slog.String("model", model),
slog.Int("tokens", tokenCount),
slog.Duration("latency", elapsed),
)
logger.Error("inference failed",
slog.String("model", model),
slog.Any("error", err),
)
my-service/
├── cmd/
│ └── server/
│ └── main.go ← composition root, dependency wiring
├── internal/ ← private to this module
│ ├── domain/
│ │ ├── post.go ← domain entities
│ │ └── repository.go ← interfaces
│ ├── application/
│ │ └── post_service.go ← use cases
│ └── infrastructure/
│ └── postgres_repo.go ← concrete implementations
├── pkg/ ← exported shared packages (if any)
├── go.mod
└── go.sum
Use internal/ to enforce that packages are not imported from outside the module.
func TestFetchPost(t *testing.T) {
tests := []struct {
name string
id string
want *Post
wantErr error
}{
{name: "found", id: "post-1", want: &Post{ID: "post-1", Title: "Hello"}, wantErr: nil},
{name: "not found", id: "missing", want: nil, wantErr: ErrNotFound},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
repo := &mockPostRepo{posts: seedPosts()}
got, err := repo.FindByID(context.Background(), tt.id)
if !errors.Is(err, tt.wantErr) {
t.Errorf("got error %v, want %v", err, tt.wantErr)
}
// compare got vs tt.want
})
}
}
// Handler wraps the service — thin translation layer
type PostHandler struct {
svc PostService
log *slog.Logger
}
func (h *PostHandler) GetPost(w http.ResponseWriter, r *http.Request) {
id := r.PathValue("id") // Go 1.22 stdlib routing
post, err := h.svc.FetchPost(r.Context(), id)
if err != nil {
if errors.Is(err, ErrNotFound) {
http.Error(w, "not found", http.StatusNotFound)
return
}
h.log.Error("fetch post failed", slog.Any("error", err))
http.Error(w, "internal error", http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(post)
}
panic() in library code — return errorsinterface{} — use any (Go 1.18+ alias) or concrete typescontext.Context in a structresult, _ = fn() — handle or propagateinit() with side effects — use explicit initialization in mainWhat SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub prometheus-ags/prometheus-skill-system --plugin prometheus-skill-pack218 skills in this plugin
/actor-modelTokio-native actor model pattern for Prometheus AGS projects. Implements actors as tokio tasks communicating via mpsc channels with a typed message enum, enabling safe concurrent state management without shared locks. Used in UAR session management, pk-librarian event broadcasting, and parking-lot scheduler design. Use when a component needs to own state exclusively while serving concurrent callers.
/adversarial-reviewIsolated, cross-model adversarial review of KBD artifacts and change diffs. Dispatches a fresh-context LLM judge over an OpenAI-compatible REST gateway (openai-proxy or `liter-llm api`) with an explicit mandate to find problems — the model that produced an artifact or change is never the model that reviews it. Runs as a pipeline stage inside kbd-assess/analyze/plan (artifact mode) and kbd-execute's single phase-boundary QA step (diff mode, once over the whole phase diff). Findings are severity-bucketed (CRITICAL/WARNING/SUGGESTION) and the judge's own report is screened by sycophancy-correction before it is surfaced.
/agent-team-creatorCreate, revise, package, and deploy agent-team definitions with staged questions and native exports for UAR, Codex, Claude Code, Copilot, Kimi Code, MiniMax CLI, OpenCode and DeepSeek. Use for team definition and catalog lifecycle; use agent-team-manage for active runtime task state.Other plugins' skills for the same job
2 plugins in one repository ship this exact skill · first indexed Nov 27, 2026