如何编码数据并使用 gob 写入文件
package main
import (
"encoding/gob"
"os"
)
type User struct {
Username string
Password string
}
func main() {
user := User{
"zola",
"supersecretpassword",
}
file, _ := os.Create("user.gob")
defer file.Close()
encoder := gob.NewEncoder(file)
encoder.Encode(user)
}