DPIGGo 動態(tài)代理庫
DPIG 是一個實驗性質(zhì)的 Go 語言動態(tài)代理庫,它不依賴代碼生成技術(shù),可以對接口的實例進行動態(tài)增強,使用方法也很簡單。
var u UserStore = user.New()
// 此處進行增強
dpig.Component(&u)
var postCall = func(in, out []reflect.Value) {
log.Println("Get User:", in[0].Interface(),out[0].Interface{})
}
// 修改方法運行行為
dpig.Change(dpig.MethodSelector{Object:"UserStore",Method:"GetUser"}, dpig.Extend{Post: []dpig.PostCall{postCall}})
u.GetUser(uid) // 此時會執(zhí)行 postCall 函數(shù)
它支持對方法進行三種增強:前置、后置、環(huán)繞。
評論
圖片
表情
