jx/internal/folio/uri.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

65 lines
1.2 KiB
Go

// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
package folio
import (
"net/url"
"decl/internal/transport"
"decl/internal/data"
"decl/internal/identifier"
"errors"
)
var (
ErrInvalidURI error = errors.New("Invalid URI")
)
type URI identifier.ID
func (u URI) NewResource(document data.Document) (newResource data.Resource, err error) {
if document == nil {
declaration := NewDeclaration()
if err = declaration.NewResource((*string)(&u)); err == nil {
return declaration.Attributes.(data.Resource), err
}
} else {
newResource, err = document.NewResource(string(u))
return
}
return
}
func (u URI) Parse() *url.URL {
url, e := url.Parse(string(u))
if e == nil {
return url
}
return nil
}
func (u URI) Exists() bool {
return transport.ExistsURI(string(u))
}
func (u URI) ContentReaderStream() (*transport.Reader, error) {
return transport.NewReaderURI(string(u))
}
func (u URI) ContentWriterStream() (*transport.Writer, error) {
return transport.NewWriterURI(string(u))
}
func (u URI) String() string {
return string(u)
}
func (u *URI) SetURL(url *url.URL) {
(*identifier.ID)(u).SetURL(url)
}
func (u URI) Extension() (string, string) {
return (identifier.ID)(u).Extension()
}