go-kiss / monkey

Go语言猴子补丁框架
https://taoshu.in/go/monkey/
MIT License
119 stars 18 forks source link

Unable to patch function while in init() #22

Open Matt7983 opened 2 months ago

Matt7983 commented 2 months ago

因為在init()階段加入了第三方套件的initialize firestore.NewClient(context.Background(), projectID) 想要把這個function替換掉

monkey.Patch(firestore.NewClient, func(ctx context.Context, projectID string, opts ...option.ClientOption) (*firestore.Client, error) {
                     client := &firestore.Client{}
                     return client, nil
                 })

但發現在init()的階段會失敗 移動到測試function就可以