func splitConnectionString(connectionString string) (username, password string, hasPassword bool, host, port, dbname, args string) {
	var hostPortDatabase, hostPort string
	userPass := leftOf(connectionString, "@")
	if userPass != "" {
		hostPortDatabase = rightOf(connectionString, "@")
	} else {
		hostPortDatabase = strings.TrimRight(connectionString, "@")
	}
	dbname = rightOf(hostPortDatabase, "/")
	if dbname != "" {
		hostPort = leftOf(hostPortDatabase, "/")
	} else {
		hostPort = strings.TrimRight(connectionString, "/")
		dbname = defaultDatabaseName
	}
	if strings.Contains(hostPort, "@") {
		hostPort = rightOf(hostPort, "@")
	}
	password = strings.TrimSpace(rightOf(userPass, ":"))
	if password != "" {
		username = leftOf(userPass, ":")
	} else {
		username = strings.TrimRight(userPass, ":")
	}
	hasPassword = password != ""
	port = rightOf(hostPort, ":")
	if port != "" {
		host = leftOf(hostPort, ":")
	} else {
		host = strings.TrimRight(hostPort, ":")
		if host != "" {
			port = strconv.Itoa(defaultPort)
		}
	}
	if strings.Contains(dbname, "?") && strings.Contains(dbname, "=") {
		args = rightOf(dbname, "?")
		if args != "" {
			dbname = leftOf(dbname, "?")
		}
	}
	if Verbose {
		log.Println("Connection:")
		log.Println("\tusername:\t", username)
		log.Println("\tpassword:\t", password)
		log.Println("\thas password:\t", hasPassword)
		log.Println("\thost:\t\t", host)
		log.Println("\tport:\t\t", port)
		log.Println("\tdbname:\t\t", dbname)
		log.Println("\targs:\t\t", args)
		log.Println()
	}
	return
}
Parse a DSN
package simplehstore
import (
	"bytes"
	"log"
	"strconv"
	"strings"
)
var (
	Verbose = false
)
func twoFields(s, delim string) (string, string, bool) {
	if strings.Count(s, delim) != 1 {
		return s, "", false
	}
	fields := strings.Split(s, delim)
	return fields[0], fields[1], true
}
func leftOf(s, delim string) string {
	if left, _, ok := twoFields(s, delim); ok {
		return strings.TrimSpace(left)
	}
	return ""
}
func rightOf(s, delim string) string {
	if _, right, ok := twoFields(s, delim); ok {
		return strings.TrimSpace(right)
	}
	return ""
}