golang将interface{}转换为struct
项目中需要用到golang的队列,container/list,需要放入的元素是struct,但是因为golang中list的设计,从list中取出时的类型为interface{},所以需要想办法把interface{}转换为struct。 这里需要用到interface assertion,具体操作见下面代码: 1 package main 2 3 import ( 4 "container/list" 5 "fmt" 6 "strconv" 7 ) 8 9 type People struct { 10 Name string 11 Age int 12 } 13 14 func main() { 15 // Create a new list and put some numbers ...阅读全文