Skip to content

Commit

Permalink
make param optional in client
Browse files Browse the repository at this point in the history
  • Loading branch information
felipemadero committed Mar 21, 2022
1 parent ce13a19 commit 8670c84
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Config struct {

type Client interface {
Ping(ctx context.Context) (*rpcpb.PingResponse, error)
Start(ctx context.Context, execPath string, numNodes uint32, opts ...OpOption) (*rpcpb.StartResponse, error)
Start(ctx context.Context, execPath string, opts ...OpOption) (*rpcpb.StartResponse, error)
Health(ctx context.Context) (*rpcpb.HealthResponse, error)
URIs(ctx context.Context) ([]string, error)
Status(ctx context.Context) (*rpcpb.StatusResponse, error)
Expand Down Expand Up @@ -92,14 +92,14 @@ func (c *client) Ping(ctx context.Context) (*rpcpb.PingResponse, error) {
return c.pingc.Ping(ctx, &rpcpb.PingRequest{})
}

func (c *client) Start(ctx context.Context, execPath string, numNodes uint32, opts ...OpOption) (*rpcpb.StartResponse, error) {
ret := &Op{}
func (c *client) Start(ctx context.Context, execPath string, opts ...OpOption) (*rpcpb.StartResponse, error) {
ret := &Op{numNodes: local.defaultNumNodes}
ret.applyOpts(opts)

zap.L().Info("start")
return c.controlc.Start(ctx, &rpcpb.StartRequest{
ExecPath: execPath,
NumNodes: numNodes,
NumNodes: &ret.numNodes,
WhitelistedSubnets: &ret.whitelistedSubnets,
LogLevel: &ret.logLevel,
})
Expand Down Expand Up @@ -203,6 +203,7 @@ func (c *client) Close() error {
}

type Op struct {
numNodes uint32
whitelistedSubnets string
logLevel string
}
Expand All @@ -215,6 +216,12 @@ func (op *Op) applyOpts(opts []OpOption) {
}
}

func WithNumNodes(numNodes uint32) OpOption {
return func(op *Op) {
op.numNodes = numNodes
}
}

func WithWhitelistedSubnets(whitelistedSubnets string) OpOption {
return func(op *Op) {
op.whitelistedSubnets = whitelistedSubnets
Expand Down

0 comments on commit 8670c84

Please sign in to comment.