Skip to content

Instantly share code, notes, and snippets.

@arriqaaq
Created January 26, 2023 07:41
Show Gist options
  • Select an option

  • Save arriqaaq/8354c1fad65bf9ea85ee6370d08edb23 to your computer and use it in GitHub Desktop.

Select an option

Save arriqaaq/8354c1fad65bf9ea85ee6370d08edb23 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 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