The heroku database URL format is very different from the standard postgres spec format. Here's the code I use to translate:
regex := regexp.MustCompile("(?i)^postgres://(?:([^:@]+):([^@]*)@)?([^@/:]+):(\\d+)/(.*)$")
matches := regex.FindStringSubmatch(os.Getenv("DATABASE_URL"))
if matches == nil {
log.Fatalf("DATABASE_URL variable must look like: postgres://username:password@hostname:port/dbname (not '%v')", os.Getenv("DATABASE_URL"))
}
sslmode := os.Getenv("PGSSL")
if sslmode == "" {
sslmode = "disable"
}
spec := fmt.Sprintf("user=%s password=%s host=%s port=%s dbname=%s sslmode=%s", matches[1], matches[2], matches[3], matches[4], matches[5], sslmode)
Hope this helps.