Documentation
¶
Index ¶
- Variables
- 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 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