Skip to content
New issue

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

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

Already on GitHub? # to your account

Code gen doesn't import anonymous imports #94

Closed
Blquinn opened this issue Dec 6, 2018 · 2 comments
Closed

Code gen doesn't import anonymous imports #94

Blquinn opened this issue Dec 6, 2018 · 2 comments
Labels
bug Something isn't working
Milestone

Comments

@Blquinn
Copy link

Blquinn commented Dec 6, 2018

When runinng wire or go generate anonymous imports such as:

import _ "github.com/lib/pq"

don't appear in generated code.

To Reproduce

Example code:

package main

import (
	"context"
	"fmt"

	"github.com/google/wire"
	"github.com/jmoiron/sqlx"
	_ "github.com/lib/pq"
)

var (
	ServiceContainer = wire.NewSet(NewDatabase)
)

func NewDatabase() *sqlx.DB {
	return sqlx.MustConnect("postgres", "host=localhost port=5432 user=ben password=password dbname=tapx sslmode=disable")
}

func initializeDB(ctx context.Context) (*sqlx.DB, error) {
	wire.Build(ServiceContainer)
	return &sqlx.DB{}, nil
}

func main() {
	c := context.Background()
	db, err := initializeDB(c)
	if err != nil {
		panic(err)
	}

	var s struct {
		I int `db:"num"`
	}
	err = db.Get(&s, "select 1 as num")
	if err != nil {
		panic(err)
	}
	fmt.Printf("got %d\n", s.I)
}

Then run wire

Expected behavior

Should generate code with the following imports:

import (
	"context"
	"fmt"

	"github.com/google/wire"
	"github.com/jmoiron/sqlx"
	_ "github.com/lib/pq"
)

Version

HEAD as of today

@zombiezen zombiezen added the bug Something isn't working label Dec 7, 2018
@zombiezen zombiezen added this to the Sprint 21 milestone Dec 7, 2018
@zombiezen
Copy link
Collaborator

Thank you for the bug report! We'll try to fix this as soon as we can, but in the meantime, you can work around by adding the blank import to another file in the same package.

@doodlesbykumbi
Copy link
Contributor

@zombiezen @Blquinn I've made a PR attempting to fix this. See ^

zombiezen pushed a commit that referenced this issue Jan 7, 2019
Adds Kumbirai Tanekha to A+C.

Fixes #94
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants