url

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2018 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Resource

type Resource struct {
	URL           string   `description:"resource URL or relative or absolute path" required:"true"` //URL of resource
	Credential    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
	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{}, decoderFactory toolbox.DecoderFactory) error

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

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

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

JSONDecode decodes json resource into target

func (*Resource) LoadCredential

func (r *Resource) LoadCredential(errorIfEmpty bool) (string, string, error)

LoadCredentialload credential, returns username, password. It takes errorIfEmpty flag to return an error if there is issue with credential

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