类型声明后的golang类型转换

Take these two bits of code: 1. http://play.golang.org/p/Oh6xNm2dRK 2. http://play.golang.org/p/Vd-6AGCBKQ

In 1. the media is first created as the empty interface and then type asserted to a string. In 2. the media is a string.

Both try to convert the media to a byte array, why the difference? Aren't they both strings by that time?

The first one doesn't change the type of media, which is already defined as interface{}. You need to set it to a new string variable, or do it inline:

http://play.golang.org/p/QB3ey_e3io

http://play.golang.org/p/RJqBJ4telB