Skip to content

Instantly share code, notes, and snippets.

@igomez10
Last active April 26, 2019 15:45
Show Gist options
  • Save igomez10/456f4953965400ac9191ffc953fdac05 to your computer and use it in GitHub Desktop.
Save igomez10/456f4953965400ac9191ffc953fdac05 to your computer and use it in GitHub Desktop.
Generic data structure in Go
package main
import "fmt"
type hack struct {
value interface{}
}
func main() {
threeInOne := [3]hack{}
threeInOne[0].value = []string{"hello"}
threeInOne[1].value = 1
threeInOne[2].value = func(par interface{}) { fmt.Printf("%+v", par) }
for i := range threeInOne {
fmt.Println(threeInOne[i])
}
threeInOne[2].value.(func(interface{}))("hey")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment