Skip to content

Instantly share code, notes, and snippets.

@blanchonvincent
Created August 9, 2019 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blanchonvincent/e81cc6a6a389ed1bbffba114683f4ab9 to your computer and use it in GitHub Desktop.
Save blanchonvincent/e81cc6a6a389ed1bbffba114683f4ab9 to your computer and use it in GitHub Desktop.
Medium - Empty interface
func emptyInterface(i interface {}) {
s := i.(*MultipleFieldStructure)
y = s
}
@spcheema
Copy link

spcheema commented Sep 30, 2020

Hi Vincent

I was going through your medium article and you said a good solution would be to use the pointer and convert back to this same struct pointer.

How do we achieve this?

func emptyInterface(i interface{}) {
	s := i.(*MultipleFieldStructure)
	y := s
	x = *y
}

what should be the declaration type of y likewise in the case of var x MultipleFieldStructure

Can you please provide a complete example of this? I'm quite new and trying to get my head around.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment