url.go
func (u *URL) Normalize(sep, empty string, cut int) string {
	s := make([]string, 5)

	s[0] = u.Unaliased
	if u.Proto != "tcp" && u.Proto != "unix" {
		s[0] += "+" + u.Proto
	}

	// set host port dbname fields
	if u.hostPortDB == nil {
		if u.Opaque != "" {
			u.hostPortDB = []string{u.Opaque, "", ""}
		} else {
			u.hostPortDB = []string{
				hostname(u.Host),
				hostport(u.Host),
				strings.TrimPrefix(u.Path, "/"),
			}
		}
	}
	copy(s[1:], u.hostPortDB)

	// set user
	if u.User != nil {
		s[4] = u.User.Username()
	}

	// replace blank entries ...
	for i := 0; i < len(s); i++ {
		if s[i] == "" {
			s[i] = empty
		}
	}

	if cut > 0 {
		// cut to only populated fields
		i := len(s) - 1
		for ; i > cut; i-- {
			if s[i] != "" {
				break
			}
		}
		s = s[:i]
	}

	// join
	return strings.Join(s, sep)
}
func (u *URL) Normalize(sep, empty string, cut int) string {
	s := make([]string, 5)

	s[0] = u.Unaliased
	if u.Proto != "tcp" && u.Proto != "unix" {
		s[0] += "+" + u.Proto
	}

	// set host port dbname fields
	if u.hostPortDB == nil {
		if u.Opaque != "" {
			u.hostPortDB = []string{u.Opaque, "", ""}
		} else {
			u.hostPortDB = []string{
				hostname(u.Host),
				hostport(u.Host),
				strings.TrimPrefix(u.Path, "/"),
			}
		}
	}
	copy(s[1:], u.hostPortDB)

	// set user
	if u.User != nil {
		s[4] = u.User.Username()
	}

	// replace blank entries ...
	for i := 0; i < len(s); i++ {
		if s[i] == "" {
			s[i] = empty
		}
	}

	if cut > 0 {
		// cut to only populated fields
		i := len(s) - 1
		for ; i > cut; i-- {
			if s[i] != "" {
				break
			}
		}
		s = s[:i]
	}

	// join
	return strings.Join(s, sep)
}
// Normalize returns the driver, host, port, database, and user name of a URL,
// joined with sep, populating blank fields with empty.