Skip to content

refactor: simplify NewConfig signature, add Configuration.Close#305

Open
meling wants to merge 5 commits intofeature/297/with-server-remove-server-newconfigfrom
feature/298/simplify-newconfig-signature
Open

refactor: simplify NewConfig signature, add Configuration.Close#305
meling wants to merge 5 commits intofeature/297/with-server-remove-server-newconfigfrom
feature/298/simplify-newconfig-signature

Conversation

@meling
Copy link
Member

@meling meling commented Mar 25, 2026

Summary

Previously, creating a configuration required two separate steps: create a *Manager, then call NewConfiguration(mgr, nodes).
This simplifies the API to a single constructor:

cfg, err := gorums.NewConfig(
    gorums.WithNodeList(addrs),
    gorums.WithDialOptions(grpc.WithTransportCredentials(insecure.NewCredentials())),
)

The manager is created internally and owned by the configuration.
Configuration.Close() is added to close all node connections and release resources.

Changes

  • NewConfig(nodes NodeListOption, opts ...DialOption) (Configuration, error) — new simplified constructor
  • Configuration.Close() error — closes the owning manager and all node connections
  • Mark old two-step pattern deprecated in preparation for removal

Related

Part of #294
Closes #298

meling added 5 commits March 24, 2026 16:41
Renames the exported option type from ManagerOption to DialOption,
aligning with gRPC conventions (grpc.DialOption) and the existing
ServerOption / CallOption naming pattern.

A deprecated type alias (type ManagerOption = DialOption) is added
temporarily so that existing generated *_gorums.pb.go files continue to
compile until they are regenerated in a follow-up commit.

Closes #295. Related to #294.
Renames the exported Manager type to outboundManager and the exported
NewManager constructor to newOutboundManager, hiding the connection-pool
type from the public API.

A deprecated type alias (type Manager = outboundManager) and a deprecated
NewManager wrapper are added temporarily to keep existing callers and
generated *_gorums.pb.go files compilable until they are updated in
follow-up commits.

Internal test helpers (TestManager, getOrCreateManager) and testopts are
updated to reference *outboundManager directly.

Closes #296. Related to #294.
Exports gorums.WithServer(srv *Server) DialOption as the canonical way
to wire a Server as the back-channel handler when creating a client
Configuration. This replaces the internal withRequestHandler call that
was previously hidden inside (*Server).NewConfig.

(*Server).NewConfig is removed; callers that used it, e.g.
system_test.go, are updated to use gorums.NewConfig with
gorums.WithServer(srv).

Closes #297. Related to #294.
Changes NewConfig(opts ...Option) to NewConfig(nodes NodeListOption,
opts ...DialOption), making the required NodeListOption explicit and
aligning with standard Go API conventions (required args first).

Additional changes:
- Add Configuration.Close() error for closing connections without
  accessing the internal Manager directly.
- Add unexported Configuration.mgr() used by Extend and Add internally.
- Deprecate Configuration.Manager() in favor of Configuration.Close().
- Deprecate NewConfiguration; callers should use NewConfig instead.
- Remove Manager, NewManager, NewConfiguration from generated code
  template; update NewConfig wrapper to the new signature.
- Remove Manager from the reservedIdents list.

NOTE: Existing generated files still call the old gorums.NewConfig
signature and will fail to compile until regenerated in commit 6.

Closes #298. Related to #294.
Changes NewConfig(opts ...Option) to NewConfig(nodes NodeListOption,
opts ...DialOption), making the required NodeListOption explicit and
aligning with standard Go API conventions (required args first).

Additional changes:
- Add Configuration.Close() error for closing connections without
  accessing the internal Manager directly.
- Add unexported Configuration.mgr() used by Extend and Add internally.
- Deprecate Configuration.Manager() in favor of Configuration.Close().
- Deprecate NewConfiguration; callers should use NewConfig instead.
- Remove Manager, NewManager, NewConfiguration from generated code
  template; update NewConfig wrapper to the new signature.
- Remove Manager from the reservedIdents list.

NOTE: Existing generated files still call the old gorums.NewConfig
signature and will fail to compile until regenerated in commit 6.

Closes #298. Related to #294.
@deepsource-io
Copy link
Contributor

deepsource-io bot commented Mar 25, 2026

DeepSource Code Review

We reviewed changes in 7a8369c...d5148e3 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
Go Mar 25, 2026 7:56a.m. Review ↗
Shell Mar 25, 2026 7:56a.m. Review ↗

@meling meling force-pushed the feature/297/with-server-remove-server-newconfig branch from 7a8369c to dfa23d4 Compare March 25, 2026 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant