Created
January 26, 2023 07:41
-
-
Save arriqaaq/8354c1fad65bf9ea85ee6370d08edb23 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 stream | |
| originalPersonBytes, _ := json.Marshal(originalPerson) | |
| // Decode byte stream to a new struct | |
| var clonedPerson Person | |
| json.Unmarshal(originalPersonBytes, &clonedPerson) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment