Skip to content

refactor(config,adminclient): functional options for NewService + New#249

Merged
zeevdr merged 1 commit into
mainfrom
refactor/config-adminclient-functional-options
Apr 29, 2026
Merged

refactor(config,adminclient): functional options for NewService + New#249
zeevdr merged 1 commit into
mainfrom
refactor/config-adminclient-functional-options

Conversation

@zeevdr
Copy link
Copy Markdown
Member

@zeevdr zeevdr commented Apr 29, 2026

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, and Recorder are nil-safe (or default to slog.Default()) and become With...() options. The ServiceConfig struct 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 return ErrServiceNotConfigured). The constructor takes no positional args and the nil, nil, nil placeholders disappear from call sites:

    // Before
    admin := adminclient.New(nil, nil, ma, nil)
    // After
    admin := adminclient.New(adminclient.WithAuditTransport(ma))

Test plan

  • make test — all packages green (race, count=1)
  • golangci-lint run ./... — 0 issues
  • go vet ./..., gofumpt -l . — clean
  • ./scripts/check-coverage.sh — all modules meet thresholds (sdk/adminclient ticked up 97.6 → 97.8)
  • CI green

🤖 Generated with Claude Code

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>
@zeevdr zeevdr merged commit 4153cd7 into main Apr 29, 2026
19 checks passed
@zeevdr zeevdr deleted the refactor/config-adminclient-functional-options branch April 29, 2026 10:26
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.
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>
@zeevdr zeevdr added enhancement New feature or request server Server changes sdk SDK changes size: M Moderate — a day or two, clear scope priority: P2 Nice-to-have labels May 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request priority: P2 Nice-to-have sdk SDK changes server Server changes size: M Moderate — a day or two, clear scope

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant