Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: replace the arguments of a function #111

Open
eleztian opened this issue Sep 24, 2022 · 1 comment
Open

feature: replace the arguments of a function #111

eleztian opened this issue Sep 24, 2022 · 1 comment

Comments

@eleztian
Copy link

eleztian commented Sep 24, 2022

Is there a more appropriate way to change the parameters of a function?

more complicated way....

var patchReadDir = gomonkey.NewPatches()
var readDir func(name string) ([]os.DirEntry, error)
readDir = func(name string) ([]os.DirEntry, error) {
        patchReadDir.Reset()
        defer patchReadDir.ApplyFunc(os.ReadDir, readDir)
        return os.ReadDir(filepath.Join(c.baseDir, name))
}
patchReadDir.ApplyFunc(os.ReadDir, readDir)
c.patches = append(c.patches, patchReadDir)
@eleztian eleztian changed the title 替换某个函数的入参 feature: replace the arguments of a function Sep 24, 2022
@myzhan
Copy link
Contributor

myzhan commented Jun 29, 2023

I think it's related to #103

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants