Golang:如何在现有库中使用反射包

I want to call a function in a existing library from function name.

In golang, just calling method from methodname is OK, because reflect package has (v Value) MethodByName(name string). But, for calling a method, all method argument should be reflect.Value.

How can I call a function whose argument are not reflect.Value.

package main

//-------------------------------
// Example of existing library
//-------------------------------
type Client struct {
    id string
}

type Method1 struct {
    record string
}

// type Method2 struct{}
// ...

// defined at library : do not change
func (c *Client) Method1(d *Method1) {
    d.record = c.id
}

//------------------
// Edit from here
//------------------
func main() {
    // give MethodN from cmd line
    method_name := "Method1"

    // How can I call Method1(* Method1) propery???
    // * Make Method1 instance
    // * Call Method1 function
    //...
    //fmt.Printf("%s record is %s", method_name, d.record)
}

http://play.golang.org/p/6B6-90GTwc

You need to get reflect.Values of client and method values with reflect.ValueOf and then use reflect.Value.Call:

methodName := "Method1"

c := &Client{id: "foo"}
m := &Method1{record: "bar"}

args := []reflect.Value{reflect.ValueOf(m)}
reflect.ValueOf(c).MethodByName(methodName).Call(args)
fmt.Printf("%s record is %s", methodName, m.record)

Playground: http://play.golang.org/p/PT33dqj9Q9.