|
| 1 | +# Migration: go-cli-builder v3, go-foundation v2, go-warp |
| 2 | + |
| 3 | +Branch: `migrate/foundation-v2-cli-builder-v3-warp` (commit `5b1a157`). |
| 4 | + |
| 5 | +## What changed |
| 6 | + |
| 7 | +### go-cli-builder v3 — `internal/cli/cli.go` |
| 8 | + |
| 9 | +cobra was replaced by declarative struct-tag commands. Every command, |
| 10 | +flag, short name and exit code is preserved: |
| 11 | + |
| 12 | +- `generate [domain]`, `gen-pass [password]`, `start`, `start-web`, |
| 13 | + `start-dns`, `validate`, `list`, `plugins`, `stop`, `restart`, `version` |
| 14 | +- global flags `--config/-c` and `--global-config` (parsed on the root, |
| 15 | + exposed to subcommands the same way cobra PersistentFlags did) |
| 16 | +- `--tui/-t` and `--bench/-b` on `start` |
| 17 | +- `--version` flag on the root plus the `version` subcommand |
| 18 | +- `Before()` on the root replaces cobra's `PersistentPreRun` (global config |
| 19 | + load before any subcommand) |
| 20 | + |
| 21 | +### go-foundation v2 — `internal/logger/logger.go` |
| 22 | + |
| 23 | +zerolog was removed from `go.mod`. The logger now runs on |
| 24 | +`go-foundation/v2/core/logger` with two custom sinks: |
| 25 | + |
| 26 | +- `jsonWriterSink`: one JSON object per line on the date-partitioned |
| 27 | + rotating file writer (unchanged `YYYY/MM/DD*.log` layout) |
| 28 | +- `consoleSink`: colored human-readable lines on stdout (termenv kept) |
| 29 | + |
| 30 | +The public API (`NewLogger`, `NewPluginLogger`, `NewSystemLogger`, |
| 31 | +`Info/Infof/Error/...`, `WithFields`, `SetOutput`, `Writer`) is unchanged, |
| 32 | +so the ~20 call sites in `internal/` and `plugins/` needed no edits. |
| 33 | + |
| 34 | +`plugins/contracts.go` adds compile-time conformance of all 7 plugins to |
| 35 | +`plugin.Plugin` via `contracts.Assert`, so a broken plugin surface fails the |
| 36 | +build instead of registration. |
| 37 | + |
| 38 | +### go-warp v1.2.2 — `internal/server/stat_cache.go` |
| 39 | + |
| 40 | +The hand-rolled `sync.Map` + atomic swap stat cache was replaced by |
| 41 | +`go-warp/v1/cache.NewInMemory` with `WithMaxEntries(65536)` and a 1s TTL. |
| 42 | +TTL expiry, LRU eviction and the max-entries bound are now handled by the |
| 43 | +framework. `resetStatCache` (used by tests) recreates the cache. |
| 44 | + |
| 45 | +## v2.3.2: configuration and vhost dispatch (second pass) |
| 46 | + |
| 47 | +After `go-foundation` v2.3.2 added the missing capabilities, the remaining |
| 48 | +gaps closed: |
| 49 | + |
| 50 | +### `internal/config` — configuration collections |
| 51 | + |
| 52 | +- `LoadAllConfigs` discovers site files through |
| 53 | + `configuration/source/dir` (glob `*.json`, `conf.global.json` excluded by |
| 54 | + the provider) and decodes each with the existing strict `LoadConfig`, so |
| 55 | + unknown fields keep failing as before. |
| 56 | +- `ValidateAll` now expresses its two failure modes as Foundation collection |
| 57 | + rules: `SiteConfig.Validate` is the per-file `ItemValidator` (file name is |
| 58 | + the entry name) and duplicate-domain / SSL-port-conflict checks are |
| 59 | + `CrossValidator`s. `ValidateCollection` aggregates all problems in one |
| 60 | + pass. CLI output shape unchanged. |
| 61 | + |
| 62 | +### `internal/server` — virtual host dispatch and SNI |
| 63 | + |
| 64 | +- `startVirtualHostServer` dropped the hand-rolled radix tree for |
| 65 | + `httpx.VHostMux` (normalized host matching, configurable fallback). The |
| 66 | + first registered handler stays the fallback for unknown hosts, preserving |
| 67 | + previous behavior. `github.com/armon/go-radix` is gone from `go.mod`. |
| 68 | +- `setupTLS` loads static certificates into `httpx.CertResolver`, which |
| 69 | + selects per-SNI; ACME hosts still fall through to the autocert manager. |
| 70 | + Host normalization is shared between mux and resolver. |
| 71 | + |
| 72 | +### Still not migrated |
| 73 | + |
| 74 | +`app` / `app/web` (action-based HTTP): GoUp *is* the server (proxy, plugins, |
| 75 | +QUIC, TUI); the action model is for building applications, not servers. |
| 76 | +DNS indexes stay as-is: pre-compiled at startup, no TTL hot path. |
| 77 | + |
| 78 | +## Verification |
| 79 | + |
| 80 | +- `go build ./...` clean |
| 81 | +- `go vet ./...` clean |
| 82 | +- `go test ./...`: 9 packages ok |
| 83 | +- CLI smoke-tested: `--help`, `--version`, `version`, `validate`, `list`, |
| 84 | + `plugins`, `gen-pass` |
0 commit comments