resource

package
v0.3.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetParentLocation

func GetParentLocation(location string) (*url.URL, error)

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

func GetURLParentLocation(url *url.URL) *url.URL

GetURLParentLocation returns the parent location of a URL.

func IsWriteSupported

func IsWriteSupported(url *url.URL) bool

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

func OpenAppend(ctx context.Context, url *url.URL, perm os.FileMode) (io.WriteCloser, error)

OpenAppend opens a resource for append.

func OpenRead

func OpenRead(ctx context.Context, url *url.URL) (io.ReadCloser, error)

OpenRead opens a URL resource for reading.

http(s) and file schemes are supported.

func OpenTruncate

func OpenTruncate(ctx context.Context, url *url.URL, perm os.FileMode) (io.WriteCloser, error)

OpenTruncate opens a a resource and truncates it.

func ReadResource

func ReadResource(ctx context.Context, pathParts ...string) ([]byte, error)

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 ReadURL

func ReadURL(ctx context.Context, url *url.URL) ([]byte, error)

ReadURL reads the contents located by the url into a byte slice or returns an error.

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

func Remove(ctx context.Context, url *url.URL) error

Remove deletes a file resource identified by the url. other resource types return an error.

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 URLToPath

func URLToPath(url *url.URL) (string, error)

URLToPath returns a file system path too the resource or an error.

func URLToRelativePath

func URLToRelativePath(url *url.URL, baseParts ...string) (string, error)

URLToRelativePath returns a file system path too the resource or an error.

func UltimateURL

func UltimateURL(pathParts ...string) (*url.URL, error)

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.

type Progress

type Progress func(string, *url.URL, *NotFoundError)

Progress functions are called by Search with the result of each source search.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL