How elisasre/go-common works
Project type and purpose
• This is a shared Golang utility library (not a running app), meant to be imported into Elisa SRE services.
• It provides common building blocks: authentication, HTTP helpers, logging, metrics, middleware, service modules, SQL utilities, etc.
File structure
• Top‐level “v2” directory houses all Go code, organized by feature area:
• auth (token management, stores, caching)
• clienv (environment config)
• httputil (HTTP request helpers)
• log (structured logging)
• metrics (counters, gauges)
• mfa (multi‐factor auth helpers)
• middleware (CSRF, rate-limit)
• netutil (TCP helpers)
• sentryutil (error reporting)
• service/module (pluggable service lifecycles: HTTP server, cron, leader election, tracing, watcher, signal handling, etc.)
• sqlutil & sqlxutil (database drivers, IAM auth)
• utils.go, must.go (misc helpers)
• There are also integrationtest and golden test harnesses, plus magefiles for build tasks.
Extract insights from the README
• Confirms purpose as a common Golang library for shared SRE code.
Sketch the main components and their relationships
a. Main Components
• Client‐side configuration: clienv
• Core utilities: utils, must
• Authentication: auth (with cache + stores) + mfa
• HTTP helpers: httputil + middleware
• Logging & Observability: log + metrics + sentryutil + service/module/tracerprovider/prom
• Service framework: service/module (HTTP server, cronrunner, siglistener, leaderelection, ticker, watcher)
• Networking: netutil
• Database: sqlutil + sqlxutil
• Integration Tests: integrationtest (external Docker Compose)
b. Relationships & Interactions
• A consuming service → imports clienv to load config → uses service/module to wire up lifecycle → registers HTTP handlers (httputil + middleware) → logs via log → reports metrics via metrics/prom → captures errors via sentryutil → relies on auth for token checks → persists data via sqlxutil/sqlutil → uses netutil for TCP operations → uses mfa for step-up auth.
• Integrationtest sits outside runtime flow but depends on service modules + Docker.
c. Architectural Patterns
• Modular, layered library: utilities at the bottom, then cross-cutting concerns (auth, HTTP, logging), then service modules on top.
• “Plug-and-play” modules: each service module implements a common interface and can be composed.
• Separation of concerns: auth stores vs cache vs token logic.
d. Key Technologies & Frameworks
• Go modules (v2)
• PostgreSQL (auth store)
• Docker Compose (integration tests)
• Mage for build automation
Detailed checklist
• Optionally, annotate common interfaces (e.g., “module.Module”).