getLen tries to get the length of an object. It returns (0, false) if impossible.
(x interface{})
| 819 | // getLen tries to get the length of an object. |
| 820 | // It returns (0, false) if impossible. |
| 821 | func getLen(x interface{}) (length int, ok bool) { |
| 822 | v := reflect.ValueOf(x) |
| 823 | defer func() { |
| 824 | ok = recover() == nil |
| 825 | }() |
| 826 | return v.Len(), true |
| 827 | } |
| 828 | |
| 829 | // Len asserts that the specified object has specific length. |
| 830 | // Len also fails if the object has a type that len() not accept. |