Skip to content

Instantly share code, notes, and snippets.

@rolaveric
Created March 2, 2014 07:22
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 rolaveric/9303148 to your computer and use it in GitHub Desktop.
Save rolaveric/9303148 to your computer and use it in GitHub Desktop.
Example of using an empty interface to work around the type system in Go
// X needs anything
func X(anything interface{}) {
// Nothing comes for free - need to see what I got
switch value := anything.(type) {
case string:
fmt.Printf("I got a string!: %s", value)
default:
fmt.Print("I got... something!")
}
}
func main() {
X("meep")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment