KeiSeiKit-1.0/_blocks/stack-go-server.md
Parfii-bot a4e667de10 KeiSeiKit-public — clean state
Single-commit clean baseline after security scrub of niche-tells,
project codenames, internal jargon, and contributor-email leaks.

Contents:
- 100 Rust crates (_primitives/_rust/)
- 37 agent manifests (_manifests/) + generated specs (_generated/)
- 67 user-invocable skills (skills/)
- 33 hooks (hooks/)
- Composition blocks (_blocks/)
- Documentation (docs/, README.md)
- TS adapter packages (_ts_packages/)
- Assembler (_assembler/)
- Roles (_roles/)
- Templates (_templates/)
- Forgejo CI (.forgejo/)

Author: Denis Parfionovich <info@greendragon.info>

License: see LICENSE.
2026-05-01 12:09:03 +08:00

25 lines
1.4 KiB
Markdown

# STACK — Go server
Use when the project is Go-locked (existing codebase) or the domain fits — networking daemons, agents, cloud-native tooling.
**Modules:** `go.mod` + `go.sum` committed. Go ≥ 1.22 (range-over-func, better `slices`/`maps` stdlib).
**HTTP:** prefer `net/http` stdlib + `http.ServeMux` (Go 1.22 pattern matching routes). Add a framework (chi, echo) only when the feature gap is concrete and documented — not "for ergonomics".
**Context propagation (non-negotiable):**
- Every handler, DB call, outbound request takes `ctx context.Context` as FIRST arg.
- `ctx` threads through stack without interruption — no `context.Background()` mid-call except at the edge.
- `context.WithTimeout` on every external I/O.
**Errors:**
- Return `error`; sentinels via `errors.Is`, typed via `errors.As`. NEVER `strings.Contains(err.Error(), "...")` — string match breaks on wrapping.
- Wrap with `%w`: `fmt.Errorf("ctx: %w", err)`.
**Concurrency:**
- `go vet` + `go test -race` MANDATORY in CI.
- Channels for ownership transfer, mutexes for protecting state — not both on the same data.
- Goroutines started in handlers must have a clear lifecycle (parent ctx cancellation).
**Logging:** `log/slog` (structured). NO `fmt.Println` in prod paths.
**Forbidden:** string-match on error messages; goroutine leaks (no ctx cancellation path); `init()` doing I/O; `go test` without `-race`; `panic()` as control flow in library code.