rpc/server: simplify errors handling during parameter parsing
Forward-ported from 2.x with some updates.
This commit is contained in:
parent
6ea0d87934
commit
35f952e44f
4 changed files with 82 additions and 127 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue