Skip to content

Commit 2c976d1

Browse files
authored
Merge pull request #30 from digitalocean/mdl-ovsb-params-interface
ovsdb: make params an interface for more type flexibility
2 parents 848abbc + c9deb00 commit 2c976d1

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

ovsdb/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ type ClientStats struct {
200200
}
201201

202202
// rpc performs a single RPC request, and checks the response for errors.
203-
func (c *Client) rpc(ctx context.Context, method string, out interface{}, args ...interface{}) error {
203+
func (c *Client) rpc(ctx context.Context, method string, out, arg interface{}) error {
204204
// Was the context canceled before sending the RPC?
205205
select {
206206
case <-ctx.Done():
@@ -218,7 +218,7 @@ func (c *Client) rpc(ctx context.Context, method string, out interface{}, args .
218218

219219
req := jsonrpc.Request{
220220
Method: method,
221-
Params: args,
221+
Params: arg,
222222
ID: c.requestID(),
223223
}
224224

ovsdb/internal/jsonrpc/conn.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ import (
2525

2626
// A Request is a JSON-RPC request.
2727
type Request struct {
28-
ID string `json:"id"`
29-
Method string `json:"method"`
30-
Params []interface{} `json:"params"`
28+
ID string `json:"id"`
29+
Method string `json:"method"`
30+
Params interface{} `json:"params"`
3131
}
3232

3333
// A Response is either a JSON-RPC response, or a JSON-RPC request notification.

ovsdb/rpc.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
// ListDatabases returns the name of all databases known to the OVSDB server.
2323
func (c *Client) ListDatabases(ctx context.Context) ([]string, error) {
2424
var dbs []string
25-
if err := c.rpc(ctx, "list_dbs", &dbs); err != nil {
25+
if err := c.rpc(ctx, "list_dbs", &dbs, nil); err != nil {
2626
return nil, err
2727
}
2828

@@ -32,14 +32,14 @@ func (c *Client) ListDatabases(ctx context.Context) ([]string, error) {
3232
// Echo verifies that the OVSDB connection is alive, and can be used to keep
3333
// the connection alive.
3434
func (c *Client) Echo(ctx context.Context) error {
35-
const req = "github.com/digitalocean/go-openvswitch/ovsdb"
35+
req := [1]string{"github.com/digitalocean/go-openvswitch/ovsdb"}
3636

3737
var res [1]string
3838
if err := c.rpc(ctx, "echo", &res, req); err != nil {
3939
return err
4040
}
4141

42-
if res[0] != req {
42+
if res[0] != req[0] {
4343
return fmt.Errorf("invalid echo response: %q", res[0])
4444
}
4545

ovsdb/rpc_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ func TestClientListDatabases(t *testing.T) {
3030
panicf("unexpected RPC method (-want +got):\n%s", diff)
3131
}
3232

33-
if diff := cmp.Diff(0, len(req.Params)); diff != "" {
33+
// Client should send an empty array parameter.
34+
ps := req.Params.([]interface{})
35+
36+
if diff := cmp.Diff(0, len(ps)); diff != "" {
3437
panicf("unexpected number of RPC parameters (-want +got):\n%s", diff)
3538
}
3639

0 commit comments

Comments
 (0)