Documentation ¶
Overview ¶
Package download handles downloading and extracting sa-mp server versions. Packages are cached in ~/.samp to avoid unnecessary downloads.
Index ¶
- Constants
- func FromCache(cacheDir, filename, dir string, method ExtractFunc, paths map[string]string, ...) (hit bool, err error)
- func FromNet(location, cacheDir, filename string) (result string, err error)
- func GetCacheDir() (cacheDir string)
- func GetPackageList(cacheDir string) (packages []pawnpackage.Package, err error)
- func MigrateOldConfig(cacheDir string) error
- func ReleaseAssetByPattern(ctx context.Context, gh *github.Client, meta versioning.DependencyMeta, ...) (filename, tag string, err error)
- func Untar(src, dst string, paths map[string]string) (files map[string]string, err error)
- func Unzip(src, dst string, paths map[string]string) (files map[string]string, err error)
- func UpdateCompilerList(cacheDir string) (err error)
- func UpdatePackageList(cacheDir string) (err error)
- func UpdateRuntimeList(cacheDir string) (err error)
- func WriteCompilerCacheFile(cacheDir string, data []byte) error
- func WritePackageCacheFile(cacheDir string, data []byte) error
- func WriteRuntimeCacheFile(cacheDir string, data []byte) error
- type Compiler
- type Compilers
- type ExtractFunc
- type RuntimePackage
- type Runtimes
Constants ¶
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(cacheDir, filename, dir string, method ExtractFunc, paths map[string]string, platform string) (hit bool, err error)
FromCache first checks if a file is cached, then
func FromNet ¶
FromNet downloads the server package by filename from the specified location to the cache dir
func GetCacheDir ¶
func GetCacheDir() (cacheDir string)
GetCacheDir returns the full path to the user's cache directory, creating it if it doesn't exist
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 ReleaseAssetByPattern ¶
func ReleaseAssetByPattern( ctx context.Context, gh *github.Client, meta versioning.DependencyMeta, matcher *regexp.Regexp, dir, outputFile, cacheDir string, ) (filename, tag string, err error)
ReleaseAssetByPattern downloads a resource file, which is a GitHub release asset
func Untar ¶
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 Unzip ¶
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 UpdateCompilerList ¶
UpdateCompilerList downloads a list of all runtime packages to a file in the cache directory
func UpdatePackageList ¶
UpdatePackageList downloads a list of all packages to a file in the cache directory
func UpdateRuntimeList ¶
UpdateRuntimeList downloads a list of all runtime packages to a file in the cache directory
func WriteCompilerCacheFile ¶
func WritePackageCacheFile ¶
func WriteRuntimeCacheFile ¶
Types ¶
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 ¶
Compilers is a list of compilers for each platform
func GetCompilerList ¶
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.
type ExtractFunc ¶
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 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 ¶
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.