url

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2023 License: Apache-2.0 Imports: 28 Imported by: 0

README

URLs

Usage example:

import (
    urlpkg "github.com/tliron/kutil/url"
)

func ReadAll(url string, format string) ([]byte, error) {
    context := urlpkg.NewContext()
    defer context.Release()

    if url_, err = urlpkg.NewURL(url, context); err == nil {
        if reader, err := url_.Open(); err == nil {
            defer reader.Close()
            return io.ReadAll(reader)
        } else {
            return nil, err
        }
    } else {
        return nil, err
    }
}

file:

http: and https:

zip:

git:

docker:

internal:

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TARBALL_ARCHIVE_FORMATS = []string{"tar", "tar.gz"}

Functions

func DeleteTemporaryDir added in v0.1.46

func DeleteTemporaryDir(path string) error

func DeleteTemporaryFile

func DeleteTemporaryFile(path string) error

func DeregisterInternalURL added in v0.1.15

func DeregisterInternalURL(path string)

func Download

func Download(url URL, temporaryPathPattern string) (*os.File, error)

func DownloadTo

func DownloadTo(url URL, path string) error

func GetFormat

func GetFormat(path string) string

func GetPath added in v0.1.61

func GetPath(url URL) (string, error)

func IsNotFound added in v0.1.66

func IsNotFound(err error) bool

func IsValidTarballArchiveFormat added in v0.1.66

func IsValidTarballArchiveFormat(archiveFormat string) bool

func ReadARD

func ReadARD(url URL, locate bool) (ard.Value, ard.Locator, error)

func ReadBytes added in v0.1.38

func ReadBytes(url URL) ([]byte, error)

func ReadString

func ReadString(url URL) (string, error)

func RegisterInternalURL

func RegisterInternalURL(path string, content any) error

`content` must be []byte or string

func Size

func Size(url URL) (int64, error)

func ToNetURL added in v0.1.61

func ToNetURL(url URL) (*neturl.URL, error)

func UpdateInternalURL added in v0.1.15

func UpdateInternalURL(path string, content any)

Types

type ContainerImageLayerDecoder

type ContainerImageLayerDecoder struct {
	// contains filtered or unexported fields
}

func NewContainerImageLayerDecoder

func NewContainerImageLayerDecoder(reader io.Reader) *ContainerImageLayerDecoder

func (*ContainerImageLayerDecoder) Decode

func (self *ContainerImageLayerDecoder) Decode() io.Reader

func (*ContainerImageLayerDecoder) Drain

func (self *ContainerImageLayerDecoder) Drain()

type Context

type Context struct {
	// contains filtered or unexported fields
}

func NewContext

func NewContext() *Context

func (*Context) GetCredentials added in v0.1.6

func (self *Context) GetCredentials(host string) *Credentials

Not thread-safe

func (*Context) GetHTTPRoundTripper added in v0.1.4

func (self *Context) GetHTTPRoundTripper(host string) http.RoundTripper

Not thread-safe

func (*Context) GetLocalPath added in v0.1.61

func (self *Context) GetLocalPath(url URL) (string, error)

Will download the file to the local temporary directory if not already locally available

func (*Context) GetMapping added in v0.1.65

func (self *Context) GetMapping(fromUrl string) (string, bool)

func (*Context) Map added in v0.1.65

func (self *Context) Map(fromUrl string, toUrl string)

Set mapping to empty string to delete it

func (*Context) OpenFile added in v0.1.61

func (self *Context) OpenFile(url URL) (*os.File, error)

func (*Context) Release

func (self *Context) Release() error

func (*Context) SetCredentials added in v0.1.6

func (self *Context) SetCredentials(host string, username string, password string, token string)

Not thread-safe

func (*Context) SetHTTPRoundTripper added in v0.1.4

func (self *Context) SetHTTPRoundTripper(host string, httpRoundTripper http.RoundTripper)

Not thread-safe

type Credentials added in v0.1.6

type Credentials struct {
	Username string
	Password string
	Token    string
}

type DockerURL

type DockerURL struct {
	URL *neturlpkg.URL
	// contains filtered or unexported fields
}

func NewDockerURL

func NewDockerURL(neturl *neturlpkg.URL, context *Context) *DockerURL

func NewValidDockerURL

func NewValidDockerURL(neturl *neturlpkg.URL, context *Context) (*DockerURL, error)

func (*DockerURL) Context

func (self *DockerURL) Context() *Context

URL interface

func (*DockerURL) Format

func (self *DockerURL) Format() string

URL interface

func (*DockerURL) Key

func (self *DockerURL) Key() string

URL interface

func (*DockerURL) Open

func (self *DockerURL) Open() (io.ReadCloser, error)

URL interface

func (*DockerURL) Origin

func (self *DockerURL) Origin() URL

URL interface

func (*DockerURL) Relative

func (self *DockerURL) Relative(path string) URL

URL interface

func (*DockerURL) RemoteOptions added in v0.1.6

func (self *DockerURL) RemoteOptions() []remote.Option

func (*DockerURL) String

func (self *DockerURL) String() string

URL interface fmt.Stringer interface

func (*DockerURL) WriteLayer

func (self *DockerURL) WriteLayer(writer io.Writer) error

func (*DockerURL) WriteTarball

func (self *DockerURL) WriteTarball(writer io.Writer) error

type FileFileProvider added in v0.1.61

type FileFileProvider struct {
	// contains filtered or unexported fields
}

func NewFileFileProvider added in v0.1.61

func NewFileFileProvider(localPath string, providedPath string) *FileFileProvider

func (*FileFileProvider) Close added in v0.1.61

func (self *FileFileProvider) Close() error

FileReader interface

func (*FileFileProvider) Open added in v0.1.61

func (self *FileFileProvider) Open() (string, bool, io.Reader, error)

FileReader interface

type FileProvider added in v0.1.61

type FileProvider interface {
	Open() (string, bool, io.Reader, error)
	Close() error
}

type FileProviders added in v0.1.61

type FileProviders interface {
	Next() (FileProvider, error)
	Close() error
}

func NewDirFileProviders added in v0.1.61

func NewDirFileProviders(path string) (FileProviders, error)

func NewFileProviders added in v0.1.61

func NewFileProviders(url URL, unpack string) (FileProviders, error)

`unpack` can be "tgz" or "zip"

type FileURL

type FileURL struct {
	Path string
	// contains filtered or unexported fields
}

func NewFileURL

func NewFileURL(path string, context *Context) *FileURL

func NewValidFileURL

func NewValidFileURL(path string, context *Context) (*FileURL, error)

func NewValidRelativeFileURL

func NewValidRelativeFileURL(path string, origin *FileURL) (*FileURL, error)

func (*FileURL) Context

func (self *FileURL) Context() *Context

URL interface

func (*FileURL) Format

func (self *FileURL) Format() string

URL interface

func (*FileURL) Key

func (self *FileURL) Key() string

URL interface

func (*FileURL) Open

func (self *FileURL) Open() (io.ReadCloser, error)

URL interface

func (*FileURL) Origin

func (self *FileURL) Origin() URL

URL interface

func (*FileURL) Relative

func (self *FileURL) Relative(path string) URL

URL interface

func (*FileURL) String

func (self *FileURL) String() string

URL interface fmt.Stringer interface

type GitURL added in v0.1.46

type GitURL struct {
	Path          string
	RepositoryURL string
	Reference     string
	Username      string
	Password      string
	// contains filtered or unexported fields
}

func NewGitURL added in v0.1.46

func NewGitURL(path string, repositoryUrl string, context *Context) *GitURL

func NewValidGitURL added in v0.1.46

func NewValidGitURL(path string, repositoryUrl string, context *Context) (*GitURL, error)

func NewValidRelativeGitURL added in v0.1.46

func NewValidRelativeGitURL(path string, origin *GitURL) (*GitURL, error)

func ParseGitURL added in v0.1.46

func ParseGitURL(url string, context *Context) (*GitURL, error)

func ParseValidGitURL added in v0.1.46

func ParseValidGitURL(url string, context *Context) (*GitURL, error)

func (*GitURL) Context added in v0.1.46

func (self *GitURL) Context() *Context

URL interface

func (*GitURL) Format added in v0.1.46

func (self *GitURL) Format() string

URL interface

func (*GitURL) Key added in v0.1.46

func (self *GitURL) Key() string

URL interface

func (*GitURL) Open added in v0.1.46

func (self *GitURL) Open() (io.ReadCloser, error)

URL interface

func (*GitURL) OpenRepository added in v0.1.46

func (self *GitURL) OpenRepository() (*git.Repository, error)

func (*GitURL) Origin added in v0.1.46

func (self *GitURL) Origin() URL

URL interface

func (*GitURL) Relative added in v0.1.46

func (self *GitURL) Relative(path string) URL

URL interface

func (*GitURL) String added in v0.1.46

func (self *GitURL) String() string

URL interface fmt.Stringer interface

type InternalURL

type InternalURL struct {
	Path    string
	Content []byte
	// contains filtered or unexported fields
}

func NewInternalURL

func NewInternalURL(path string, context *Context) *InternalURL

func NewValidInternalURL

func NewValidInternalURL(path string, context *Context) (*InternalURL, error)

func NewValidRelativeInternalURL

func NewValidRelativeInternalURL(path string, origin *InternalURL) (*InternalURL, error)

func ReadToInternalURL

func ReadToInternalURL(path string, reader io.Reader, context *Context) (*InternalURL, error)

func ReadToInternalURLFromStdin

func ReadToInternalURLFromStdin(format string, context *Context) (*InternalURL, error)

func (*InternalURL) Context

func (self *InternalURL) Context() *Context

URL interface

func (*InternalURL) Format

func (self *InternalURL) Format() string

URL interface

func (*InternalURL) Key

func (self *InternalURL) Key() string

URL interface

func (*InternalURL) Open

func (self *InternalURL) Open() (io.ReadCloser, error)

URL interface

func (*InternalURL) Origin

func (self *InternalURL) Origin() URL

URL interface

func (*InternalURL) Relative

func (self *InternalURL) Relative(path string) URL

URL interface

func (*InternalURL) SetContent added in v0.1.61

func (self *InternalURL) SetContent(content any)

func (*InternalURL) String

func (self *InternalURL) String() string

URL interface fmt.Stringer interface

type NetworkURL

type NetworkURL struct {
	URL *neturlpkg.URL
	// contains filtered or unexported fields
}

func NewNetworkURL

func NewNetworkURL(neturl *neturlpkg.URL, context *Context) *NetworkURL

func NewValidNetworkURL

func NewValidNetworkURL(neturl *neturlpkg.URL, context *Context) (*NetworkURL, error)

func NewValidRelativeNetworkURL

func NewValidRelativeNetworkURL(path string, origin *NetworkURL) (*NetworkURL, error)

func (*NetworkURL) Context

func (self *NetworkURL) Context() *Context

URL interface

func (*NetworkURL) Format

func (self *NetworkURL) Format() string

URL interface

func (*NetworkURL) Key

func (self *NetworkURL) Key() string

URL interface

func (*NetworkURL) Open

func (self *NetworkURL) Open() (io.ReadCloser, error)

URL interface

func (*NetworkURL) Origin

func (self *NetworkURL) Origin() URL

URL interface

func (*NetworkURL) Relative

func (self *NetworkURL) Relative(path string) URL

URL interface

func (*NetworkURL) String

func (self *NetworkURL) String() string

URL interface fmt.Stringer interface

type NotFound added in v0.1.66

type NotFound struct {
	Message string
}

func NewNotFound added in v0.1.66

func NewNotFound(message string) *NotFound

func NewNotFoundf added in v0.1.66

func NewNotFoundf(format string, arg ...any) *NotFound

func (*NotFound) Error added in v0.1.66

func (self *NotFound) Error() string

error interface

type StaticFileProviders added in v0.1.61

type StaticFileProviders struct {
	// contains filtered or unexported fields
}

func NewStaticFileProviders added in v0.1.61

func NewStaticFileProviders(sources ...FileProvider) *StaticFileProviders

func (*StaticFileProviders) Close added in v0.1.61

func (self *StaticFileProviders) Close() error

FileProviders interface

func (*StaticFileProviders) Next added in v0.1.61

func (self *StaticFileProviders) Next() (FileProvider, error)

FileProviders interface

type TarFileProvider added in v0.1.61

type TarFileProvider struct {
	// contains filtered or unexported fields
}

func NewTarFileReader added in v0.1.61

func NewTarFileReader(header *tar.Header, tarReader *tar.Reader) *TarFileProvider

func (*TarFileProvider) Close added in v0.1.61

func (self *TarFileProvider) Close() error

FileReader interface

func (*TarFileProvider) Open added in v0.1.61

func (self *TarFileProvider) Open() (string, bool, io.Reader, error)

FileReader interface

type TarFileProviders added in v0.1.61

type TarFileProviders struct {
	// contains filtered or unexported fields
}

func NewTarFileProviders added in v0.1.61

func NewTarFileProviders(url URL) (*TarFileProviders, error)

func (*TarFileProviders) Close added in v0.1.61

func (self *TarFileProviders) Close() error

FileProviders interface

func (*TarFileProviders) Next added in v0.1.61

func (self *TarFileProviders) Next() (FileProvider, error)

FileProviders interface

type TarGZipFileProviders added in v0.1.61

type TarGZipFileProviders struct {
	// contains filtered or unexported fields
}

func NewTarGZipFileProviders added in v0.1.61

func NewTarGZipFileProviders(url URL) (*TarGZipFileProviders, error)

func (*TarGZipFileProviders) Close added in v0.1.61

func (self *TarGZipFileProviders) Close() error

FileProviders interface

func (*TarGZipFileProviders) Next added in v0.1.61

func (self *TarGZipFileProviders) Next() (FileProvider, error)

FileProviders interface

type TarballEntryReader added in v0.1.66

type TarballEntryReader struct {
	TarballReader *TarballReader
}

func NewTarballEntryReader added in v0.1.66

func NewTarballEntryReader(tarballReader *TarballReader) *TarballEntryReader

func (*TarballEntryReader) Close added in v0.1.66

func (self *TarballEntryReader) Close() error

io.Closer interface

func (*TarballEntryReader) Read added in v0.1.66

func (self *TarballEntryReader) Read(p []byte) (n int, err error)

io.Reader interface

type TarballReader added in v0.1.66

type TarballReader struct {
	TarReader         *tar.Reader
	ArchiveReader     io.ReadCloser
	CompressionReader io.ReadCloser
}

func NewTarballReader added in v0.1.66

func NewTarballReader(reader *tar.Reader, archiveReader io.ReadCloser, compressionReader io.ReadCloser) *TarballReader

func OpenTarballFromFile added in v0.1.66

func OpenTarballFromFile(file *os.File) (*TarballReader, error)

func (*TarballReader) Close added in v0.1.66

func (self *TarballReader) Close() error

io.Closer interface

func (*TarballReader) Has added in v0.1.66

func (self *TarballReader) Has(path string) (bool, error)

func (*TarballReader) Iterate added in v0.1.66

func (self *TarballReader) Iterate(f func(*tar.Header) bool) error

func (*TarballReader) Open added in v0.1.66

func (self *TarballReader) Open(path string) (*TarballEntryReader, error)

type TarballURL added in v0.1.66

type TarballURL struct {
	Path          string
	ArchiveURL    URL
	ArchiveFormat string
}

func NewTarballURL added in v0.1.66

func NewTarballURL(path string, archiveUrl URL, archiveFormat string) *TarballURL

func NewValidRelativeTarballURL added in v0.1.66

func NewValidRelativeTarballURL(path string, origin *TarballURL) (*TarballURL, error)

func NewValidTarballURL added in v0.1.66

func NewValidTarballURL(path string, archiveUrl URL, archiveFormat string) (*TarballURL, error)

func ParseTarballURL added in v0.1.66

func ParseTarballURL(url string, context *Context) (*TarballURL, error)

func ParseValidTarballURL added in v0.1.66

func ParseValidTarballURL(url string, context *Context) (*TarballURL, error)

func (*TarballURL) Context added in v0.1.66

func (self *TarballURL) Context() *Context

URL interface

func (*TarballURL) Format added in v0.1.66

func (self *TarballURL) Format() string

URL interface

func (*TarballURL) Key added in v0.1.66

func (self *TarballURL) Key() string

URL interface

func (*TarballURL) Open added in v0.1.66

func (self *TarballURL) Open() (io.ReadCloser, error)

URL interface

func (*TarballURL) OpenArchive added in v0.1.66

func (self *TarballURL) OpenArchive() (*TarballReader, error)

func (*TarballURL) Origin added in v0.1.66

func (self *TarballURL) Origin() URL

URL interface

func (*TarballURL) Relative added in v0.1.66

func (self *TarballURL) Relative(path string) URL

URL interface

func (*TarballURL) String added in v0.1.66

func (self *TarballURL) String() string

URL interface fmt.Stringer interface

type URL

type URL interface {
	String() string
	Format() string // yaml|json|xml
	Origin() URL    // base dir, is not necessarily a valid URL
	Relative(path string) URL
	Key() string // for maps
	Open() (io.ReadCloser, error)
	Context() *Context
}

func NewURL

func NewURL(url string, context *Context) (URL, error)

func NewValidURL

func NewValidURL(url string, origins []URL, context *Context) (URL, error)

type URLFileProvider added in v0.1.61

type URLFileProvider struct {
	// contains filtered or unexported fields
}

func NewURLFileProvider added in v0.1.61

func NewURLFileProvider(url URL) *URLFileProvider

func (*URLFileProvider) Close added in v0.1.61

func (self *URLFileProvider) Close() error

FileReader interface

func (*URLFileProvider) Open added in v0.1.61

func (self *URLFileProvider) Open() (string, bool, io.Reader, error)

FileReader interface

type ZipEntryReader

type ZipEntryReader struct {
	EntryReader io.ReadCloser
	ZipReader   *ZipReader
}

func NewZipEntryReader

func NewZipEntryReader(entryReader io.ReadCloser, zipReader *ZipReader) *ZipEntryReader

func (*ZipEntryReader) Close

func (self *ZipEntryReader) Close() error

io.Closer interface

func (*ZipEntryReader) Read

func (self *ZipEntryReader) Read(p []byte) (n int, err error)

io.Reader interface

type ZipFileProvider added in v0.1.61

type ZipFileProvider struct {
	// contains filtered or unexported fields
}

func NewZipFileProvider added in v0.1.61

func NewZipFileProvider(file *zip.File) *ZipFileProvider

func (*ZipFileProvider) Close added in v0.1.61

func (self *ZipFileProvider) Close() error

FileReader interface

func (*ZipFileProvider) Open added in v0.1.61

func (self *ZipFileProvider) Open() (string, bool, io.Reader, error)

FileReader interface

type ZipFileProviders added in v0.1.61

type ZipFileProviders struct {
	// contains filtered or unexported fields
}

func NewZipFileProviders added in v0.1.61

func NewZipFileProviders(path string) (*ZipFileProviders, error)

func (*ZipFileProviders) Close added in v0.1.61

func (self *ZipFileProviders) Close() error

FileProviders interface

func (*ZipFileProviders) Next added in v0.1.61

func (self *ZipFileProviders) Next() (FileProvider, error)

FileProviders interface

type ZipReader

type ZipReader struct {
	ZipReader *zip.Reader
	File      *os.File
}

func NewZipReader

func NewZipReader(reader *zip.Reader, file *os.File) *ZipReader

func OpenZipFromFile

func OpenZipFromFile(file *os.File) (*ZipReader, error)

func (*ZipReader) Close

func (self *ZipReader) Close() error

io.Closer interface

func (*ZipReader) Has added in v0.1.66

func (self *ZipReader) Has(path string) bool

func (*ZipReader) Iterate added in v0.1.66

func (self *ZipReader) Iterate(f func(*zip.File) bool)

func (*ZipReader) Open added in v0.1.66

func (self *ZipReader) Open(path string) (*ZipEntryReader, error)

type ZipURL

type ZipURL struct {
	Path       string
	ArchiveURL URL
}

func NewValidRelativeZipURL

func NewValidRelativeZipURL(path string, origin *ZipURL) (*ZipURL, error)

func NewValidZipURL

func NewValidZipURL(path string, archiveUrl URL) (*ZipURL, error)

func NewZipURL

func NewZipURL(path string, archiveUrl URL) *ZipURL

func ParseValidZipURL

func ParseValidZipURL(url string, context *Context) (*ZipURL, error)

func ParseZipURL

func ParseZipURL(url string, context *Context) (*ZipURL, error)

func (*ZipURL) Context

func (self *ZipURL) Context() *Context

URL interface

func (*ZipURL) Format

func (self *ZipURL) Format() string

URL interface

func (*ZipURL) Key

func (self *ZipURL) Key() string

URL interface

func (*ZipURL) Open

func (self *ZipURL) Open() (io.ReadCloser, error)

URL interface

func (*ZipURL) OpenArchive

func (self *ZipURL) OpenArchive() (*ZipReader, error)

func (*ZipURL) Origin

func (self *ZipURL) Origin() URL

URL interface

func (*ZipURL) Relative

func (self *ZipURL) Relative(path string) URL

URL interface

func (*ZipURL) String

func (self *ZipURL) String() string

URL interface fmt.Stringer interface

Jump to

Keyboard shortcuts

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