jx/internal/identifier/id.go
Matthew Rich 06f3247b08
Some checks failed
Lint / golangci-lint (push) Has been cancelled
Declarative Tests / test (push) Has been cancelled
Declarative Tests / build-fedora (push) Has been cancelled
Declarative Tests / build-ubuntu-focal (push) Has been cancelled
add interfaces
2024-08-15 08:12:42 -07:00

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
}