Created
January 26, 2023 07:38
-
-
Save arriqaaq/b686ae8143289ab79a2aa6b881993c46 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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