Solution Review: Decode the Contents

This lesson discusses the solution to the challenge given in the previous lesson.

package main
import (
"bufio"
"fmt"
"encoding/gob"
"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)
}

Get hands-on with 1200+ tech skills courses.