Documentation ¶
Index ¶
- func GetParentLocation(location string) (*url.URL, error)
- func GetURLParentLocation(url *url.URL) *url.URL
- func IsWriteSupported(url *url.URL) bool
- func NewReadCloser(reader io.Reader) io.ReadCloser
- func NewWriteCloser(writer io.Writer) io.WriteCloser
- func OpenAppend(ctx context.Context, url *url.URL, perm os.FileMode) (io.WriteCloser, error)
- func OpenRead(ctx context.Context, url *url.URL) (io.ReadCloser, error)
- func OpenTruncate(ctx context.Context, url *url.URL, perm os.FileMode) (io.WriteCloser, error)
- func ReadResource(ctx context.Context, pathParts ...string) ([]byte, error)
- func ReadURL(ctx context.Context, url *url.URL) ([]byte, error)
- func Relative(any interface{}) string
- func Remove(ctx context.Context, url *url.URL) error
- func Search(ctx context.Context, relLocation string, progress Progress, ...) ([]byte, *url.URL, error)
- func URLToPath(url *url.URL) (string, error)
- func URLToRelativePath(url *url.URL, baseParts ...string) (string, error)
- func UltimateURL(pathParts ...string) (*url.URL, error)
- type NotFoundError
- type Progress
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetParentLocation ¶
GetParentLocation takes a filesystem or url path and returns a url representing the partent of the path. If there is no parent, the url will contain a path of ".".
func GetURLParentLocation ¶
GetURLParentLocation returns the parent location of a URL.
func IsWriteSupported ¶
IsWriteSupported returns true if the url can be written to by this package If true this does not mean the caller has permission r right too write only that Open/Write methods can be called.
func NewReadCloser ¶
func NewReadCloser(reader io.Reader) io.ReadCloser
NewReadCloser creates a reader closer from a reader. The close operation is a no op. This type can be used when a interface requires a reader closer.
func NewWriteCloser ¶
func NewWriteCloser(writer io.Writer) io.WriteCloser
NewWriteCloser creates a writer closer from a reader. The close operation is a no op. This type can be used when a interface requires a reader closer.
func OpenAppend ¶
OpenAppend opens a resource for append.
func OpenTruncate ¶
OpenTruncate opens a a resource and truncates it.
func ReadResource ¶
ReadResource reads a resource into a byte array or returns an error. The resource parts are merged left to right using UltimateURL. Once defined the url is then access and read. Relative url paths are supported only if they ultimately resolve to an absolute url.
func Relative ¶
func Relative(any interface{}) string
Relative returns the best relative path to the current working directory If its file this will be a OS path, if its not it will be the the URL.
func Remove ¶
Remove deletes a file resource identified by the url. other resource types return an error.
func Search ¶
func Search(ctx context.Context, relLocation string, progress Progress, absSources ...string) ([]byte, *url.URL, error)
Search searches for a resource against a list of sources. If the resource is found tts contents are returned along with the url on which itt was located. If the resource could not be found an error is returned. The search will stop on any error other than a not found error. The relLocation and absSources are merged using UltimateURL.
func URLToRelativePath ¶
URLToRelativePath returns a file system path too the resource or an error.
func UltimateURL ¶
UltimateURL returns a url or an error. The path parts are merged left to right to create a resource path which is then encoded as a UrL The parts may be either a file system path or a url in the file or http(s) schemes. pathParts are relative to the merger of the preceding parts. If no absolute path is provided the current working directory is used as the root directory.
Examples of supported part formats ¶
windows: c:\\windows\\something or .\\windows\\file spaced.doc" or c:/something
unc: \\\\server\\share\\path unix: /root/url/bin/somthing or ~/.home/thing or ../bin/go https: https://server/resource file: file:/somedata or file:///somedata or file:///c:/windows/clock.avi
Support for both os windows and unix styles.
Types ¶
type NotFoundError ¶
type NotFoundError struct {
// contains filtered or unexported fields
}
NotFoundError indicates a resource cannot be found.
func IsNotFoundError ¶
func IsNotFoundError(err error) *NotFoundError
IsNotFoundError checks if an error is a *NotFoundError and if soo return it. If it is not nil is returned.
func NewNotFoundError ¶
func NewNotFoundError(resource string, cause error) *NotFoundError
NewNotFoundError creates a new not found resource error. The cause should any error raised by the underlying resource open call. If no cause is provided a generic cause is added. The resource can be access via the Resource() method.
func (*NotFoundError) Error ¶
func (nfe *NotFoundError) Error() string
Error converts the errorinto a string.
func (*NotFoundError) Resource ¶
func (nfe *NotFoundError) Resource() string
Resource returns the resource that was not found.
func (*NotFoundError) Unwrap ¶
func (nfe *NotFoundError) Unwrap() error
Unwrap provides access to the causing error.