network

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const MAX_CONCURRENT_DOWNLOADS = 6

Variables

This section is empty.

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 struct {
	Path string
	URL  string
}

func (Cache) FetchAndRead added in v1.1.0

func (cache Cache) FetchAndRead(v *[]byte) error

FetchAndRead updates the cache with data from cache.URL, if set, and reads the contents of the cache into v.

func (Cache) Read added in v1.1.0

func (cache Cache) Read(v *[]byte) error

Read reads the contents of the cache into v.

type DownloadEntry

type DownloadEntry struct {
	URL  string
	Path string
	Sha1 string
}

type HTTPStatusError added in v1.1.0

type HTTPStatusError struct {
	URL        string
	Method     string
	StatusCode int
}

func (*HTTPStatusError) Error added in v1.1.0

func (e *HTTPStatusError) Error() string

type JSONCache

type JSONCache[T any] struct {
	Path       string
	URL        string
	RemoteSha1 string
}

func (JSONCache[T]) FetchAndRead added in v1.1.0

func (cache JSONCache[T]) FetchAndRead(v *T) error

FetchAndRead updates the cache with data from cache.URL, if set, and reads the contents of the cache into v.

func (JSONCache[T]) Read

func (cache JSONCache[T]) Read(v *T) error

Read reads the contents of the cache into v.

func (JSONCache[T]) Sha1

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

Sha1 returns the SHA1 checksum of the cache

Jump to

Keyboard shortcuts

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