Skip to content

Instantly share code, notes, and snippets.

@chrisvdg
Created May 6, 2021 06:54
Show Gist options
  • Save chrisvdg/3780e037a4aee654070bb356226e96c9 to your computer and use it in GitHub Desktop.
Save chrisvdg/3780e037a4aee654070bb356226e96c9 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"reflect"
)
type My struct{}
func (m My) MyFunc(name string) {
fmt.Printf("MyFunc called %s\n", name)
}
func main() {
m := My{}
meth := reflect.ValueOf(m).MethodByName("MyFunc")
in := make([]reflect.Value, 1)
in[0] = reflect.ValueOf("hello")
meth.Call(in)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment