Documentation ¶
Index ¶
- Variables
- func DownloadFile(ctx context.Context, dst, src, wd string) (string, error)
- func Fetch(inputURL string, opts ...FetchOption) (bytes []byte, err error)
- func FetchLocalFile(url *url.URL, config *fetchOpts) ([]byte, error)
- func GetLocalFileDir(inputURL, baseDir string) string
- func ParseChecksum(src string) (*url.URL, string, error)
- func ValidateChecksum(data []byte, expectedChecksum string) error
- type FetchOption
Constants ¶
This section is empty.
Variables ¶
var HttpClient = &http.Client{ Timeout: 10 * time.Second, }
Functions ¶
func DownloadFile ¶ added in v0.11.0
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):
- Local files
- Git
- Mercurial
- HTTP
- Amazon S3
- Google GCP
- SMB
- Source: https://pkg.go.dev/github.com/hashicorp/go-getter/v2#section-readme
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 ¶
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 ParseChecksum ¶
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 ¶
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