// Parse parses urlstr, returning a URL with the OriginalScheme, Transport, Driver,
// Unaliased, and DSN fields populated.
//
// Note: if urlstr has a Opaque component (ie, URLs not specified as "scheme://"
// but "scheme:"), and the database scheme does not support opaque components,
// then Parse will attempt to re-process the URL as "scheme://<opaque>" using
// the OriginalScheme.
Parse parses urlstr, returning a URL with the OriginalScheme, Transport, Driver,
Unaliased, and DSN fields populated.

if urlstr has a Opaque component , and the database scheme does not support opaque components,
then Parse will attempt to re-process the URL as "scheme://" using
the OriginalScheme.
// Parse parses urlstr returning a URL with the OriginalScheme Transport Driver // Unaliased and DSN fields populated . // // Note : if urlstr has a Opaque component ( ie URLs not specified as " scheme : // " // but " scheme : " ) and the database scheme does not support opaque components // then Parse will attempt to re - process the URL as " scheme : // <opaque > " using // the OriginalScheme .
func Parse(urlstr string) (*URL, error) {
	u, err := url.Parse(urlstr)
	if err != nil {
		return nil, err
	}
	if u.Scheme == "" {
		return nil, ErrInvalidDatabaseScheme
	}
	v := &URL{URL: *u, OriginalScheme: urlstr[:len(u.Scheme)], Transport: "tcp"}
	var checkTransport bool
	if i := strings.IndexRune(v.Scheme, '+'); i != -1 {
		v.Transport = urlstr[i+1 : len(u.Scheme)]
		v.Scheme = v.Scheme[:i]
		checkTransport = true
	}
	scheme, ok := schemeMap[v.Scheme]
	if !ok {
		return nil, ErrUnknownDatabaseScheme
	}
	if !scheme.Opaque && v.Opaque != "" {
		q := ""
		if v.RawQuery != "" {
			q = "?" + v.RawQuery
		}
		f := ""
		if v.Fragment != "" {
			f = "#" + v.Fragment
		}
		return Parse(v.OriginalScheme + "://" + v.Opaque + q + f)
	}
	if scheme.Opaque && v.Opaque == "" {
		v.Opaque, v.Host, v.Path, v.RawPath = v.Host+v.Path, "", "", ""
	} else if v.Host == "." || (v.Host == "" && strings.TrimPrefix(v.Path, "/") != "") {
		v.Transport = "unix"
	}
	if checkTransport || v.Transport != "tcp" {
		if scheme.Transport == TransportNone {
			return nil, ErrInvalidTransportProtocol
		}
		switch {
		case scheme.Transport&TransportAny != 0 && v.Transport != "",
			scheme.Transport&TransportTCP != 0 && v.Transport == "tcp",
			scheme.Transport&TransportUDP != 0 && v.Transport == "udp",
			scheme.Transport&TransportUnix != 0 && v.Transport == "unix":
		default:
			return nil, ErrInvalidTransportProtocol
		}
	}
	v.Driver, v.Unaliased = scheme.Driver, scheme.Driver
	if scheme.Override != "" {
		v.Driver = scheme.Override
	}
	v.DSN, err = scheme.Generator(v)
	if err != nil {
		return nil, err
	}
	return v, nil
}
func Parse ( urlstr string ) ( * URL , error ) { u , err := url . Parse ( urlstr ) if err != nil { return nil , err } if u . Scheme == " " { return nil , ErrInvalidDatabaseScheme } v := & URL { URL : * u , OriginalScheme : urlstr [ : len ( u . Scheme ) ] , Transport : " " } var checkTransport bool if i := strings . IndexRune ( v . Scheme , '+' ) ; i != - 1 { v . Transport = urlstr [ i + 1 : len ( u . Scheme ) ] v . Scheme = v . Scheme [ : i ] checkTransport = true } scheme , ok := schemeMap [ v . Scheme ] if ! ok { return nil , ErrUnknownDatabaseScheme } if ! scheme . Opaque && v . Opaque != " " { q := " " if v . RawQuery != " " { q = " " + v . RawQuery } f := " " if v . Fragment != " " { f = " " + v . Fragment } return Parse ( v . OriginalScheme + " " + v . Opaque + q + f ) } if scheme . Opaque && v . Opaque == " " { v . Opaque , v . Host , v . Path , v . RawPath = v . Host + v . Path , " " , " " , " " } else if v . Host == " " || ( v . Host == " " && strings . TrimPrefix ( v . Path , " " ) != " " ) { v . Transport = " " } if checkTransport || v . Transport != " " { if scheme . Transport == TransportNone { return nil , ErrInvalidTransportProtocol } switch { case scheme . Transport & TransportAny != 0 && v . Transport != " " , scheme . Transport & TransportTCP != 0 && v . Transport == " " , scheme . Transport & TransportUDP != 0 && v . Transport == " " , scheme . Transport & TransportUnix != 0 && v . Transport == " " : default : return nil , ErrInvalidTransportProtocol } } v . Driver , v . Unaliased = scheme . Driver , scheme . Driver if scheme . Override != " " { v . Driver = scheme . Override } v . DSN , err = scheme . Generator ( v ) if err != nil { return nil , err } return v , nil }
Parse parses urlstr, returning a URL with the OriginalScheme, Transport, Driver,
Unaliased, and DSN fields populated.
Parse parses urlstr returning a URL with the OriginalScheme Transport Driver Unaliased and DSN fields populated .
// parse url // create url // check for +transport in scheme // get dsn generator // if scheme does not understand opaque URLs, retry parsing after making a fully // qualified URL // force Opaque // force unix proto // check proto // set driver // generate dsn