network

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HttpClient = &http.Client{
	Timeout: 10 * time.Second,
}

Functions

func DownloadFile added in v0.11.0

func DownloadFile(ctx context.Context, dst, src, wd string) (string, error)

DownloadFile downloads a file to the requested dst (full file path) from src. wd is used when resolving relative paths and should be set to the common root directory of relative paths (defaults to the directory the input file is in). Go-getter supports the following protocols, though not all are relevant in file mode (and Lula can extend the Getter interface if we need to add to this list):

DownloadFile returns the actual download path and error. The error returned may be a go-multierror.

func Fetch

func Fetch(inputURL string, opts ...FetchOption) (bytes []byte, err error)

Fetch fetches the response body from a given URL after validating it. If the URL scheme is "file", the file is fetched from the local filesystem. If the URL scheme is "http", "https", or "ftp", the file is fetched from the remote server. If the URL has a checksum, the file is validated against the checksum.

func FetchLocalFile

func FetchLocalFile(url *url.URL, config *fetchOpts) ([]byte, error)

FetchLocalFile fetches a local file from a given URL. If the URL scheme is not "file", an error is returned. If the URL is relative, the component definition directory is prepended if set, otherwise the current working directory is prepended.

func GetLocalFileDir added in v0.9.0

func GetLocalFileDir(inputURL, baseDir string) string

func ParseChecksum

func ParseChecksum(src string) (*url.URL, string, error)

ParseChecksum parses a URL string into a url.URL object. If the URL has a checksum, the checksum is removed from the URL and returned.

func ValidateChecksum

func ValidateChecksum(data []byte, expectedChecksum string) error

ValidateChecksum validates a given checksum against a given []bytes. Supports MD5, SHA-1, SHA-256, and SHA-512. Returns an error if the hash does not match.

Types

type FetchOption added in v0.9.0

type FetchOption func(*fetchOpts) error

func WithBaseDir added in v0.9.0

func WithBaseDir(baseDir string) FetchOption

Jump to

Keyboard shortcuts

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