Skip to content

Instantly share code, notes, and snippets.

@arriqaaq
Created January 26, 2023 07:38
Show Gist options
  • Save arriqaaq/b686ae8143289ab79a2aa6b881993c46 to your computer and use it in GitHub Desktop.
Save arriqaaq/b686ae8143289ab79a2aa6b881993c46 to your computer and use it in GitHub Desktop.
type Person struct {
Name string
Age int
}
func (p *Person) Greet() string {
return "Hello, my name is " + p.Name
}
originalPerson := &Person{Name: "John", Age: 30}
// Encode original struct to a byte slice
buf := new(bytes.Buffer)
enc := gob.NewEncoder(buf)
enc.Encode(originalPerson)
// Decode byte slice to a new struct
var clonedPerson Person
dec := gob.NewDecoder(buf)
dec.Decode(&clonedPerson)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment