network

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const MAX_CONCURRENT_DOWNLOADS = 6

Variables

View Source
var ErrNotCached = errors.New("data not cached and request failed")

Functions

func CheckResponse

func CheckResponse(resp *http.Response) error

CheckResponse ensures the status code of an HTTP response is successful, returning an HTTPStatusError if not.

func DownloadFile

func DownloadFile(entry DownloadEntry) error

DownloadFile downloads the specified DownloadEntry and saves it.

All parent directories are created in order to create the file.

func StartDownloadEntries

func StartDownloadEntries(entries []DownloadEntry) chan error

StartDownloadEntries runs DownloadFile on each specified DownloadEntry and returns a channel with the download results.

Types

type Cache added in v1.1.0

type Cache[T any] struct {
	Path        string
	URL         string
	RemoteSha1  string
	AlwaysFetch bool
	Unmarshaler func(data []byte, v any) error // Custom unmarshal function. Defaults to JSON.
}

A Cache stores and retrieves remote data to unmarshal either into JSON or a custom unmarshaler.

func (Cache[T]) Get added in v1.5.0

func (cache Cache[T]) Get(v *T) error

Get checks the cache and checks if it is valid. If it is, its contents are returned. If not, they are fetched and then returned.

func (Cache[T]) Sha1 added in v1.2.0

func (cache Cache[T]) Sha1() (string, error)

Sha1 returns the SHA1 checksum of the cache

type DownloadEntry

type DownloadEntry struct {
	URL      string
	Path     string
	Sha1     string
	FileMode os.FileMode
}

type HTTPStatusError added in v1.1.0

type HTTPStatusError struct {
	URL        string
	Method     string
	StatusCode int
}

HTTPStatusError is an error type returned when an HTTP response finishes with a status code >= 300 or < 200

func (*HTTPStatusError) Error added in v1.1.0

func (e *HTTPStatusError) Error() string

Jump to

Keyboard shortcuts

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