In Golang, I am trying to convert an Interface to Slice of Bytes. Debugger clearly shows that it is a Slice of Bytes.
// Check an Interface's Type.
ifcType = reflect.TypeOf(ifc).Kind()
// Array?
if ifcType == reflect.Slice {
// Get Type of Sub-Elements.
ifcElementType = reflect.TypeOf(ifc).Elem().Kind()
if ifcElementType == reflect.Uint8 {
// Array of Bytes.
// => 'bencode' Byte String.
// Convert the Type.
ba, ok = ifc.([]byte)
if !ok {
return nil, ErrTypeAssertion
}
When I have checked that Interface's Type is Slice and Sub-Item's Type is Uint8, I do the Type Assertion. But for some Reason, it fails. How can that be ?
GoLand's Debugger Screenshot just after 'ok' Variable has become 'false': http://imagehost.cc/image/v4403
Thank you!