/
rpc.go
72 lines (62 loc) · 1.67 KB
/
rpc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright (c) 2019, AT&T Intellectual Property. All rights reserved.
//
// Copyright (c) 2015 by Brocade Communications Systems, Inc.
// All rights reserved.
//
// SPDX-License-Identifier: GPL-2.0-only
package ifmgrd
import (
"fmt"
)
//Request represents an RPC request
type Request struct {
//Op is the method that was called via json rpc
Method string `json:"method"`
//Args is a list of arguments to that method
Args []interface{} `json:"params"`
//Id is the unique request identifier
Id int `json:"id"`
}
//Response represents an RPC response
type Response struct {
//Result is any value returned by the handler
//The client library uses reflection to ensure it received the appropriate type.
Result interface{} `json:"result"`
//Error contains a message describing a problem
Error interface{} `json:"error"`
//Id is the unique request identifier
Id int `json:"id"`
}
type MethErr struct {
Name string
}
func (e *MethErr) Error() string {
return fmt.Sprintf("unknown method %s", e.Name)
}
type ArgErr struct {
Method string
Farg interface{}
Typ string
Etyp string
}
func (e *ArgErr) Error() string {
if e.Typ == "" {
return fmt.Sprintf("cannot use %v (type %T) as type %s in call to %s",
e.Farg, e.Farg, e.Etyp, e.Method)
}
return fmt.Sprintf("cannot use %v (type %s) as type %s in call to %s",
e.Farg, e.Typ, e.Etyp, e.Method)
}
type ArgNErr struct {
Method string
Len int
Elen int
}
func (e *ArgNErr) Error() string {
if e.Len > e.Elen {
return fmt.Sprintf("too many arguments in call to %s expected %d got %d",
e.Method, e.Elen, e.Len)
}
return fmt.Sprintf("too few arguments in call to %s expected %d got %d",
e.Method, e.Elen, e.Len)
}