jx/internal/identifier/id.go

47 lines
806 B
Go
Raw Normal View History

2024-08-15 15:12:42 +00:00
// 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]
2024-08-18 01:19:22 +00:00
} else {
exttype = elements[numberOfElements - 1]
2024-08-15 15:12:42 +00:00
}
}
2024-08-18 01:19:22 +00:00
return exttype, fileext
2024-08-15 15:12:42 +00:00
}
2024-09-19 07:59:38 +00:00
func (i ID) IsEmpty() bool {
return i == ""
}