2020-01-14 12:02:38 +00:00
|
|
|
package request
|
2018-03-23 20:36:59 +00:00
|
|
|
|
|
|
|
type (
|
2019-10-22 14:56:03 +00:00
|
|
|
// Params represents the JSON-RPC params.
|
2018-03-23 20:36:59 +00:00
|
|
|
Params []Param
|
|
|
|
)
|
|
|
|
|
2019-11-21 13:42:51 +00:00
|
|
|
// Value returns the param struct for the given
|
2018-03-23 20:36:59 +00:00
|
|
|
// index if it exists.
|
2020-06-04 11:58:47 +00:00
|
|
|
func (p Params) Value(index int) *Param {
|
2018-03-23 20:36:59 +00:00
|
|
|
if len(p) > index {
|
2020-06-04 11:58:47 +00:00
|
|
|
return &p[index]
|
2018-03-23 20:36:59 +00:00
|
|
|
}
|
|
|
|
|
2020-06-04 11:58:47 +00:00
|
|
|
return nil
|
2018-03-23 20:36:59 +00:00
|
|
|
}
|
|
|
|
|
2019-11-21 13:42:51 +00:00
|
|
|
// ValueWithType returns the param struct at the given index if it
|
2018-03-23 20:36:59 +00:00
|
|
|
// exists and matches the given type.
|
2020-06-04 11:58:47 +00:00
|
|
|
func (p Params) ValueWithType(index int, valType paramType) *Param {
|
|
|
|
if val := p.Value(index); val != nil && val.Type == valType {
|
|
|
|
return val
|
2018-03-23 20:36:59 +00:00
|
|
|
}
|
2020-06-04 11:58:47 +00:00
|
|
|
return nil
|
2018-03-23 20:36:59 +00:00
|
|
|
}
|