degob.go 606 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // degob.go
  2. package main
  3. import (
  4. "bufio"
  5. "encoding/gob"
  6. "fmt"
  7. "log"
  8. "os"
  9. )
  10. type Address struct {
  11. Type string
  12. City string
  13. Country string
  14. }
  15. type VCard struct {
  16. FirstName string
  17. LastName string
  18. Addresses []*Address
  19. Remark string
  20. }
  21. var content string
  22. var vc VCard
  23. func main() {
  24. // using a decoder:
  25. file, _ := os.Open("vcard.gob")
  26. defer file.Close()
  27. inReader := bufio.NewReader(file)
  28. dec := gob.NewDecoder(inReader)
  29. err := dec.Decode(&vc)
  30. if err != nil {
  31. log.Println("Error in decoding gob")
  32. }
  33. fmt.Println(vc)
  34. }
  35. // Output:
  36. // {Jan Kersschot [0x12642e60 0x12642e80] none}