hexdigest / gowrap

GoWrap is a command line tool for generating decorators for Go interfaces
MIT License
1.06k stars 82 forks source link

Add support for internal packages #74

Open geekofalltrades opened 1 year ago

geekofalltrades commented 1 year ago

When I try to generate a wrapper from an interface in an internal package, gowrap fails.

/path/to/package/internal/generated/prom_test.go:

package generated

//go:generate gowrap gen -g -p . -i TestInterface -t prometheus -o prom.go

type TestInterface interface{
    TestMethod()
}
go generate ./...
failed to parse source package: open repo.git/path/to/package/internal/generated: no such file or directory
internal/generated/prom_test.go:3: running "gowrap": exit status 1

Moving the file out of the internal subpackage makes it work.

hexdigest commented 1 year ago

Hey @geekofalltrades,

I think the problem here is a _test.go suffix rather than internal package because it works fine with internal packages. Try putting the interface you're trying to generate decorator for somewhere else. There's not very much sense to parse test files.

Let me know if it's your case. I think I have to document it because it's not the first time people face this issue.

geekofalltrades commented 1 year ago

This seemed to be working in a _test.go file when I moved that file out of an internal package.

Also, it makes sense to me to have this particular interface in a _test.go file, because I'm using it to test a custom gowrap template.

But, there was no non-_test.go-suffixed file in the directory, so possibly the whole directory was not registering as a Go package. And when I moved it out of the internal package, it was into a directory that had other go files in it that were not _test.go files.