rpc: separate out request and response structures
Mostly as is, no real effort done yet to optimize them, so there are still a lot of duplicates there, but at least we sort them out into different smaller packages.
This commit is contained in:
parent
69e1ad512f
commit
f330f2f40b
18 changed files with 422 additions and 396 deletions
26
pkg/rpc/request/params.go
Normal file
26
pkg/rpc/request/params.go
Normal file
|
@ -0,0 +1,26 @@
|
|||
package request
|
||||
|
||||
type (
|
||||
// Params represents the JSON-RPC params.
|
||||
Params []Param
|
||||
)
|
||||
|
||||
// Value returns the param struct for the given
|
||||
// index if it exists.
|
||||
func (p Params) Value(index int) (*Param, bool) {
|
||||
if len(p) > index {
|
||||
return &p[index], true
|
||||
}
|
||||
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// ValueWithType returns the param struct at the given index if it
|
||||
// exists and matches the given type.
|
||||
func (p Params) ValueWithType(index int, valType paramType) (*Param, bool) {
|
||||
if val, ok := p.Value(index); ok && val.Type == valType {
|
||||
return val, true
|
||||
}
|
||||
|
||||
return nil, false
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue