Skip to content

Code gen doesn't import anonymous imports #94

Closed
@Blquinn

Description

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions