diff --git a/lesson7/marshalling/20_bson_deserialize.go b/lesson7/marshalling/20_bson_deserialize.go new file mode 100644 index 0000000..e5d2a52 --- /dev/null +++ b/lesson7/marshalling/20_bson_deserialize.go @@ -0,0 +1,33 @@ +package main + +import ( + "fmt" + "gopkg.in/mgo.v2/bson" + "io/ioutil" +) + +type User struct { + Id uint32 + Name string + Surname string +} + +func main() { + var user User + + bsonInput, err := ioutil.ReadFile("1.bson") + if err != nil { + fmt.Println(err) + return + } + + fmt.Printf("Read %d bytes\n", len(bsonInput)) + + err = bson.Unmarshal(bsonInput, &user) + if err != nil { + fmt.Println(err) + return + } + fmt.Println("Deserialized value") + fmt.Println(user) +}