url

package
v0.1.46 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2021 License: Apache-2.0 Imports: 22 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

This section is empty.

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 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 string) error

func Size

func Size(url URL) (int64, error)

func UpdateInternalURL added in v0.1.15

func UpdateInternalURL(path string, content string)

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) Open

func (self *Context) Open(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 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
	// 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 string
	// 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) (*InternalURL, error)

func ReadToInternalURLFromStdin

func ReadToInternalURLFromStdin(format string) (*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) 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 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 ZipEntryReader

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

func NewZipEntryReader

func NewZipEntryReader(entryReader io.ReadCloser, archiveReader *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 ZipReader

type ZipReader struct {
	Reader *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

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