Skip to content

Implicit initialization of lib/pq messes with other imports #18

@anaulin

Description

@anaulin

Hi there, thanks for the handy library!

Since I was already using github.com/lib/pq in my app, when I added a dependency on github.com/antonlindstrom/pgstore I got the following runtime error:

panic: sql: Register called twice for driver postgres

goroutine 1 [running]:
panic(0x420ec0, 0xc820208e30)
    /usr/local/Cellar/go/1.6/libexec/src/runtime/panic.go:464 +0x3e6
database/sql.Register(0x5a78c0, 0x8, 0x9b2b58, 0x84dd30)
    /usr/local/Cellar/go/1.6/libexec/src/database/sql/sql.go:45 +0x181
github.com/bolt-data/boltapp/vendor/github.com/lib/pq.init.1()
    /Users/anaulin/src/github.com/bolt-data/boltapp/vendor/github.com/lib/pq/conn.go:44 +0x71
github.com/bolt-data/boltapp/vendor/github.com/lib/pq.init()
    /Users/anaulin/src/github.com/bolt-data/boltapp/vendor/github.com/lib/pq/user_posix.go:24 +0x4b0
github.com/bolt-data/boltapp/db.init()
    /Users/anaulin/src/github.com/bolt-data/boltapp/db/connection.go:27 +0x59
github.com/bolt-data/boltapp/handlers.init()
    /Users/anaulin/src/github.com/bolt-data/boltapp/handlers/template_util.go:28 +0x5b
main.init()

I can work around this issue by removing my own import of github.com/lib/pq but it feels a little messy, for a couple of reasons:

  1. It is no longer explicit in my code which Postgres driver is being used and where
  2. Some other dependency that also registers lib/pq will mess with things

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions