// Copyright 2024 Matthew Rich . All rights reserved. package identifier import ( "net/url" "errors" "strings" ) var ( ErrInvalidURI error = errors.New("Invalid URI") ) type ID string func (i *ID) SetURL(u *url.URL) { *i = ID(u.String()) } func (i ID) Parse() *url.URL { url, e := url.Parse(string(i)) if e == nil { return url } return nil } func (i ID) Extension() (exttype string, fileext string) { elements := strings.Split(string(i), ".") numberOfElements := len(elements) if numberOfElements > 1 { if numberOfElements > 2 { exttype = elements[numberOfElements - 2] fileext = elements[numberOfElements - 1] } else { exttype = elements[numberOfElements - 1] } } return exttype, fileext } func (i ID) IsEmpty() bool { return i == "" }