dsn.go
func GenPostgres(u *URL) (string, error) {
	host, port, dbname := hostname(u.Host), hostport(u.Host), strings.TrimPrefix(u.Path, "/")
	if host == "." {
		return "", ErrRelativePathNotSupported
	}

	// resolve path
	if u.Proto == "unix" {
		if host == "" {
			dbname = "/" + dbname
		}

		host, port, dbname = resolveDir(stdpath.Join(host, dbname))
	}

	q := u.Query()
	q.Set("host", host)
	q.Set("port", port)
	q.Set("dbname", dbname)

	// add user/pass
	if u.User != nil {
		q.Set("user", u.User.Username())
		pass, _ := u.User.Password()
		q.Set("password", pass)
	}

	// save host, port, dbname
	if u.hostPortDB == nil {
		u.hostPortDB = []string{host, port, dbname}
	}

	return genOptions(q, "", "=", " ", ",", true), nil
}
func GenPostgres(u *URL) (string, error) {
	host, port, dbname := hostname(u.Host), hostport(u.Host), strings.TrimPrefix(u.Path, "/")
	if host == "." {
		return "", ErrRelativePathNotSupported
	}

	// resolve path
	if u.Proto == "unix" {
		if host == "" {
			dbname = "/" + dbname
		}

		host, port, dbname = resolveDir(stdpath.Join(host, dbname))
	}

	q := u.Query()
	q.Set("host", host)
	q.Set("port", port)
	q.Set("dbname", dbname)

	// add user/pass
	if u.User != nil {
		q.Set("user", u.User.Username())
		pass, _ := u.User.Password()
		q.Set("password", pass)
	}

	// save host, port, dbname
	if u.hostPortDB == nil {
		u.hostPortDB = []string{host, port, dbname}
	}

	return genOptions(q, "", "=", " ", ",", true), nil
}
func GenPostgres ( u * URL ) ( string , error ) { host , port , dbname := hostname ( u . Host ) , hostport ( u . Host ) , strings . TrimPrefix ( u . Path , " " ) if host == " " { return " " , ErrRelativePathNotSupported } // resolve path if u . Proto == " " { if host == " " { dbname = " " + dbname } host , port , dbname = resolveDir ( stdpath . Join ( host , dbname ) ) } q := u . Query ( ) q . Set ( " " , host ) q . Set ( " " , port ) q . Set ( " " , dbname ) // add user/pass if u . User != nil { q . Set ( " " , u . User . Username ( ) ) pass , _ := u . User . Password ( ) q . Set ( " " , pass ) } // save host, port, dbname if u . hostPortDB == nil { u . hostPortDB = [ ] string { host , port , dbname } } return genOptions ( q , " " , " " , " " , " " , true ) , nil }
// GenPostgres generates a postgres DSN from the passed URL.
GenPostgres generates a postgres DSN from the passed URL .