Skip to content

Instantly share code, notes, and snippets.

@clsung
Created October 1, 2016 17:43
Show Gist options
  • Save clsung/fa8ce3b40be7887881e54d8682f3bdfe to your computer and use it in GitHub Desktop.
Save clsung/fa8ce3b40be7887881e54d8682f3bdfe to your computer and use it in GitHub Desktop.
// Values is a helper that converts an array command reply to a []interface{}.
// If err is not equal to nil, then Values returns nil, err. Otherwise, Values
// converts the reply as follows:
//
// Reply type Result
// array reply, nil
// nil nil, ErrNil
// other nil, error
func Values(reply interface{}, err error) ([]interface{}, error) {
if err != nil {
return nil, err
}
switch reply := reply.(type) {
case []interface{}:
return reply, nil
case nil:
return nil, ErrNil
case Error:
return nil, reply
}
return nil, fmt.Errorf("redigo: unexpected type for Values, got type %T", reply)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment