Skip to content

Commit

Permalink
fix(rpc): resolve linter issues and improve code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
sebasti810 committed Aug 14, 2024
1 parent 7a53e2a commit e18f3ac
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
15 changes: 11 additions & 4 deletions api/rpc/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ type Client struct {
closer multiClientCloser
}

type ClientOption func(*clientConfig)
type RPCClientOption func(*clientConfig)

type clientConfig struct {
timeout time.Duration
}

func WithTimeout(timeout time.Duration) ClientOption {
func WithTimeout(timeout time.Duration) RPCClientOption {
return func(c *clientConfig) {
c.timeout = timeout
}
Expand Down Expand Up @@ -78,7 +78,7 @@ func (c *Client) Close() {

// NewClient creates a new Client with one connection per namespace with the
// given token as the authorization token.
func NewClient(ctx context.Context, addr, token string, opts ...ClientOption) (*Client, error) {
func NewClient(ctx context.Context, addr, token string, opts ...RPCClientOption) (*Client, error) {
config := &clientConfig{}
for _, opt := range opts {
opt(config)
Expand All @@ -97,7 +97,14 @@ func newClient(ctx context.Context, addr string, authHeader http.Header, config
}

for name, module := range moduleMap(&client) {
closer, err := jsonrpc.NewMergeClient(ctx, addr, name, []interface{}{module}, authHeader, jsonrpc.WithHTTPClient(httpClient))
closer, err := jsonrpc.NewMergeClient(
ctx,
addr,
name,
[]interface{}{module},
authHeader,
jsonrpc.WithHTTPClient(httpClient),
)
if err != nil {
return nil, err
}
Expand Down
14 changes: 7 additions & 7 deletions cmd/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ func RPCFlags() *flag.FlagSet {
)

fset.DurationVar(
&timeoutFlag,
"timeout",
0,
"Timeout for RPC requests (e.g. 30s, 1m)",
)
&timeoutFlag,
"timeout",
0,
"Timeout for RPC requests (e.g. 30s, 1m)",
)

storeFlag := NodeFlags().Lookup(nodeStoreFlag)
fset.AddFlag(storeFlag)
return fset
}

func InitClient(cmd *cobra.Command, _ []string) error {
if authTokenFlag == "" {
if authTokenFlag == "" {
rootErrMsg := "cant access the auth token"

storePath, err := getStorePath(cmd)
Expand Down Expand Up @@ -82,7 +82,7 @@ func InitClient(cmd *cobra.Command, _ []string) error {
}
}

var opts []rpc.ClientOption
var opts []rpc.RPCClientOption
if timeoutFlag > 0 {
opts = append(opts, rpc.WithTimeout(timeoutFlag))
}
Expand Down

0 comments on commit e18f3ac

Please sign in to comment.