Skip to content

Commit

Permalink
Example #20: deserialize from BSON format
Browse files Browse the repository at this point in the history
  • Loading branch information
tisnik committed Jul 3, 2020
1 parent 4a33d78 commit 8be6025
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions lesson7/marshalling/20_bson_deserialize.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 8be6025

Please sign in to comment.