cheekybits / genny

Elegant generics for Go
MIT License
1.71k stars 167 forks source link

Imports not generated correctly #40

Open pierznj opened 7 years ago

pierznj commented 7 years ago

In my template I have these imports:

import (
"errors"
"fmt"
"strings"

"github.com/deoxxa/gojson"
"github.com/macropodhq/go.uuid"
"github.com/foo/bar/entities"
"github.com/foo/bar/fdb"
"github.com/foo/bar/security"
"github.com/foo/simplelog"
)

My generated files have imports looking like this:

import (
"encoding/json"
"strings"

"github.com/facebookgo/stackerr"
uuid "github.com/macropodhq/go.uuid"
"github.com/foo/bar/entities"
"github.com/foo/bar/fdb"
"github.com/foo/bar/security"
"github.com/foo/simplelog"
)

You can see that "errors" has been removed (thus preventing my code from compiling), and "github.com/macropodhq/go.uuid" has been renamed to "uuid" (I didn't ask for it, but OK). Furthermore it has decided to replace the custom json package we use with the standard "Go encoding/json" package. I guess genny is auto-fixing the imports section - but it's doing it wrongly.

Crevil commented 7 years ago

We are seeing similar behaviour with the packages errors and github.com/pkg/errors. Are there any means to make sure the imports stay the same?

eloff commented 4 years ago

I guess that it's using goimports or some such and there is ambiguity between two packages on your system, e.g. errors and github.com/pkg/errors so it does nothing in that case. It would be better if it just copies the imports verbatim and removes the import to genny (if unused).

Antonboom commented 3 years ago

https://github.com/golang/go/issues/44737