download

package
v0.0.0-...-083f60e Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: GPL-3.0 Imports: 28 Imported by: 0

Documentation

Overview

Package download handles downloading and extracting sa-mp server versions. Packages are cached in ~/.samp to avoid unnecessary downloads.

Index

Constants

View Source
const (
	// ExtractZip is an extract function for .zip packages
	ExtractZip = "zip"
	// ExtractTgz is an extract function for .tar.gz packages
	ExtractTgz = "tgz"
)

Variables

This section is empty.

Functions

func FromCache

func FromCache(request CacheExtractRequest) (bool, error)

FromCache first checks if a file is cached, then extracts it if present.

func FromNet

func FromNet(ctx context.Context, location, cachePath string) (result string, err error)

func FromNetWithClient

func FromNetWithClient(ctx context.Context, client HTTPDoer, location, cachePath string) (result string, err error)

func GetPackageList

func GetPackageList(cacheDir string) (packages []pawnpackage.Package, err error)

GetPackageList gets a list of known packages from the sampctl package service, if the list does not exist locally, it is downloaded and cached for future use.

func GetPackageListContext

func GetPackageListContext(ctx context.Context, cacheDir string) (packages []pawnpackage.Package, err error)

func GetPackageListWithClient

func GetPackageListWithClient(cacheDir string, client HTTPDoer) (packages []pawnpackage.Package, err error)

func GetPackageListWithClientContext

func GetPackageListWithClientContext(ctx context.Context, cacheDir string, client HTTPDoer) (packages []pawnpackage.Package, err error)

func MigrateOldConfig

func MigrateOldConfig(cacheDir string) error

MigrateOldConfig migrates old config to the new path.

func ReleaseAssetByPattern

func ReleaseAssetByPattern(request ReleaseAssetRequest) (filename, tag string, err error)

ReleaseAssetByPattern downloads a resource file, which is a GitHub release asset

func ReleaseAssetByPatternWithAPI

func ReleaseAssetByPatternWithAPI(request ReleaseAssetAPIRequest) (filename, tag string, err error)

func Untar

func Untar(src, dst string, paths map[string]string) (files map[string]string, err error)

Untar takes a destination path and a reader; a tar reader loops over the tarfile creating the file structure at 'dst' along the way, and writing any files from https://medium.com/@skdomino/taring-untaring-files-in-go-6b07cf56bc07 nolint:gocyclo

func UntarWithIgnore

func UntarWithIgnore(src, dst string, paths map[string]string, ignorePatterns []string) (files map[string]string, err error)

UntarWithIgnore is like Untar but accepts ignore patterns for files that should not be overwritten

func Unzip

func Unzip(src, dst string, paths map[string]string) (files map[string]string, err error)

Unzip will un-compress a zip archive, moving all files and folders to an output directory. from: https://golangcode.com/unzip-files-in-go/

func UnzipWithIgnore

func UnzipWithIgnore(src, dst string, paths map[string]string, ignorePatterns []string) (files map[string]string, err error)

UnzipWithIgnore is like Unzip but accepts ignore patterns for files that should not be overwritten

func UpdateCompilerList

func UpdateCompilerList(cacheDir string) (err error)

UpdateCompilerList downloads a list of all runtime packages to a file in the cache directory

func UpdateCompilerListContext

func UpdateCompilerListContext(ctx context.Context, cacheDir string) (err error)

func UpdateCompilerListWithClientContext

func UpdateCompilerListWithClientContext(ctx context.Context, cacheDir string, client HTTPDoer) (err error)

func UpdatePackageList

func UpdatePackageList(cacheDir string) (err error)

UpdatePackageList downloads a list of all packages to a file in the cache directory

func UpdatePackageListContext

func UpdatePackageListContext(ctx context.Context, cacheDir string) (err error)

func UpdatePackageListWithClient

func UpdatePackageListWithClient(cacheDir string, client HTTPDoer) (err error)

func UpdatePackageListWithClientContext

func UpdatePackageListWithClientContext(ctx context.Context, cacheDir string, client HTTPDoer) (err error)

func UpdateRuntimeList

func UpdateRuntimeList(cacheDir string) (err error)

UpdateRuntimeList downloads a list of all runtime packages to a file in the cache directory

func UpdateRuntimeListContext

func UpdateRuntimeListContext(ctx context.Context, cacheDir string) (err error)

func UpdateRuntimeListWithClientContext

func UpdateRuntimeListWithClientContext(ctx context.Context, cacheDir string, client HTTPDoer) (err error)

func WriteCompilerCacheFile

func WriteCompilerCacheFile(cacheDir string, data []byte) error

func WritePackageCacheFile

func WritePackageCacheFile(cacheDir string, data []byte) error

func WriteRuntimeCacheFile

func WriteRuntimeCacheFile(cacheDir string, data []byte) error

Types

type CacheExtractRequest

type CacheExtractRequest struct {
	CacheDir string
	Filename string
	Dir      string
	Method   ExtractFunc
	Paths    map[string]string
	Platform string
}

CacheExtractRequest describes a cached archive extraction operation.

type Compiler

type Compiler struct {
	Match  string            `json:"match"`  // the release asset name pattern
	Method string            `json:"method"` // the extraction method
	Binary string            `json:"binary"` // execution binary
	Paths  map[string]string `json:"paths"`  // map of files to their target locations
}

Compiler represents a compiler package for a specific OS

type Compilers

type Compilers map[string]Compiler

Compilers is a list of compilers for each platform

func GetCompilerList

func GetCompilerList(cacheDir string) (compilers Compilers, err error)

GetCompilerList gets a list of known compiler packages from the sampctl repo, if the list does not exist locally, it is downloaded and cached for future use.

func GetCompilerListContext

func GetCompilerListContext(ctx context.Context, cacheDir string) (compilers Compilers, err error)

func GetCompilerListWithClientContext

func GetCompilerListWithClientContext(ctx context.Context, cacheDir string, client HTTPDoer) (compilers Compilers, err error)

type ExtractFunc

type ExtractFunc func(string, string, map[string]string) (map[string]string, error)

ExtractFunc represents a function responsible for extracting a set of files from an archive to a directory. The map argument contains a map of source files in the archive to target file locations on the host filesystem (absolute paths).

func ExtractFuncFromName

func ExtractFuncFromName(name string) ExtractFunc

ExtractFuncFromName returns an extract function for a given name

type GitHubReleasesAPI

type GitHubReleasesAPI interface {
	ListReleases(ctx context.Context, owner, repo string, opt *github.ListOptions) ([]*github.RepositoryRelease, *github.Response, error)
	GetReleaseByTag(ctx context.Context, owner, repo, tag string) (*github.RepositoryRelease, *github.Response, error)
	DownloadReleaseAsset(ctx context.Context, owner, repo string, id int64) (io.ReadCloser, string, error)
}

GitHubReleasesAPI wrap the go-github api for release lookups

type HTTPDoer

type HTTPDoer interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPDoer lets us test HTTP clients

type ReleaseAssetAPIRequest

type ReleaseAssetAPIRequest struct {
	Context    context.Context
	Client     GitHubReleasesAPI
	Meta       versioning.DependencyMeta
	Matcher    *regexp.Regexp
	Dir        string
	OutputFile string
	CacheDir   string
}

ReleaseAssetAPIRequest describes a GitHub release asset download using the narrow releases API.

type ReleaseAssetDownloadRequest

type ReleaseAssetDownloadRequest struct {
	Context     context.Context
	Client      GitHubReleasesAPI
	Meta        versioning.DependencyMeta
	Asset       *github.ReleaseAsset
	Destination string
}

ReleaseAssetDownloadRequest describes the final transfer of a selected release asset.

type ReleaseAssetRequest

type ReleaseAssetRequest struct {
	Context    context.Context
	Client     *github.Client
	Meta       versioning.DependencyMeta
	Matcher    *regexp.Regexp
	Dir        string
	OutputFile string
	CacheDir   string
}

ReleaseAssetRequest describes a GitHub release asset download using a github.Client.

type RuntimePackage

type RuntimePackage struct {
	Version       string            `json:"version"`
	Linux         string            `json:"linux"`
	Win32         string            `json:"win32"`
	LinuxChecksum string            `json:"linux_checksum"`
	Win32Checksum string            `json:"win32_checksum"`
	LinuxPaths    map[string]string `json:"linux_paths"`
	Win32Paths    map[string]string `json:"win32_paths"`
}

RuntimePackage represents a SA:MP server version, it stores both platform filenames and a checksum

type Runtimes

type Runtimes struct {
	Aliases  map[string]string `json:"aliases"`
	Packages []RuntimePackage  `json:"packages"`
}

Runtimes is a collection of Package objects for sorting

func GetRuntimeList

func GetRuntimeList(cacheDir string) (runtimes Runtimes, err error)

GetRuntimeList gets a list of known runtime packages from the sampctl repo, if the list does not exist locally, it is downloaded and cached for future use.

func GetRuntimeListContext

func GetRuntimeListContext(ctx context.Context, cacheDir string) (runtimes Runtimes, err error)

func GetRuntimeListWithClientContext

func GetRuntimeListWithClientContext(ctx context.Context, cacheDir string, client HTTPDoer) (runtimes Runtimes, err error)

Jump to

Keyboard shortcuts

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