Documentation ¶
Index ¶
- Constants
- Variables
- func DeleteTemporaryDir(path string) error
- func DeleteTemporaryFile(path string) error
- func DeregisterInternalURL(path string)
- func Download(context contextpkg.Context, url URL, temporaryPathPattern string) (*os.File, error)
- func DownloadTo(context contextpkg.Context, url URL, path string) error
- func GetFormat(path string) string
- func GetPath(url URL) (string, error)
- func GetTemporaryPathPattern(key string) string
- func IsNotFound(err error) bool
- func IsNotImplemented(err error) bool
- func IsValidTarballArchiveFormat(archiveFormat string) bool
- func ReadBytes(context contextpkg.Context, url URL) ([]byte, error)
- func ReadString(context contextpkg.Context, url URL) (string, error)
- func ReadToInternalURLsFromFS(context contextpkg.Context, fs fspkg.FS, root string, ...) error
- func RegisterInternalURL(path string, content any) error
- func Size(context contextpkg.Context, url URL) (int64, error)
- func ToNetURL(url URL) (*neturlpkg.URL, error)
- func URLPathToFilePath(path string) string
- func UpdateInternalURL(path string, content any)
- type Context
- func (self *Context) AddTransformer(transformer URLTransformerFunc)
- func (self *Context) GetCredentials(host string) *Credentials
- func (self *Context) GetHTTPRoundTripper(host string) http.RoundTripper
- func (self *Context) GetLocalPath(context contextpkg.Context, url URL) (string, error)
- func (self *Context) GetMapping(fromUrl string) (string, bool)
- func (self *Context) Map(fromUrl string, toUrl string)
- func (self *Context) NewAnyOrFileURL(urlOrPath string) URL
- func (self *Context) NewDockerURL(neturl *neturlpkg.URL) *DockerURL
- func (self *Context) NewFileURL(filePath string) *FileURL
- func (self *Context) NewGitURL(path string, repositoryUrl string) *GitURL
- func (self *Context) NewInternalURL(path string) *InternalURL
- func (self *Context) NewMockURL(scheme string, path string, content any) *MockURL
- func (self *Context) NewNetworkURL(neturl *neturlpkg.URL) *NetworkURL
- func (self *Context) NewURL(url string) (URL, error)
- func (self *Context) NewValidAnyOrFileURL(context contextpkg.Context, urlOrPath string, bases []URL) (URL, error)
- func (self *Context) NewValidDockerURL(neturl *neturlpkg.URL) (*DockerURL, error)
- func (self *Context) NewValidFileURL(filePath string) (*FileURL, error)
- func (self *Context) NewValidGitURL(path string, repositoryUrl string) (*GitURL, error)
- func (self *Context) NewValidInternalURL(path string) (*InternalURL, error)
- func (self *Context) NewValidNetworkURL(neturl *neturlpkg.URL) (*NetworkURL, error)
- func (self *Context) NewValidURL(context contextpkg.Context, urlOrPath string, bases []URL) (URL, error)
- func (self *Context) NewWorkingDirFileURL() (*FileURL, error)
- func (self *Context) OpenFile(context contextpkg.Context, url URL) (*os.File, error)
- func (self *Context) ParseGitURL(url string) (*GitURL, error)
- func (self *Context) ParseTarballURL(url string) (*TarballURL, error)
- func (self *Context) ParseValidGitURL(url string) (*GitURL, error)
- func (self *Context) ParseValidTarballURL(context contextpkg.Context, url string) (*TarballURL, error)
- func (self *Context) ParseValidZipURL(context contextpkg.Context, url string) (*ZipURL, error)
- func (self *Context) ParseZipURL(url string) (*ZipURL, error)
- func (self *Context) ReadToInternalURL(path string, reader io.Reader) (*InternalURL, error)
- func (self *Context) ReadToInternalURLFromStdin(context contextpkg.Context, format string) (*InternalURL, error)
- func (self *Context) Release() error
- func (self *Context) SetCredentials(host string, username string, password string, token string)
- func (self *Context) SetHTTPRoundTripper(host string, httpRoundTripper http.RoundTripper)
- func (self *Context) Transform(fromUrl string) (string, bool)
- type Credentials
- type DockerURL
- func (self *DockerURL) Base() URL
- func (self *DockerURL) Context() *Context
- func (self *DockerURL) Format() string
- func (self *DockerURL) Key() string
- func (self *DockerURL) Open(context contextpkg.Context) (io.ReadCloser, error)
- func (self *DockerURL) Relative(path string) URL
- func (self *DockerURL) RemoteOptions(context contextpkg.Context) []remote.Option
- func (self *DockerURL) String() string
- func (self *DockerURL) ValidRelative(context contextpkg.Context, path string) (URL, error)
- func (self *DockerURL) WriteFirstLayer(context contextpkg.Context, writer io.Writer) error
- func (self *DockerURL) WriteTarball(context contextpkg.Context, writer io.Writer) error
- type FileURL
- func (self *FileURL) Base() URL
- func (self *FileURL) Context() *Context
- func (self *FileURL) Format() string
- func (self *FileURL) Key() string
- func (self *FileURL) Open(context contextpkg.Context) (io.ReadCloser, error)
- func (self *FileURL) Relative(path string) URL
- func (self *FileURL) String() string
- func (self *FileURL) ValidRelative(context contextpkg.Context, filePath string) (URL, error)
- type GitURL
- func (self *GitURL) Base() URL
- func (self *GitURL) Context() *Context
- func (self *GitURL) Format() string
- func (self *GitURL) Key() string
- func (self *GitURL) Open(context contextpkg.Context) (io.ReadCloser, error)
- func (self *GitURL) OpenRepository() (*git.Repository, error)
- func (self *GitURL) Relative(path string) URL
- func (self *GitURL) String() string
- func (self *GitURL) ValidRelative(context contextpkg.Context, path string) (URL, error)
- type InternalURL
- func (self *InternalURL) Base() URL
- func (self *InternalURL) Context() *Context
- func (self *InternalURL) Format() string
- func (self *InternalURL) Key() string
- func (self *InternalURL) Open(context contextpkg.Context) (io.ReadCloser, error)
- func (self *InternalURL) Relative(path string) URL
- func (self *InternalURL) SetContent(content any)
- func (self *InternalURL) String() string
- func (self *InternalURL) ValidRelative(context contextpkg.Context, path string) (URL, error)
- type InternalURLProvider
- type MockURL
- func (self *MockURL) Base() URL
- func (self *MockURL) Context() *Context
- func (self *MockURL) Format() string
- func (self *MockURL) Key() string
- func (self *MockURL) Open(context contextpkg.Context) (io.ReadCloser, error)
- func (self *MockURL) Relative(path string) URL
- func (self *MockURL) SetContent(content any)
- func (self *MockURL) String() string
- func (self *MockURL) ValidRelative(context contextpkg.Context, path string) (URL, error)
- type NetworkURL
- func (self *NetworkURL) Base() URL
- func (self *NetworkURL) Context() *Context
- func (self *NetworkURL) Format() string
- func (self *NetworkURL) Key() string
- func (self *NetworkURL) Open(context contextpkg.Context) (io.ReadCloser, error)
- func (self *NetworkURL) Relative(path string) URL
- func (self *NetworkURL) String() string
- func (self *NetworkURL) ValidRelative(context contextpkg.Context, path string) (URL, error)
- type NotFound
- type NotImplemented
- type TarballURL
- func (self *TarballURL) Base() URL
- func (self *TarballURL) Context() *Context
- func (self *TarballURL) Format() string
- func (self *TarballURL) Key() string
- func (self *TarballURL) Open(context contextpkg.Context) (io.ReadCloser, error)
- func (self *TarballURL) OpenArchive(context contextpkg.Context) (*util.TarballReader, error)
- func (self *TarballURL) Relative(path string) URL
- func (self *TarballURL) String() string
- func (self *TarballURL) ValidRelative(context contextpkg.Context, path string) (URL, error)
- type URL
- type URLTransformerFunc
- type ZipEntryReader
- type ZipReader
- type ZipURL
- func (self *ZipURL) Base() URL
- func (self *ZipURL) Context() *Context
- func (self *ZipURL) Format() string
- func (self *ZipURL) Key() string
- func (self *ZipURL) Open(context contextpkg.Context) (io.ReadCloser, error)
- func (self *ZipURL) OpenArchive(context contextpkg.Context) (*ZipReader, error)
- func (self *ZipURL) Relative(path string) URL
- func (self *ZipURL) String() string
- func (self *ZipURL) ValidRelative(context contextpkg.Context, path string) (URL, error)
Constants ¶
const PathSeparator = string(filepath.Separator)
Variables ¶
var TARBALL_ARCHIVE_FORMATS = []string{"tar", "tar.gz"}
Functions ¶
func DeleteTemporaryDir ¶
func DeleteTemporaryFile ¶
func DeregisterInternalURL ¶
func DeregisterInternalURL(path string)
Deletes registers content for InternalURL or does nothing if the content is not registered.
func DownloadTo ¶
func DownloadTo(context contextpkg.Context, url URL, path string) error
func GetTemporaryPathPattern ¶ added in v0.2.4
func IsNotFound ¶
func IsNotImplemented ¶ added in v0.2.8
func ReadString ¶
func ReadString(context contextpkg.Context, url URL) (string, error)
func ReadToInternalURLsFromFS ¶ added in v0.2.7
func ReadToInternalURLsFromFS(context contextpkg.Context, fs fspkg.FS, root string, translatePath func(path string) (string, bool)) error
Walks a io/fs.FS starting at "root" and registers its files' content for InternalURL. "root" can be an emptry string to read the entire FS.
The optional argument "translatePath" is a function that can translate the FS path to an internal URL path and can also filter out entries when it returns false. If the argument is not provided all files will be read with their paths as is.
If "fs" is an embed.FS, this function is optimized to handle it more efficiently via calls to embed.FS.ReadFile.
Will return an error if there is already content registered at an internal path.
func RegisterInternalURL ¶
Registers content for InternalURL.
"content" can be []byte or an InternalURLProvider. Other types will be converted to string and then to []byte.
Will return an error if there is already content registered at the path. For a version that always succeeds, use UpdateInternalURL.
func URLPathToFilePath ¶ added in v0.2.1
func UpdateInternalURL ¶
Updates registered content for InternalURL or registers it if not yet registered.
"content" can be []byte or an InternalURLProvider. Other types will be converted to string and then to []byte.
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
func NewContext ¶
func NewContext() *Context
func (*Context) AddTransformer ¶ added in v0.4.0
func (self *Context) AddTransformer(transformer URLTransformerFunc)
func (*Context) GetCredentials ¶
func (self *Context) GetCredentials(host string) *Credentials
Not thread-safe
func (*Context) GetHTTPRoundTripper ¶
func (self *Context) GetHTTPRoundTripper(host string) http.RoundTripper
Not thread-safe
func (*Context) GetLocalPath ¶
Will download the file to the local temporary directory if not already locally available
func (*Context) GetMapping ¶
URLTransformerFunc signature
func (*Context) NewAnyOrFileURL ¶ added in v0.3.1
Parses the argument as either an absolute URL or a file path.
In essence attempts to parse the URL via Context.NewURL and if that fails treats the URL as a file path and returns a *FileURL.
To support relative URLs, see Context.NewValidAnyOrFileURL.
On Windows note that if there happens to be a drive that has the same name as a supported URL scheme (e.g. "http") then callers would have to provide a full file URL, e.g. instead of "http:\Dir\file" provide "file:///http:/Dir/file", otherwise it will be parsed as a URL of that scheme.
func (*Context) NewDockerURL ¶ added in v0.2.0
func (*Context) NewFileURL ¶ added in v0.2.0
Note that the argument is treated as an OS file path (using backslashes on Windows). The path must be absolute.
Directories must be suffixed with an OS path separator.
func (*Context) NewInternalURL ¶ added in v0.2.0
func (self *Context) NewInternalURL(path string) *InternalURL
func (*Context) NewMockURL ¶ added in v0.2.9
"content" can be []byte or an InternalURLProvider. Other types will be converted to string and then to []byte.
func (*Context) NewNetworkURL ¶ added in v0.2.0
func (self *Context) NewNetworkURL(neturl *neturlpkg.URL) *NetworkURL
func (*Context) NewURL ¶ added in v0.2.0
Parses the argument as an absolute URL.
To support relative URLs, see Context.NewValidURL.
If you are expecting either a URL or a file path, consider Context.NewAnyOrFileURL.
func (*Context) NewValidAnyOrFileURL ¶ added in v0.3.1
func (self *Context) NewValidAnyOrFileURL(context contextpkg.Context, urlOrPath string, bases []URL) (URL, error)
Parses the argument as an absolute URL or an absolute file path or a relative path. Relative paths support ".." and ".", with the returned URL path always being absolute.
The returned URL is "valid", meaning that during this call it was possible to call Open on it. Of course this can't guarantee that future calls to Open will succeed.
Relative URLs are tested against the "bases" argument in order. The first valid URL will be returned and the remaining bases will be ignored. Note that bases can be any of any URL type.
func (*Context) NewValidDockerURL ¶ added in v0.2.0
func (*Context) NewValidFileURL ¶ added in v0.2.0
Note that the argument is treated as an OS file path (using backslashes on Windows). The path must be absolute.
If the path is a directory, it will automatically be suffixed with an OS path separator if it doesn't already have one.
func (*Context) NewValidGitURL ¶ added in v0.2.0
func (*Context) NewValidInternalURL ¶ added in v0.2.0
func (self *Context) NewValidInternalURL(path string) (*InternalURL, error)
func (*Context) NewValidNetworkURL ¶ added in v0.2.0
func (self *Context) NewValidNetworkURL(neturl *neturlpkg.URL) (*NetworkURL, error)
func (*Context) NewValidURL ¶ added in v0.2.0
func (self *Context) NewValidURL(context contextpkg.Context, urlOrPath string, bases []URL) (URL, error)
Parses the argument as either an absolute URL or a relative path. Relative paths support ".." and ".", with the returned URL path always being absolute.
The returned URL is "valid", meaning that during this call it was possible to call Open on it. Of course this can't guarantee that future calls to Open will succeed.
Relative URLs are tested against the "bases" argument in order. The first valid URL will be returned and the remaining bases will be ignored. Note that bases can be any of any URL type.
If you are expecting either a URL or a file path, consider Context.NewValidAnyOrFileURL.
func (*Context) NewWorkingDirFileURL ¶ added in v0.3.0
A valid URL for the working directory.
func (*Context) ParseGitURL ¶ added in v0.2.0
func (*Context) ParseTarballURL ¶ added in v0.2.0
func (self *Context) ParseTarballURL(url string) (*TarballURL, error)
func (*Context) ParseValidGitURL ¶ added in v0.2.0
func (*Context) ParseValidTarballURL ¶ added in v0.2.0
func (self *Context) ParseValidTarballURL(context contextpkg.Context, url string) (*TarballURL, error)
func (*Context) ParseValidZipURL ¶ added in v0.2.0
func (*Context) ParseZipURL ¶ added in v0.2.0
func (*Context) ReadToInternalURL ¶ added in v0.2.0
Registers content for InternalURL from an io.Reader.
Will automatically close "reader" if it supports io.Closer.
Will return an error if there is already content registered at the path.
func (*Context) ReadToInternalURLFromStdin ¶ added in v0.2.0
func (self *Context) ReadToInternalURLFromStdin(context contextpkg.Context, format string) (*InternalURL, error)
Registers content for InternalURL from os.Stdin. "format" can be an empty string.
The URL will have a globally unique path in the form of "/stdin/GUID[.FORMAT]". The "format" extension is used to support URL.Format.
func (*Context) SetCredentials ¶
Not thread-safe
func (*Context) SetHTTPRoundTripper ¶
func (self *Context) SetHTTPRoundTripper(host string, httpRoundTripper http.RoundTripper)
Not thread-safe
type Credentials ¶
type DockerURL ¶
func (*DockerURL) Open ¶
func (self *DockerURL) Open(context contextpkg.Context) (io.ReadCloser, error)
(URL interface)
func (*DockerURL) RemoteOptions ¶
func (self *DockerURL) RemoteOptions(context contextpkg.Context) []remote.Option
func (*DockerURL) ValidRelative ¶ added in v0.4.0
(URL interface)
func (*DockerURL) WriteFirstLayer ¶ added in v0.2.2
func (*DockerURL) WriteTarball ¶
type FileURL ¶
type FileURL struct { // This is an absolute OS file path. // // That means that when compiled on Windows it will expect and use // backslashes as path separators in addition to other Windows // filesystem convnentions. Path string // contains filtered or unexported fields }
func (*FileURL) Open ¶
func (self *FileURL) Open(context contextpkg.Context) (io.ReadCloser, error)
(URL interface)
func (*FileURL) Relative ¶
Note that the argument can be a URL-type path or an OS file path (using backslashes on Windows).
Directories must be suffixed with an OS path separator.
(URL interface)
func (*FileURL) ValidRelative ¶ added in v0.4.0
Note that the argument can be a URL-type path or an OS file path (using backslashes on Windows).
If the path is a directory, it will automatically be suffixed with an OS path separator if it doesn't already have one.
(URL interface)
type GitURL ¶
type GitURL struct { Path string RepositoryURL string Reference string Username string Password string // contains filtered or unexported fields }
func (*GitURL) Open ¶
func (self *GitURL) Open(context contextpkg.Context) (io.ReadCloser, error)
(URL interface)
func (*GitURL) OpenRepository ¶
func (*GitURL) ValidRelative ¶ added in v0.4.0
(URL interface)
type InternalURL ¶
type InternalURL struct { Path string // If explicitly set to a non-nil value then it will override any globally // registered content when calling InternalURL.Open. // // []byte or InternalURLProvider. OverrideContent any // contains filtered or unexported fields }
func (*InternalURL) Open ¶
func (self *InternalURL) Open(context contextpkg.Context) (io.ReadCloser, error)
If InternalURL.Content was set to a non-nil value, then it will be used. Otherwise will attempt to retrieve the globally registered content.
(URL interface)
func (*InternalURL) SetContent ¶
func (self *InternalURL) SetContent(content any)
Updates the contents of this instance only. To change the globally registered content use UpdateInternalURL.
"content" can be []byte or an InternalURLProvider. Other types will be converted to string and then to []byte.
func (*InternalURL) ValidRelative ¶ added in v0.4.0
func (self *InternalURL) ValidRelative(context contextpkg.Context, path string) (URL, error)
(URL interface)
type InternalURLProvider ¶ added in v0.2.4
type InternalURLProvider interface {
OpenPath(context contextpkg.Context, path string) (io.ReadCloser, error)
}
type MockURL ¶ added in v0.2.9
type MockURL struct { Scheme string Path string Content any // []byte or InternalURLProvider // contains filtered or unexported fields }
func (*MockURL) Open ¶ added in v0.2.9
func (self *MockURL) Open(context contextpkg.Context) (io.ReadCloser, error)
(URL interface)
func (*MockURL) SetContent ¶ added in v0.4.0
Updates the contents of this instance only. To change the globally registered content use UpdateInternalURL.
"content" can be []byte or an InternalURLProvider. Other types will be converted to string and then to []byte.
func (*MockURL) String ¶ added in v0.2.9
(fmt.Stringer interface)
func (*MockURL) ValidRelative ¶ added in v0.4.0
(URL interface)
type NetworkURL ¶
func (*NetworkURL) Open ¶
func (self *NetworkURL) Open(context contextpkg.Context) (io.ReadCloser, error)
(URL interface)
func (*NetworkURL) ValidRelative ¶ added in v0.4.0
func (self *NetworkURL) ValidRelative(context contextpkg.Context, path string) (URL, error)
(URL interface)
type NotImplemented ¶ added in v0.2.8
type NotImplemented struct {
Message string
}
func NewNotImplemented ¶ added in v0.2.8
func NewNotImplemented(message string) *NotImplemented
func NewNotImplementedf ¶ added in v0.2.8
func NewNotImplementedf(format string, arg ...any) *NotImplemented
func (*NotImplemented) Error ¶ added in v0.2.8
func (self *NotImplemented) Error() string
(error interface)
type TarballURL ¶
func NewTarballURL ¶
func NewTarballURL(path string, archiveUrl URL, archiveFormat string) *TarballURL
func NewValidTarballURL ¶
func NewValidTarballURL(context contextpkg.Context, path string, archiveUrl URL, archiveFormat string) (*TarballURL, error)
func (*TarballURL) Open ¶
func (self *TarballURL) Open(context contextpkg.Context) (io.ReadCloser, error)
(URL interface)
func (*TarballURL) OpenArchive ¶
func (self *TarballURL) OpenArchive(context contextpkg.Context) (*util.TarballReader, error)
func (*TarballURL) ValidRelative ¶ added in v0.4.0
func (self *TarballURL) ValidRelative(context contextpkg.Context, path string) (URL, error)
(URL interface)
type URL ¶
type URL interface { fmt.Stringer // Format of the URL content's default representation. // // Can return "yaml", "json", "xml", etc., or an empty string if the format // is unknown. // // The format is often derived from a file extension if available, otherwise // it might be retrieved from metadata. // // An attempt is made to standardize the return values, e.g. a "yml" file // extension is always returned as "yaml", and a "tar.gz" file extension is // always returned as "tgz". Format() string // Returns a URL that is the equivalent of a "base directory" for this URL. // // Base URLs always often have a trailing slash to signify that they are // "directories" rather than "files". One notable exception is "file:" URLs // when compiled on Windows, in which case a trailing backslash is used // instead. // // The base is often used in two ways: // // 1. You can call URL.Relative on it to get a sibling URL to this one (relative // to the same "base directory"). // 2. You can use it in the "bases" list argument of Context.NewValidURL for the // same purpose. // // Note that the base might not be a valid URL in itself, e.g. you might not // be able to call Open on it. Base() URL // Parses the argument as a path relative to the URL. That means that this // URL is treated as a "base directory" (see URL.Base). The argument supports // ".." and ".", with the returned URL path always being absolute. Relative(path string) URL // As URL.Relative but returns a valid URL. ValidRelative(context contextpkg.Context, path string) (URL, error) // Returns a string that uniquely identifies the URL. // // Useful for map and cache keys. Key() string // Opens the URL for reading. // // Note that for some URLs it can involve lengthy operations, e.g. cloning a // remote repository or downloading an archive. For this reason a cancellable // context can be provided as an argument. // // An effort is made to not repeat these lengthy operations by caching related // state in the URL's exturl Context (caching is deliberately not done globally). // For example, when accessing a "git:" URL on a remote git repository then that // repository will be cloned locally only if it's the first the repository has been // referred to for the exturl Context. Subsequent Open calls for URLs that refer // to the same git repository will reuse the existing clone. // // It is the caller's responsibility to call Close on the reader. Open(context contextpkg.Context) (io.ReadCloser, error) // The exturl context used to create this URL. Context() *Context }
type URLTransformerFunc ¶ added in v0.4.0
type ZipEntryReader ¶
type ZipEntryReader struct { EntryReader io.ReadCloser ZipReader *ZipReader }
func NewZipEntryReader ¶
func NewZipEntryReader(entryReader io.ReadCloser, zipReader *ZipReader) *ZipEntryReader
type ZipReader ¶
func NewZipReaderForFile ¶ added in v0.4.0
type ZipURL ¶
func NewValidZipURL ¶
func (*ZipURL) Open ¶
func (self *ZipURL) Open(context contextpkg.Context) (io.ReadCloser, error)
(URL interface)
func (*ZipURL) OpenArchive ¶
func (self *ZipURL) OpenArchive(context contextpkg.Context) (*ZipReader, error)
func (*ZipURL) ValidRelative ¶ added in v0.4.0
(URL interface)