// GenMyMySQL generates a MyMySQL MySQL DSN from the passed URL.
GenMyMySQL generates a MyMySQL MySQL DSN from the passed URL.
// GenMyMySQL generates a MyMySQL MySQL DSN from the passed URL .
func GenMyMySQL(u *URL) (string, error) {
	host, port, dbname := u.Hostname(), u.Port(), strings.TrimPrefix(u.Path, "/")
	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
	dsn += genOptions(
		convertOptions(u.Query(), "true", ""),
		",", "=", ",", " ", false,
	)
	dsn += "*" + dbname
	if u.User != nil {
		pass, _ := u.User.Password()
		dsn += "/" + u.User.Username() + "/" + pass
	} else if strings.HasSuffix(dsn, "*") {
		dsn += "//"
	}
	return dsn, nil
}
func GenMyMySQL ( u * URL ) ( string , error ) { host , port , dbname := u . Hostname ( ) , u . Port ( ) , strings . TrimPrefix ( u . Path , " " ) 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 dsn += genOptions ( convertOptions ( u . Query ( ) , " " , " " ) , " " , " " , " " , " " , false , ) dsn += " " + dbname if u . User != nil { pass , _ := u . User . Password ( ) dsn += " " + u . User . Username ( ) + " " + pass } else if strings . HasSuffix ( dsn , " " ) { dsn += " " } return dsn , nil }
GenMyMySQL generates a MyMySQL MySQL DSN from the passed URL.
GenMyMySQL generates a MyMySQL MySQL DSN from the passed URL .
// resolve path // save host, port, dbname // if host or proto is not empty // build dsn