43 lines
730 B
Go
43 lines
730 B
Go
|
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. 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]
|
||
|
}
|
||
|
exttype = elements[numberOfElements - 1]
|
||
|
}
|
||
|
return
|
||
|
}
|
||
|
|