url

package
v0.37.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 14 Imported by: 56

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AES256Key added in v0.31.3

type AES256Key struct {
	Key                 []byte
	Base64Key           string
	Base64KeyMd5Hash    string
	Base64KeySha256Hash string
}

AES256Key represents custom key

type Resource

type Resource struct {
	URL           string     `description:"resource URL or relative or absolute path" required:"true"` //URL of resource
	Credentials   string     `description:"credentials file"`                                          //name of credential file or credential key depending on implementation
	ParsedURL     *url.URL   `json:"-"`                                                                //parsed URL resource
	Cache         string     `description:"local cache path"`                                          //Cache path for the resource, if specified resource will be cached in the specified path
	CustomKey     *AES256Key `description:" content encryption key"`
	CacheExpiryMs int        //CacheExpiryMs expiry time in ms
	// contains filtered or unexported fields
}

Resource represents a URL based resource, with enriched meta info

func NewResource

func NewResource(Params ...interface{}) *Resource

NewResource returns a new resource for provided URL, followed by optional credential, cache and cache expiryMs.

func (*Resource) Cachable

func (r *Resource) Cachable() bool

Cachable returns true if resource is cachable

func (*Resource) Clone

func (r *Resource) Clone() *Resource

Clone creates a clone of the resource

func (*Resource) CredentialURL

func (r *Resource) CredentialURL(username, password string) string

CredentialURL returns url's with provided credential

func (*Resource) Decode

func (r *Resource) Decode(target interface{}) (err error)

Decode decodes url's data into target, it support JSON and YAML exp.

func (*Resource) DecodeWith

func (r *Resource) DecodeWith(target interface{}, decoderFactory toolbox.DecoderFactory) error

Decode decodes url's data into target, it takes decoderFactory which decodes data into target

func (*Resource) DecoderFactory added in v0.5.4

func (r *Resource) DecoderFactory() toolbox.DecoderFactory

DecoderFactory returns new decoder factory for resource

func (*Resource) DirectoryPath

func (r *Resource) DirectoryPath() string

Path returns url's path directory, assumption is that directory does not have extension, if path ends with '/' it is being stripped.

func (*Resource) Download

func (r *Resource) Download() ([]byte, error)

Download downloads data from URL, it returns data as []byte, or error, if resource is cacheable it first look into cache

func (*Resource) DownloadBase64 added in v0.26.0

func (r *Resource) DownloadBase64() (string, error)

DownloadBase64 loads base64 resource content

func (*Resource) DownloadText

func (r *Resource) DownloadText() (string, error)

DownloadText returns a text downloaded from url

func (*Resource) HasChanged

func (r *Resource) HasChanged() (changed bool, err error)

func (*Resource) Host

func (r *Resource) Host() string

Host returns url's host name with user name if user name is part of url

func (*Resource) Init

func (r *Resource) Init() (err error)

func (*Resource) JSONDecode

func (r *Resource) JSONDecode(target interface{}) error

JSONDecode decodes json resource into target

func (*Resource) Port

func (r *Resource) Port() string

Port returns url's port

func (*Resource) Rename

func (r *Resource) Rename(name string) (err error)

Rename renames URI name of this resource

func (*Resource) YAMLDecode

func (r *Resource) YAMLDecode(target interface{}) error

JSONDecode decodes yaml resource into target

Jump to

Keyboard shortcuts

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