gowrap icon indicating copy to clipboard operation
gowrap copied to clipboard

Duplicate import statements with gowrap >=1.4.0

Open ghouscht opened this issue 1 year ago • 0 comments

Hi, First of all thank you for your work on gowrap, I really like it and use it in various projects.

However, since version 1.4.0 I have some issues in more complex projects that seem to be caused by https://github.com/hexdigest/gowrap/pull/92. I'm using the gowrap {{.Import}} template and in my case that generates the following imports if the gowrap version is >=1.4.0:

import (
	"time"

	"github.com/prometheus/client_golang/prometheus"
	_sourceUser "<redacted>/internal/user/service/user"
	"<redacted>/internal/user/service/user/models"

	_sourceUser "<redacted>/internal/user/service/user"
)

As you can see the user import is duplicated.

With version 1.3.10 and same arguments to gowrap the imports are generated as follows:

import (
	"time"

	"github.com/prometheus/client_golang/prometheus"
	"<redacted>/internal/user/service/user"
	"<redacted>/internal/user/service/user/models"
)

Any idea how this can be fixed? ~~I'm trying to create a simple reproducer for this but so far I wasn't successful.~~

Here is a simple reproducer: https://github.com/ghouscht/gowrap-issue-98

In my case I'm not using import aliases in the package where the interface and go generate statement sits but the outcome is the same = duplicate imports.

ghouscht avatar Dec 31 '24 14:12 ghouscht