fetch

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const GB = 1024 * 1024 * 1024

Variables

View Source
var MaxFileSize = 2 * GB

MaxFileSize is the maximum allowed size for extracted files (default 2GB). This is a safety limit to prevent zip bombs or accidental extraction of huge files.

Functions

func BinaryRelease added in v0.1.0

func BinaryRelease(toolPath string, spec ReleaseSpec) error

BinaryRelease downloads a binary archive from the URL defined in spec, extracts the file matching toolPath's basename, and writes it to toolPath with executable permissions (0500). Supports .zip and .tar.gz archives.

func Delete added in v0.1.0

func Delete(urlString string, options ...Option) (err error)

Delete performs an HTTP DELETE request to the specified URL. Returns an error if the response status code is >= 300.

func Fetch

func Fetch(urlString string, options ...Option) (contents string, err error)

Fetch performs an HTTP GET request to the specified URL and returns the response body as a string. Use the Writer() option to redirect output to a writer instead. Returns an error if the response status code is >= 300.

Types

type Option

type Option func(*fetchOptions) error

Option is a functional option for customizing HTTP fetch behavior.

func Headers

func Headers(headers map[string]string) Option

Headers adds custom HTTP headers to the request. Can be called multiple times to accumulate headers.

func Writer

func Writer(writer io.Writer) Option

Writer redirects the response body to the provided writer instead of returning it as a string. Useful for downloading large files directly to disk.

type ReleaseSpec added in v0.1.0

type ReleaseSpec struct {
	// URL is the URL template for downloading. Built-in variables include:
	//   - {{os}}: runtime.GOOS (e.g., "linux", "darwin", "windows")
	//   - {{arch}}: runtime.GOARCH (e.g., "amd64", "arm64")
	// Additional variables can be defined in Args and Platform.
	URL string

	// Args provides default template values for all platforms.
	Args map[string]string

	// Platform provides platform-specific overrides for Args. Keys can be:
	//   - OS only: "linux", "darwin", "windows"
	//   - Arch only with wildcard: "*/arm64", "*/amd64"
	//   - OS/Arch pair: "darwin/arm64", "linux/amd64"
	// More specific keys take precedence over less specific ones.
	Platform map[string]map[string]string
}

ReleaseSpec defines how to download and extract a binary release from a URL. The URL is a Go template that can reference variables from Args, Platform, and the built-in {{os}} and {{arch}} values.

Jump to

Keyboard shortcuts

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