// GenMySQL generates a mysql DSN from the passed URL.
GenMySQL generates a mysql DSN from the passed URL.
// GenMySQL generates a mysql DSN from the passed URL .
func GenMySQL(u *URL) (string, error) {
	host, port, dbname := u.Hostname(), u.Port(), strings.TrimPrefix(u.Path, "/")
	var dsn string
	if u.User != nil {
		if n := u.User.Username(); n != "" {
			if p, ok := u.User.Password(); ok {
				n += ":" + p
			}
			dsn += n + "@"
		}
	}
	if u.Transport == "unix" {
		if host == "" {
			dbname = "/" + dbname
		}
		host, dbname = resolveSocket(stdpath.Join(host, dbname))
		port = ""
	}
	if u.hostPortDB == nil {
		u.hostPortDB = []string{host, port, dbname}
	}
	if u.Transport != "unix" {
		if host == "" {
			host = "localhost"
		}
		if port == "" {
			port = "3306"
		}
	}
	if port != "" {
		port = ":" + port
	}
	dsn += u.Transport + "(" + host + port + ")" + "/" + dbname
	return dsn + genQueryOptions(u.Query()), nil
}
func GenMySQL ( u * URL ) ( string , error ) { host , port , dbname := u . Hostname ( ) , u . Port ( ) , strings . TrimPrefix ( u . Path , " " ) var dsn string if u . User != nil { if n := u . User . Username ( ) ; n != " " { if p , ok := u . User . Password ( ) ; ok { n += " " + p } dsn += n + " " } } if u . Transport == " " { if host == " " { dbname = " " + dbname } host , dbname = resolveSocket ( stdpath . Join ( host , dbname ) ) port = " " } if u . hostPortDB == nil { u . hostPortDB = [ ] string { host , port , dbname } } if u . Transport != " " { if host == " " { host = " " } if port == " " { port = " " } } if port != " " { port = " " + port } dsn += u . Transport + " " + host + port + " " + " " + dbname return dsn + genQueryOptions ( u . Query ( ) ) , nil }
GenMySQL generates a mysql DSN from the passed URL.
GenMySQL generates a mysql DSN from the passed URL .
// build dsn // resolve path // save host, port, dbname // if host or proto is not empty // add proto and database