🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[TOC] ## 结构体与buf转换 ``` type Person struct { Name string Age int } func main() { var buf1 bytes.Buffer en := gob.NewEncoder(&buf1) en.Encode(Person{"idcpj1", 111}) en.Encode(Person{"idcpj2", 222}) var p1 Person var p2 Person de := gob.NewDecoder(&buf1) de.Decode(&p1) de.Decode(&p2) fmt.Printf("%+v\n", p1) // {Name:idcpj1 Age:111} fmt.Printf("%+v\n", p2) // {Name:idcpj2 Age:222} } ```