Documentation
¶
Index ¶
- func Download(ctx context.Context, url, path string, onProgress func(current, total int64)) error
- func ExtractJSONKeys(r io.Reader) ([]string, error)
- func FetchJSON[T any](ctx context.Context, url string, value *T) error
- func MergeZips(ctx context.Context, baseZipPath, overlayZipPath, outputZipPath string) (err error)
- type ProgressReader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Download ¶
Download downloads a file from a given URL to a specified path with context support. If the download fails, any partially created file at the destination path will be removed.
func ExtractJSONKeys ¶
ExtractJSONKeys extracts the top-level keys from a JSON object provided by an io.Reader.
It expects the input to be a valid JSON object (i.e., starting with '{'). The function iterates through all key-value pairs at the top level, collects the keys in the order they appear in the JSON string, and skips the values.
Parameters:
- r: an io.Reader containing the JSON object.
Returns:
- []string: a slice of strings containing the keys found at the top level of the JSON object, in the same order as in the input JSON.
- error: an error if the input is not a valid JSON object or if any decoding issues occur.
func FetchJSON ¶
FetchJSON fetches JSON data from the given URL and decodes it into the provided variable with context support.
Parameters:
- ctx: the context to control the request lifetime.
- url: the URL to fetch the JSON from.
- value: a pointer to the variable where the decoded JSON will be stored.
Returns:
- error: an error if the HTTP request fails or the JSON cannot be decoded.
Types ¶
Click to show internal directories.
Click to hide internal directories.