jx/internal/identifier/id.go
Matthew Rich 4b38af88a4
Some checks are pending
Lint / golangci-lint (push) Waiting to run
Declarative Tests / test (push) Waiting to run
Declarative Tests / build-fedora (push) Waiting to run
Declarative Tests / build-ubuntu-focal (push) Waiting to run
add base URL parsing
2024-09-19 07:59:38 +00:00

47 lines
806 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]
} else {
exttype = elements[numberOfElements - 1]
}
}
return exttype, fileext
}
func (i ID) IsEmpty() bool {
return i == ""
}