mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-20 19:19:06 +08:00
commands: Allow commands to output pointers to specified type
This commit is contained in:
@ -114,14 +114,17 @@ func (c *Command) Call(req Request) Response {
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
actualType := reflect.ValueOf(output).Type()
|
actualType := reflect.TypeOf(output)
|
||||||
|
if actualType.Kind() == reflect.Ptr {
|
||||||
|
actualType = actualType.Elem()
|
||||||
|
}
|
||||||
|
|
||||||
// test if output is a channel
|
// test if output is a channel
|
||||||
isChan := actualType.Kind() == reflect.Chan
|
isChan := actualType.Kind() == reflect.Chan
|
||||||
|
|
||||||
// If the command specified an output type, ensure the actual value returned is of that type
|
// If the command specified an output type, ensure the actual value returned is of that type
|
||||||
if cmd.Type != nil && !isChan {
|
if cmd.Type != nil && !isChan {
|
||||||
expectedType := reflect.ValueOf(cmd.Type).Type()
|
expectedType := reflect.TypeOf(cmd.Type)
|
||||||
|
|
||||||
if actualType != expectedType {
|
if actualType != expectedType {
|
||||||
res.SetError(ErrIncorrectType, ErrNormal)
|
res.SetError(ErrIncorrectType, ErrNormal)
|
||||||
|
Reference in New Issue
Block a user