mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 01:08:53 +08:00
43 lines
606 B
Go
Executable File
43 lines
606 B
Go
Executable File
// degob.go
|
|
package main
|
|
|
|
import (
|
|
"bufio"
|
|
"encoding/gob"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
)
|
|
|
|
type Address struct {
|
|
Type string
|
|
City string
|
|
Country string
|
|
}
|
|
|
|
type VCard struct {
|
|
FirstName string
|
|
LastName string
|
|
Addresses []*Address
|
|
Remark string
|
|
}
|
|
|
|
var content string
|
|
var vc VCard
|
|
|
|
func main() {
|
|
// using a decoder:
|
|
file, _ := os.Open("vcard.gob")
|
|
defer file.Close()
|
|
inReader := bufio.NewReader(file)
|
|
dec := gob.NewDecoder(inReader)
|
|
err := dec.Decode(&vc)
|
|
if err != nil {
|
|
log.Println("Error in decoding gob")
|
|
}
|
|
fmt.Println(vc)
|
|
}
|
|
|
|
// Output:
|
|
// {Jan Kersschot [0x12642e60 0x12642e80] none}
|