network

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 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.

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 FetchJSON

func FetchJSON(url string, v any) error

FetchJSON fetches url and unmarshals its JSON contents into v

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 DownloadEntry

type DownloadEntry struct {
	URL      string
	Filename string
}

type JSONCache

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

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

func (JSONCache[T]) UpdateAndRead

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

UpdateAndRead updates the cache with data from cache.URL and reads the contents of the cache into v.

Jump to

Keyboard shortcuts

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