rpc/server: simplify errors handling during parameter parsing

Forward-ported from 2.x with some updates.
This commit is contained in:
Evgenii Stratonikov 2020-06-04 14:58:47 +03:00 committed by Roman Khimov
parent 6ea0d87934
commit 35f952e44f
4 changed files with 82 additions and 127 deletions

View file

@ -7,20 +7,19 @@ type (
// Value returns the param struct for the given
// index if it exists.
func (p Params) Value(index int) (*Param, bool) {
func (p Params) Value(index int) *Param {
if len(p) > index {
return &p[index], true
return &p[index]
}
return nil, false
return nil
}
// 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
func (p Params) ValueWithType(index int, valType paramType) *Param {
if val := p.Value(index); val != nil && val.Type == valType {
return val
}
return nil, false
return nil
}