refactor(config,adminclient): functional options for NewService + New#249
Merged
Merged
Conversation
Continues the refactor sweep from #235 / #236, completing the candidates flagged during the original survey. - config.NewService(store, cache, publisher, subscriber, opts...) — the four required dependencies are positional; Logger, CacheMetrics, Metrics, Validators, and Recorder become With...() options. The ServiceConfig struct is removed. - adminclient.New(opts...) — all four transports (Schema, Config, Audit, Server) are independently optional per the existing nil-allowed contract, so the constructor takes no positional args. Replaces scattered `nil, nil, nil` placeholders at call sites. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
6 tasks
zeevdr
added a commit
that referenced
this pull request
Apr 29, 2026
…Service (#254) Lands the first half of #217: bound schema document size and field count at CreateSchema / ImportSchema, so a single malicious import cannot exhaust the server before validator caching helps. Compile-timeout for the JSON-Schema compiler ships in the stacked follow-up #255. - internal/schema/limits.go — new Limits struct (MaxFields, MaxDocBytes) + DefaultLimits (10 000 fields, 5 MiB). - schema.NewService(store, opts...) — store stays positional; logger, metrics, validators, and limits move to With...() options. Mirrors the config / audit / auth / server functional-options sweep from #235, #236, #249. - ImportSchema rejects YAML payloads above MaxDocBytes before parsing, and CreateSchema / ImportSchema reject schemas above MaxFields after parsing. Zero on either dimension means unlimited. - cmd/server reads SCHEMA_MAX_FIELDS and SCHEMA_MAX_DOC_BYTES env vars and threads them through WithLimits. Both documented in docs/server/configuration.md. Refs #217.
This was referenced Apr 30, 2026
zeevdr
added a commit
that referenced
this pull request
May 1, 2026
) PRs #235, #236, #249, #254 replaced struct-config constructors with functional options across server, gateway, audit, auth, config, adminclient, and schema. The Config / ServiceConfig / RecorderConfig / GatewayConfig structs are removed without backward-compat shims (alpha). This document records before/after for each affected constructor and the list of With...() options, so SDK consumers and embedders know what to update when bumping versions. Closes #275 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
zeevdr
added a commit
that referenced
this pull request
May 1, 2026
The functional-options refactors (PR #235 server, #236 audit/auth, #249 config/adminclient, #254 schema) made every constructor in cmd/server/main.go take a list of With...() options derived from env vars + cfg flags. The wiring had no tests, so the bug class "flag is read but never wired into an option" was silent. Extract the server + gateway option-construction logic into pure helpers (buildServerOptions, buildGatewayOptions) that return both the option slice and a small struct describing the boolean decisions (UseTLS, UseInsecure, HasRateLimiter). Tests assert on the decisions, catching the silent-default bug class without inspecting opaque option closures. Cases covered: TLS vs Insecure (server + gateway); rate limiter wired when non-nil and absent when nil; extra grpc.ServerOptions are folded into a single WithGRPCServerOptions and don't inflate the option slice. Closes #284 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
zeevdr
added a commit
that referenced
this pull request
May 1, 2026
) (#323) PRs #235, #236, #249, #254 replaced struct-config constructors with functional options across server, gateway, audit, auth, config, adminclient, and schema. The Config / ServiceConfig / RecorderConfig / GatewayConfig structs are removed without backward-compat shims (alpha). This document records before/after for each affected constructor and the list of With...() options, so SDK consumers and embedders know what to update when bumping versions. Closes #275 Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
zeevdr
added a commit
that referenced
this pull request
May 1, 2026
…325) The functional-options refactors (PR #235 server, #236 audit/auth, #249 config/adminclient, #254 schema) made every constructor in cmd/server/main.go take a list of With...() options derived from env vars + cfg flags. The wiring had no tests, so the bug class "flag is read but never wired into an option" was silent. Extract the server + gateway option-construction logic into pure helpers (buildServerOptions, buildGatewayOptions) that return both the option slice and a small struct describing the boolean decisions (UseTLS, UseInsecure, HasRateLimiter). Tests assert on the decisions, catching the silent-default bug class without inspecting opaque option closures. Cases covered: TLS vs Insecure (server + gateway); rate limiter wired when non-nil and absent when nil; extra grpc.ServerOptions are folded into a single WithGRPCServerOptions and don't inflate the option slice. Closes #284 Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Completes the functional-options sweep from #235 / #236 by revisiting the two candidates I dropped from the original survey on closer reading. Both turned out to fit the "required positional, optional via
With...()" rule:config.NewService(store, cache, publisher, subscriber, opts...)— the four required dependencies stay positional;Logger,CacheMetrics,Metrics,Validators, andRecorderare nil-safe (or default toslog.Default()) and becomeWith...()options. TheServiceConfigstruct is removed.adminclient.New(opts...)— all four transports (Schema, Config, Audit, Server) are independently optional per the long-standing nil-allowed contract (methods on a nil-transport service returnErrServiceNotConfigured). The constructor takes no positional args and thenil, nil, nilplaceholders disappear from call sites:Test plan
make test— all packages green (race, count=1)golangci-lint run ./...— 0 issuesgo vet ./...,gofumpt -l .— clean./scripts/check-coverage.sh— all modules meet thresholds (sdk/adminclient ticked up 97.6 → 97.8)🤖 Generated with Claude Code