Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8876af3bfa
|
||
|
|
c6a753e49b
|
||
|
|
f0ff3c38ed
|
+40
-5
@@ -6,13 +6,48 @@ This module adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## [1.0.1] — 2026-05-28
|
## [1.1.2] — 2026-08-08
|
||||||
|
|
||||||
|
Patch — CORS wildcard hardening plus documentation fixes.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Bumped `code.nochebuena.dev/einherjar/contracts` dependency from v1.0.0 to v1.1.0.
|
- **`mw.CORS` now rejects `"*"` (panics at construction)** instead of silently no-op'ing it.
|
||||||
No code changes — MVS selects v1.1.0 automatically when a consumer (e.g. `auth`)
|
`"*"` matched nothing (exact-match only), so a service passing it ran with CORS effectively
|
||||||
requires the new `SecurityBag` API. This pin makes the minimum explicit.
|
off — a silent trap. Fail loud at boot; use `mw.CORSAllowAll()` (development) or list explicit origins.
|
||||||
|
- Bumped `contracts`, `core` to v1.1.2.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- README Go examples now compile: `mw.Recover(logger)`, `health.NewHandler(...).ServeHTTP`, and the
|
||||||
|
`mw.CORS` example no longer passes `"*"`. Corrected the `CORSAllowAll` description.
|
||||||
|
|
||||||
|
## [1.1.1] — 2026-08-07
|
||||||
|
|
||||||
|
Patch — coordinated framework version alignment.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Bumped `contracts` and `core` to v1.1.1 (framework version alignment). No code or API changes.
|
||||||
|
|
||||||
|
## [1.1.0] — 2026-08-07
|
||||||
|
|
||||||
|
Coordinated framework release. Documentation fixes plus the framework version bump
|
||||||
|
(which finally makes the previously-drafted `contracts` v1.1.0 pin real).
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- **Package doc examples didn't compile.** Verified by compiling the example patterns
|
||||||
|
against the real API:
|
||||||
|
- `mw.Recover()` -> `mw.Recover(logger)` — the recover middleware takes a `logging.Logger`
|
||||||
|
(`server`, `mw` package docs and `server.go`).
|
||||||
|
- `health.NewHandler(logger, …)` -> `health.NewHandler(logger, …).ServeHTTP` — the handler
|
||||||
|
returns `http.Handler`, but chi's `Get` takes `http.HandlerFunc`; same for
|
||||||
|
`NewHandlerWithConfig` (`server`, `web`, `health` package docs).
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Bumped `contracts` and `core` to v1.1.0 (framework version alignment).
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -50,7 +85,7 @@ This module adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html
|
|||||||
request logging: method, path, status, latency; uses `StatusRecorder` to capture code
|
request logging: method, path, status, latency; uses `StatusRecorder` to capture code
|
||||||
- `CORS(origins []string) func(http.Handler) http.Handler` — sets
|
- `CORS(origins []string) func(http.Handler) http.Handler` — sets
|
||||||
`Access-Control-Allow-Origin` for listed origins; supports preflight (`OPTIONS`)
|
`Access-Control-Allow-Origin` for listed origins; supports preflight (`OPTIONS`)
|
||||||
- `CORSAllowAll() func(http.Handler) http.Handler` — shorthand for `CORS([]string{"*"})`
|
- `CORSAllowAll() func(http.Handler) http.Handler` — allows any origin by reflecting the request `Origin` (no `Access-Control-Allow-Credentials`); development only
|
||||||
- `RateLimiterStore` interface — `Allow(ctx context.Context, key string) (bool, error)`;
|
- `RateLimiterStore` interface — `Allow(ctx context.Context, key string) (bool, error)`;
|
||||||
pluggable backend; `error` return allows infrastructure failures to surface; fail-open
|
pluggable backend; `error` return allows infrastructure failures to surface; fail-open
|
||||||
contract: non-nil error allows the request
|
contract: non-nil error allows the request
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# einherjar/web
|
# einherjar/web
|
||||||
|
|
||||||
[](https://code.nochebuena.dev/einherjar/web)
|
[](https://code.nochebuena.dev/einherjar/web)
|
||||||
[](LICENSE)
|
[](LICENSE)
|
||||||
[](https://go.dev)
|
[](https://go.dev)
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ logger := logz.New(logz.Config{JSON: true, StaticArgs: []any{"service", "api"}})
|
|||||||
srv := web.New(logger)
|
srv := web.New(logger)
|
||||||
// Pre-wired stack: Recover → RequestID (UUID v7/v4) → RequestLogger → [CORS]
|
// Pre-wired stack: Recover → RequestID (UUID v7/v4) → RequestLogger → [CORS]
|
||||||
|
|
||||||
srv.Get("/health", health.NewHandler(logger, db, cache))
|
srv.Get("/health", health.NewHandler(logger, db, cache).ServeHTTP)
|
||||||
|
|
||||||
lc := launcher.New(logger)
|
lc := launcher.New(logger)
|
||||||
lc.Append(srv)
|
lc.Append(srv)
|
||||||
@@ -76,7 +76,7 @@ Environment variables for `web.New`:
|
|||||||
| `EINHERJAR_SERVER_WRITE_TIMEOUT` | `10s` | HTTP write timeout |
|
| `EINHERJAR_SERVER_WRITE_TIMEOUT` | `10s` | HTTP write timeout |
|
||||||
| `EINHERJAR_SERVER_IDLE_TIMEOUT` | `120s` | Keep-alive idle timeout |
|
| `EINHERJAR_SERVER_IDLE_TIMEOUT` | `120s` | Keep-alive idle timeout |
|
||||||
| `EINHERJAR_SERVER_SHUTDOWN_TIMEOUT` | `10s` | Graceful shutdown budget |
|
| `EINHERJAR_SERVER_SHUTDOWN_TIMEOUT` | `10s` | Graceful shutdown budget |
|
||||||
| `EINHERJAR_SERVER_CORS_ORIGINS` | _(empty — CORS off)_ | Comma-separated allowed origins |
|
| `EINHERJAR_SERVER_CORS_ORIGINS` | _(empty — CORS off)_ | Comma-separated allowed origins (`*` is rejected — use `mw.CORSAllowAll()` in code for allow-all) |
|
||||||
|
|
||||||
### Tier 2 — Full control (`server.New`)
|
### Tier 2 — Full control (`server.New`)
|
||||||
|
|
||||||
@@ -90,9 +90,9 @@ import (
|
|||||||
|
|
||||||
srv := server.New(logger, server.Config{Port: 9090},
|
srv := server.New(logger, server.Config{Port: 9090},
|
||||||
server.WithMiddleware(
|
server.WithMiddleware(
|
||||||
mw.Recover(),
|
mw.Recover(logger),
|
||||||
mw.RequestID(myIDGenerator),
|
mw.RequestID(myIDGenerator),
|
||||||
mw.CORS([]string{"*"}),
|
mw.CORS([]string{"https://example.com"}),
|
||||||
mw.RequestLogger(logger),
|
mw.RequestLogger(logger),
|
||||||
myOwnMiddleware,
|
myOwnMiddleware,
|
||||||
),
|
),
|
||||||
@@ -177,7 +177,7 @@ values are mapped to their canonical HTTP status codes (full 16-code table below
|
|||||||
import "code.nochebuena.dev/einherjar/web/health"
|
import "code.nochebuena.dev/einherjar/web/health"
|
||||||
|
|
||||||
// db and cache implement observability.Checkable
|
// db and cache implement observability.Checkable
|
||||||
srv.Get("/health", health.NewHandler(logger, db, cache))
|
srv.Get("/health", health.NewHandler(logger, db, cache).ServeHTTP)
|
||||||
|
|
||||||
// Response shape:
|
// Response shape:
|
||||||
// {"status":"UP","components":{"db":{"status":"UP","latency":"1.2ms"}}}
|
// {"status":"UP","components":{"db":{"status":"UP","latency":"1.2ms"}}}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
// lc := launcher.New(logger)
|
// lc := launcher.New(logger)
|
||||||
//
|
//
|
||||||
// srv := web.New(logger)
|
// srv := web.New(logger)
|
||||||
// srv.Get("/health", health.NewHandler(logger, db, cache))
|
// srv.Get("/health", health.NewHandler(logger, db, cache).ServeHTTP)
|
||||||
//
|
//
|
||||||
// lc.Append(srv)
|
// lc.Append(srv)
|
||||||
// lc.BeforeStart(func() error {
|
// lc.BeforeStart(func() error {
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ module code.nochebuena.dev/einherjar/web
|
|||||||
go 1.26
|
go 1.26
|
||||||
|
|
||||||
require (
|
require (
|
||||||
code.nochebuena.dev/einherjar/contracts v1.0.0
|
code.nochebuena.dev/einherjar/contracts v1.1.2
|
||||||
code.nochebuena.dev/einherjar/core v1.0.0
|
code.nochebuena.dev/einherjar/core v1.1.2
|
||||||
github.com/go-chi/chi/v5 v5.2.1
|
github.com/go-chi/chi/v5 v5.2.1
|
||||||
github.com/google/uuid v1.6.0
|
github.com/google/uuid v1.6.0
|
||||||
golang.org/x/time v0.11.0
|
golang.org/x/time v0.11.0
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
code.nochebuena.dev/einherjar/contracts v1.0.0 h1:hRudEtOIqU7vwedYLsCh8+9q5dCnKb61qX+zibqImRU=
|
code.nochebuena.dev/einherjar/contracts v1.1.2 h1:LNAFCKQjpNjkCyMid2AgkhDPPzOx8dvpRqqZ7F3zpo0=
|
||||||
code.nochebuena.dev/einherjar/contracts v1.0.0/go.mod h1:ccltUtrFb5+MEJdkx2VVEUL+xC5pupVlVVsMM8AlCWI=
|
code.nochebuena.dev/einherjar/contracts v1.1.2/go.mod h1:ccltUtrFb5+MEJdkx2VVEUL+xC5pupVlVVsMM8AlCWI=
|
||||||
code.nochebuena.dev/einherjar/core v1.0.0 h1:AueZgfjp3+rQmDKOxmJQ945TTh+sqC1l/xJdTOdbr9w=
|
code.nochebuena.dev/einherjar/core v1.1.2 h1:iYU2fIWtnyOYFbTMD92NaLJMye4XgZHXWhEjB3iS7lo=
|
||||||
code.nochebuena.dev/einherjar/core v1.0.0/go.mod h1:0IywfRnJXX9xXQO6iPVaq2QDlXbbpXrB8A4T7gO8nE4=
|
code.nochebuena.dev/einherjar/core v1.1.2/go.mod h1:Y7qZ9nri9Ydey3+40yz75KErOvOUjRSoffdykXbncsw=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/gabriel-vasile/mimetype v1.4.12 h1:e9hWvmLYvtp846tLHam2o++qitpguFiYCKbn0w9jyqw=
|
github.com/gabriel-vasile/mimetype v1.4.12 h1:e9hWvmLYvtp846tLHam2o++qitpguFiYCKbn0w9jyqw=
|
||||||
|
|||||||
+2
-2
@@ -12,12 +12,12 @@
|
|||||||
//
|
//
|
||||||
// # Example
|
// # Example
|
||||||
//
|
//
|
||||||
// srv.Get("/health", health.NewHandler(logger, db, cache, storage))
|
// srv.Get("/health", health.NewHandler(logger, db, cache, storage).ServeHTTP)
|
||||||
//
|
//
|
||||||
// Or with custom timeout:
|
// Or with custom timeout:
|
||||||
//
|
//
|
||||||
// srv.Get("/health", health.NewHandlerWithConfig(logger,
|
// srv.Get("/health", health.NewHandlerWithConfig(logger,
|
||||||
// health.Config{CheckTimeout: 3 * time.Second},
|
// health.Config{CheckTimeout: 3 * time.Second},
|
||||||
// db, cache,
|
// db, cache,
|
||||||
// ))
|
// ).ServeHTTP)
|
||||||
package health
|
package health
|
||||||
|
|||||||
@@ -11,6 +11,15 @@ const (
|
|||||||
// Returns 204 No Content for OPTIONS preflight requests.
|
// Returns 204 No Content for OPTIONS preflight requests.
|
||||||
// Pass the outermost origins first; an empty slice is a no-op.
|
// Pass the outermost origins first; an empty slice is a no-op.
|
||||||
func CORS(origins []string) func(http.Handler) http.Handler {
|
func CORS(origins []string) func(http.Handler) http.Handler {
|
||||||
|
// "*" is a silent no-op here (exact-match only) — reject it loudly at
|
||||||
|
// construction so a misconfigured service fails to boot instead of quietly
|
||||||
|
// blocking every browser. For allow-all, call CORSAllowAll (development only).
|
||||||
|
for _, o := range origins {
|
||||||
|
if o == "*" {
|
||||||
|
panic(`mw.CORS: "*" is not a valid origin — list explicit origins, or use CORSAllowAll() for allow-all`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
originSet := make(map[string]struct{}, len(origins))
|
originSet := make(map[string]struct{}, len(origins))
|
||||||
for _, o := range origins {
|
for _, o := range origins {
|
||||||
originSet[o] = struct{}{}
|
originSet[o] = struct{}{}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
// # Recommended middleware order (outermost first)
|
// # Recommended middleware order (outermost first)
|
||||||
//
|
//
|
||||||
// server.WithMiddleware(
|
// server.WithMiddleware(
|
||||||
// mw.Recover(),
|
// mw.Recover(logger),
|
||||||
// mw.RequestID(uuid.NewString),
|
// mw.RequestID(uuid.NewString),
|
||||||
// mw.RequestLogger(logger),
|
// mw.RequestLogger(logger),
|
||||||
// mw.CORS([]string{"https://example.com"}),
|
// mw.CORS([]string{"https://example.com"}),
|
||||||
|
|||||||
+2
-2
@@ -12,14 +12,14 @@
|
|||||||
//
|
//
|
||||||
// srv := server.New(logger, server.Config{Port: 8080},
|
// srv := server.New(logger, server.Config{Port: 8080},
|
||||||
// server.WithMiddleware(
|
// server.WithMiddleware(
|
||||||
// mw.Recover(),
|
// mw.Recover(logger),
|
||||||
// mw.RequestID(myIDGenerator),
|
// mw.RequestID(myIDGenerator),
|
||||||
// mw.RequestLogger(logger),
|
// mw.RequestLogger(logger),
|
||||||
// mw.CORS([]string{"https://example.com"}),
|
// mw.CORS([]string{"https://example.com"}),
|
||||||
// ),
|
// ),
|
||||||
// )
|
// )
|
||||||
//
|
//
|
||||||
// srv.Get("/health", health.NewHandler(logger, db))
|
// srv.Get("/health", health.NewHandler(logger, db).ServeHTTP)
|
||||||
//
|
//
|
||||||
// lc := launcher.New(logger)
|
// lc := launcher.New(logger)
|
||||||
// lc.Append(srv)
|
// lc.Append(srv)
|
||||||
|
|||||||
+1
-1
@@ -7,7 +7,7 @@
|
|||||||
//
|
//
|
||||||
// srv := server.New(logger, server.Config{Port: 8080},
|
// srv := server.New(logger, server.Config{Port: 8080},
|
||||||
// server.WithMiddleware(
|
// server.WithMiddleware(
|
||||||
// mw.Recover(),
|
// mw.Recover(logger),
|
||||||
// mw.RequestID(uuid.NewString),
|
// mw.RequestID(uuid.NewString),
|
||||||
// mw.RequestLogger(logger),
|
// mw.RequestLogger(logger),
|
||||||
// ),
|
// ),
|
||||||
|
|||||||
Reference in New Issue
Block a user