Merge pull request #18449 from coolljt0725/plugins_cleanup
pkg/plugins/client.go: don't try to encode os decode if it's nil
This commit is contained in:
commit
cd655d8b48
2 changed files with 13 additions and 5 deletions
|
@ -60,17 +60,21 @@ type Client struct {
|
||||||
// It will retry for 30 seconds if a failure occurs when calling.
|
// It will retry for 30 seconds if a failure occurs when calling.
|
||||||
func (c *Client) Call(serviceMethod string, args interface{}, ret interface{}) error {
|
func (c *Client) Call(serviceMethod string, args interface{}, ret interface{}) error {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
if err := json.NewEncoder(&buf).Encode(args); err != nil {
|
if args != nil {
|
||||||
return err
|
if err := json.NewEncoder(&buf).Encode(args); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
body, err := c.callWithRetry(serviceMethod, &buf, true)
|
body, err := c.callWithRetry(serviceMethod, &buf, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer body.Close()
|
defer body.Close()
|
||||||
if err := json.NewDecoder(body).Decode(&ret); err != nil {
|
if ret != nil {
|
||||||
logrus.Errorf("%s: error reading plugin resp: %v", serviceMethod, err)
|
if err := json.NewDecoder(body).Decode(&ret); err != nil {
|
||||||
return err
|
logrus.Errorf("%s: error reading plugin resp: %v", serviceMethod, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,6 +63,10 @@ func TestEchoInputOutput(t *testing.T) {
|
||||||
if !reflect.DeepEqual(output, m) {
|
if !reflect.DeepEqual(output, m) {
|
||||||
t.Fatalf("Expected %v, was %v\n", m, output)
|
t.Fatalf("Expected %v, was %v\n", m, output)
|
||||||
}
|
}
|
||||||
|
err = c.Call("Test.Echo", nil, nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBackoff(t *testing.T) {
|
func TestBackoff(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue