Skip to content

Instantly share code, notes, and snippets.

@notzippy
Created February 28, 2017 00:40
Show Gist options
  • Save notzippy/3ff69611e6b97b3a769ff6e578bf8ff1 to your computer and use it in GitHub Desktop.
Save notzippy/3ff69611e6b97b3a769ff6e578bf8ff1 to your computer and use it in GitHub Desktop.
The fun golang laws of reflection - Create a new structure from a pointer using reflection. The returned interface is an instantiated not empty
Using the passed in pointer to an interface create a new instantiated structure (not an empty address)
func Update(foo interface{}) {
result := reflect.New(reflect.ValueOf(update).Elem().Type()).Interface()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment