Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaiba committed May 13, 2024
1 parent befa82f commit c25fc68
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion core/gatewayclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func NewClient(ctx context.Context, target string, opts *GatewayOptions) (*Gatew

gatewayClient, err := gwClient.NewClient(parsedTarget,
// reuse the same http connection
gateway.WithBaseRPCClient(txClient.JSONRPCClient),
gateway.WithJSONRPCClient(txClient.JSONRPCClient),
)
if err != nil {
return nil, fmt.Errorf("create gateway rpc client: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion core/rpc/client/admin/jsonrpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func WrapUserClient(cl *userClient.Client) *Client {
}
}

var _ user.TxSvcClient = (*Client)(nil) // via embedded rpcclient.JSONRPCClient
var _ user.TxSvcClient = (*Client)(nil) // via embedded userClient.Client
var _ admin.AdminClient = (*Client)(nil) // with extra methods

// Approve approves a validator join request for the validator identified by a
Expand Down
5 changes: 5 additions & 0 deletions core/rpc/client/gateway/jsonrpc/client.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// package jsonrpc implements a JSON-RPC client for the Kwil gateway service.

package jsonrpc

import (
Expand All @@ -10,6 +12,9 @@ import (
"github.com/kwilteam/kwil-db/core/rpc/client/gateway"
)

// Client is a JSON-RPC client for the Kwil gateway service. It use the
// JSONRPCClient from the rpcclient package for the actual JSON-RPC communication,
// and implements gateway service methods.
type Client struct {
*rpcclient.JSONRPCClient

Expand Down
4 changes: 2 additions & 2 deletions core/rpc/client/gateway/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ func WithHTTPClient(client *http.Client) ClientOption {
}
}

// WithBaseRPCClient sets the user client for the client.
// WithJSONRPCClient sets the jsonrpc client for the client.
// This allows custom user clients to be used.
func WithBaseRPCClient(userClient *rpcclient.JSONRPCClient) ClientOption {
func WithJSONRPCClient(userClient *rpcclient.JSONRPCClient) ClientOption {
return func(c *clientOptions) {
c.JSONRPCClient = userClient
}
Expand Down
15 changes: 7 additions & 8 deletions core/rpc/client/jsonrpc.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Package rpcclient provides a Kwil JSON-RPC (API v1) client. It supports only
// HTTP POST, no WebSockets yet. The JSONRPCClient type implements the
// core/rpc/client/user.TxSvcClient interface that is required by
// core/client.JSONRPCClient.
// Package client provides some base Kwil rpc clients.
// JSONRPCClient is a JSON-RPC (API v1) client supports only HTTP POST, no
// WebSockets yet.
package client

import (
Expand Down Expand Up @@ -38,9 +37,9 @@ import (
// message (pb) types sent in POST, or just GET with endpoint implying method.
// - the "method" in the outer request type is instead of the endpoint, all POST

// JSONRPCClient is a JSON-RPC client that handles sending and receiving
// JSON-RPC requests and responses. It is a low-level client that does not
// care about the specifics of the JSON-RPC methods or responses.
// JSONRPCClient is a JSON-RPC client that handles JSON RPC communication.
// It is a low-level client that does not care about the specifics of the
// JSON-RPC methods or responses.
type JSONRPCClient struct {
conn *http.Client

Expand Down Expand Up @@ -205,7 +204,7 @@ func clientError(jsonRPCErr *jsonrpc.Error) error {
return errors.Join(ErrNotFound, err)
// case jsonrpc.ErrorUnauthorized: // not yet used on server
// return errors.Join(client.ErrUnauthorized, err)
// case jsonrpc.ErrorInvalidSignature: // or leave this to core/client.JSONRPCClient to detect and report
// case jsonrpc.ErrorInvalidSignature: // or leave this to core/client.Client to detect and report
// return errors.Join(client.ErrInvalidSignature, err)
default:
}
Expand Down
7 changes: 6 additions & 1 deletion core/rpc/client/user/jsonrpc/client.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package rpcclient
// Package jsonrpc implements the core/rpc/client/user.TxSvcClient interface
// that is required by core/client.Client.
package jsonrpc

import (
"context"
Expand All @@ -16,6 +18,9 @@ import (
"github.com/kwilteam/kwil-db/core/types/transactions"
)

// Client is a JSON-RPC client for the Kwil user service. It use the JSONRPCClient
// from the rpcclient package for the actual JSON-RPC communication, and implements
// the user.TxSvcClient interface.
type Client struct {
*rpcclient.JSONRPCClient
}
Expand Down
2 changes: 1 addition & 1 deletion core/rpc/http/function/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type service struct {
}

// NewAPIClient creates a new API client. Requires a userAgent string describing your application.
// optionally a custom http.JSONRPCClient to allow for advanced features such as caching.
// optionally a custom http.Client to allow for advanced features such as caching.
func NewAPIClient(cfg *Configuration) *APIClient {
if cfg.HTTPClient == nil {
cfg.HTTPClient = http.DefaultClient
Expand Down

0 comments on commit c25fc68

Please sign in to comment.