两种不同形式的数据库连接字符串

I have two different codes to connect postgresql with golang first code like this

connStr := fmt.Sprintf("user=%s password=%s dbname=%s sslmode=disable", user, password, dbName)

and the second one like this

connStr := fmt.Sprintf("postgres://%s:%s@localhost/%s?sslmode=disable", user, password, dbName)

What's the difference between them? And when do I have to use the second one?

Both of them work and as far as I know there is not real difference between them.

import "database/sql"

import _ "github.com/lib/pq"

connStr := fmt.Sprintf("postgres://%s:%s@localhost/%s?sslmode=disable", user, password, dbName)
db, err := sql.Open("postgres", connStr)

///////////////////////////////

import "database/sql"

import _ "github.com/lib/pq"

connStr := fmt.Sprintf("user=%s password=%s dbname=%s sslmode=disable", user, password, dbName)
db, err := sql.Open("postgres", connStr)
if err != nil {
    log.Fatal(err)
}

More info you can find here: https://godoc.org/github.com/lib/pq