Solution Review: Decode the Contents
This lesson discusses the solution to the challenge given in the previous lesson.
package mainimport ("bufio""fmt""encoding/gob""log""os")type Address struct {Type stringCity stringCountry string}type VCard struct {FirstName stringLastName stringAddresses []*AddressRemark string}var content stringvar vc VCardfunc 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 1400+ tech skills courses.