Posts tagged Go
Config fields that quietly turn protection off: four fixes from gortexa
Empty values, "*" and custom lists can silently disable security checks. Four fixes from gortexa PR #57 are reproduced in Go.
Secret store and database write ordering: what a failure leaves behind, and how a retry resumes
Without a shared transaction, write order affects the state left after failure. SQLite examples cover secret overwrites, pending rows and retries.
Protobuf as the Single Source of Truth: Serving gRPC and HTTP/JSON from One Go Port
One .proto contract generates types and entry points for gRPC, HTTP/JSON and MCP. A Go example serves gRPC and HTTP/JSON from one h2c port and shows where shared timeouts break streams.
Batching ClickHouse Inserts: A Queue and Go Worker, Async Inserts and Deduplicated Retries
I prefer a queue and Go worker to control ClickHouse batching. Async inserts suit clients that cannot batch; retries depend on deduplication and its limits.
After RFC 10017, the First Reason for a BFF Is Keeping Tokens Out of the Browser
RFC 10017 ranks the BFF first for browser OAuth security because tokens stay on the server. Settle token storage before working on aggregation.
Unpredictable Game RNG in Production, Replayable in Tests: Separating the Two in Go
Use a Source interface to keep production RNG unpredictable and tests reproducible. Covers HMAC-seeded ChaCha8, recorded draws for disputes and an AES-CTR deadlock.
What an HMAC Request Signature Should Cover: Method, Path, Query and the Raw Body
Sign only the body and the path or query can be swapped freely; re-serialise JSON before verifying and honest requests fail. Cover the method, path, sorted query and raw body bytes.
Treat Unset as Zero: Hard Caps, Approval Thresholds and Which Way a Kill Switch Fails
Defaults decide what a money system does when a setting is missing or unreadable: reject out-of-range amounts, treat an unset approval threshold as zero, and fail closed on writes only.
The Six Things We Didn't Build: What the Framework Teaches
Six things gortex deliberately left unbuilt, from a full graceful-shutdown chain to OpenAPI generation, and the principles the whole series teaches.
The Security Middleware Suite: CORS / CSRF / JWT / Rate Limit / Binder
Gortex keeps body caps, CORS, CSRF, JWT, rate limiting and log redaction at framework level; JWT is pinned to HS256 and per-IP limiting behind a proxy needs TrustedProxies.
Observability: Three-State Health Checks and a Tracing Abstraction
Gortex health checks report Healthy, Degraded or Unhealthy, adding a degraded state beyond up/down; tracing depends on one Tracer interface, with OTel as an adapter.
The WebSocket Hub: Go's Take on the Actor Model
Gortex's WebSocket Hub is the actor model in Go: one goroutine owns all state, callers reach it over channels instead of locks, and slow consumers are dropped.
Concurrent Counting and Resilience: Sharded Metrics and a Circuit Breaker
How gortex shards one metrics lock into sixteen, counts with atomics, keeps a three-state circuit breaker consistent, and why a channel is the wrong tool here.
The Zero-Allocation Secret: Context Pool and smartParams
How gortex's routing hot path reaches 0 allocs/op: sync.Pool Context reuse, a [4]string smartParams, an embedded responseWriter, and how to measure it.
The Segment-Trie Router: Matching Without Regex
Gortex routes with a segment trie, not regex: string splitting plus map lookups, O(segments) when no backtracking is needed, static > param > wildcard precedence, no allocations.
Struct-Tag Routing: reflect in Practice
How gortex builds its route table from struct tags with reflect: method names pick the verb, middleware inherits down groups, and bad config fails at startup.
Why Build a Kitchen-Sink Framework
Why gortex is a kitchen-sink framework: what a framework layer trades away once the goal shifts from one lean microservice to consistency across services.
Memory and Sync Primitives
Go zero-allocation needs escape analysis, sync.Pool reuse and the right primitive: atomic for one value, Mutex for a block of state, RWMutex if reads dominate.
Goroutines and Channels
Goroutines are cheap but leak without an exit, channels synchronise, and one goroutine owning state needs no lock. Plain counters want a mutex or atomic.
Interfaces and Composition
Go interfaces are satisfied implicitly: small interfaces and embedding replace inheritance, and an adapter behind an interface keeps implementations swappable.
Struct Tags and reflect
reflect reads Go struct tags at runtime. Lookup tells an empty tag from a missing one; reflect is slow and panics, so keep it at startup, off the hot path.
net/http and the Middleware Pattern
Most Go web frameworks (Gin, Echo, chi) sit on net/http: http.Handler and ServeHTTP are the only abstraction, and middleware is a closure wrapping a Handler, outermost first.