Besides the well-known JSON and XML, Go also offers the binary format, gob. This recipe goes through the basic concept of how to use the gob package.
Serializing objects to binary format
How to do it...
- Open the console and create the folder chapter05/recipe10.
- Navigate to the directory.
- Create the gob.go file with the following content:
package main
import (
"bytes"
"encoding/gob"
"fmt"
)
type User struct {
FirstName string
LastName string
Age int
Active bool
}
func (u User) String() string {
return fmt.Sprintf(`{"FirstName":%s,"LastName":%s,
...