func parseIdentifierURL(url *gourl.URL) (*URL, error) {
	r := URL{
		Schema:   CharmHub.String(),
		Revision: -1,
	}

	path := url.Path
	if url.Opaque != "" {
		path = url.Opaque
	}

	parts := strings.Split(strings.Trim(path, "/"), "/")
	if len(parts) == 0 || len(parts) > 3 {
		return nil, errors.Errorf(`charm or bundle URL %q malformed`, url)
	}

	var nameRev string
	if num := len(parts); num == 3 {
		r.Architecture, r.Series, nameRev = parts[0], parts[1], parts[2]
	} else if num == 2 {
		r.Architecture, nameRev = parts[0], parts[1]
	} else {
		nameRev = parts[0]
	}

	// Mandatory
	r.Name, r.Revision = extractRevision(nameRev)
	if err := ValidateName(r.Name); err != nil {
		return nil, errors.Annotatef(err, "cannot parse name and/or revision in URL %q", url)
	}

	// Optional
	if r.Architecture != "" {
		if err := ValidateArchitecture(r.Architecture); err != nil {
			return nil, errors.Annotatef(err, "cannot parse architecture in URL %q", url)
		}
	}
	if r.Series != "" {
		if err := ValidateSeries(r.Series); err != nil {
			return nil, errors.Annotatef(err, "cannot parse series in URL %q", url)
		}
	}

	return &r, nil
}
// parseIdentifierURL will attempt to parse an identifier URL. The identifier
// URL is split up into 3 parts, some of which are optional and some are
// mandatory.
//
//  - architecture (optional)
//  - series (optional)
//  - name
//  - revision (optional)
//
// Examples are as follows:
//
//  - ch:amd64/foo-1
//  - ch:amd64/focal/foo-1
//  - ch:foo-1
//  - ch:foo
//  - ch:amd64/focal/foo
//
parseIdentifierURL will attempt to parse an identifier URL. The identifier
URL is split up into 3 parts, some of which are optional and some are
mandatory.



Examples are as follows.


// parseIdentifierURL will attempt to parse an identifier URL . The identifier // URL is split up into 3 parts some of which are optional and some are // mandatory . // // - architecture ( optional ) // - series ( optional ) // - name // - revision ( optional ) // // Examples are as follows : // // - ch : amd64 / foo - 1 // - ch : amd64 / focal / foo - 1 // - ch : foo - 1 // - ch : foo // - ch : amd64 / focal / foo //
func parseIdentifierURL(url *gourl.URL) (*URL, error) {
	r := URL{
		Schema:   CharmHub.String(),
		Revision: -1,
	}
	path := url.Path
	if url.Opaque != "" {
		path = url.Opaque
	}
	parts := strings.Split(strings.Trim(path, "/"), "/")
	if len(parts) == 0 || len(parts) > 3 {
		return nil, errors.Errorf(`charm or bundle URL %q malformed`, url)
	}
	var nameRev string
	if num := len(parts); num == 3 {
		r.Architecture, r.Series, nameRev = parts[0], parts[1], parts[2]
	} else if num == 2 {
		r.Architecture, nameRev = parts[0], parts[1]
	} else {
		nameRev = parts[0]
	}
	r.Name, r.Revision = extractRevision(nameRev)
	if err := ValidateName(r.Name); err != nil {
		return nil, errors.Annotatef(err, "cannot parse name and/or revision in URL %q", url)
	}
	if r.Architecture != "" {
		if err := ValidateArchitecture(r.Architecture); err != nil {
			return nil, errors.Annotatef(err, "cannot parse architecture in URL %q", url)
		}
	}
	if r.Series != "" {
		if err := ValidateSeries(r.Series); err != nil {
			return nil, errors.Annotatef(err, "cannot parse series in URL %q", url)
		}
	}
	return &r, nil
}
func parseIdentifierURL ( url * gourl . URL ) ( * URL , error ) { r := URL { Schema : CharmHub . String ( ) , Revision : - 1 , } path := url . Path if url . Opaque != " " { path = url . Opaque } parts := strings . Split ( strings . Trim ( path , " " ) , " " ) if len ( parts ) == 0 || len ( parts ) > 3 { return nil , errors . Errorf ( `charm or bundle URL %q malformed` , url ) } var nameRev string if num := len ( parts ) ; num == 3 { r . Architecture , r . Series , nameRev = parts [ 0 ] , parts [ 1 ] , parts [ 2 ] } else if num == 2 { r . Architecture , nameRev = parts [ 0 ] , parts [ 1 ] } else { nameRev = parts [ 0 ] } r . Name , r . Revision = extractRevision ( nameRev ) if err := ValidateName ( r . Name ) ; err != nil { return nil , errors . Annotatef ( err , " " , url ) } if r . Architecture != " " { if err := ValidateArchitecture ( r . Architecture ) ; err != nil { return nil , errors . Annotatef ( err , " " , url ) } } if r . Series != " " { if err := ValidateSeries ( r . Series ) ; err != nil { return nil , errors . Annotatef ( err , " " , url ) } } return & r , nil }
parseIdentifierURL will attempt to parse an identifier URL.
parseIdentifierURL will attempt to parse an identifier URL .
// Mandatory // Optional