Skip to content

Instantly share code, notes, and snippets.

@fdv
Created February 25, 2020 12:07
Show Gist options
  • Save fdv/c8791b614edc0aa5211420520ceab179 to your computer and use it in GitHub Desktop.
Save fdv/c8791b614edc0aa5211420520ceab179 to your computer and use it in GitHub Desktop.
Use case
package main
import "fmt"
func printString(foo string) {
fmt.Println(foo)
}
func printLen(foo string) {
fmt.Println(len(foo))
}
type foo struct {
Value string
Func interface{}
}
func main() {
var fools = []foo{
foo{
Value: "hello world",
Func: printString,
},
foo{
Value: "goodbye world",
Func: printLen,
},
}
for i := range fools {
fools[i].Func.(func(foo string))(fools[i].Value)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment