Closed moshuipan closed 5 years ago
package main import ( "fmt" "reflect" "github.com/agiledragon/gomonkey" ) type B struct { a string } func (b *B) Get(s string) string { return "" } func (b *B) Put(s string) string { var i int for ; i < 100; i++ { b.a = "iiiii" } return "" } func main(){ var b *B gomonkey.ApplyMethod(reflect.TypeOf(b), "Get", func(_ *B, subPath string) string { return subPath }) fmt.Println("get:", ws.Get("get")) // want "get" gomonkey.ApplyMethod(reflect.TypeOf(b), "Put", func(_ *B, subPath string) string { return subPath }) fmt.Println("put:", ws.Put("put")) }
b.Get没被替换
请看README中Notes的第一点
ok,thanks:smile:
b.Get没被替换