July 2019
Intermediate to advanced
458 pages
12h 12m
English
Another note about this package is that if you are working with interfaces, their implementation should be registered first, using the functions:
func Register(value interface{})func RegisterName(name string, value interface{})
This will make the package aware of the specified types and it will enable us to call decode on the interface type. Let's start by defining an interface and its implementation for our struct:
type Greeter interface { Greet(w io.Writer)}type Character struct { Name string `gob:"name"` Surname string `gob:"surname"` Job string `gob:"job,omitempty"` YearOfBirth int `gob:"year_of_birth,omitempty"`}func (c Character) Greet(w io.Writer) { fmt.Fprintf(w, "Hello, my name is %s %s", c.Name, c.Surname) if c.Job != ...Read now
Unlock full access