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(request CacheExtractRequest) (bool, error)
- func FromNet(ctx context.Context, location, cachePath string) (result string, err error)
- func FromNetWithClient(ctx context.Context, client HTTPDoer, location, cachePath string) (result string, err error)
- func GetPackageList(cacheDir string) (packages []pawnpackage.Package, err error)
- func GetPackageListContext(ctx context.Context, cacheDir string) (packages []pawnpackage.Package, err error)
- func GetPackageListWithClient(cacheDir string, client HTTPDoer) (packages []pawnpackage.Package, err error)
- func GetPackageListWithClientContext(ctx context.Context, cacheDir string, client HTTPDoer) (packages []pawnpackage.Package, err error)
- func MigrateOldConfig(cacheDir string) error
- func ReleaseAssetByPattern(request ReleaseAssetRequest) (filename, tag string, err error)
- func ReleaseAssetByPatternWithAPI(request ReleaseAssetAPIRequest) (filename, tag string, err error)
- func Untar(src, dst string, paths map[string]string) (files map[string]string, err error)
- func UntarWithIgnore(src, dst string, paths map[string]string, ignorePatterns []string) (files map[string]string, err error)
- func Unzip(src, dst string, paths map[string]string) (files map[string]string, err error)
- func UnzipWithIgnore(src, dst string, paths map[string]string, ignorePatterns []string) (files map[string]string, err error)
- func UpdateCompilerList(cacheDir string) (err error)
- func UpdateCompilerListContext(ctx context.Context, cacheDir string) (err error)
- func UpdateCompilerListWithClientContext(ctx context.Context, cacheDir string, client HTTPDoer) (err error)
- func UpdatePackageList(cacheDir string) (err error)
- func UpdatePackageListContext(ctx context.Context, cacheDir string) (err error)
- func UpdatePackageListWithClient(cacheDir string, client HTTPDoer) (err error)
- func UpdatePackageListWithClientContext(ctx context.Context, cacheDir string, client HTTPDoer) (err error)
- func UpdateRuntimeList(cacheDir string) (err error)
- func UpdateRuntimeListContext(ctx context.Context, cacheDir string) (err error)
- func UpdateRuntimeListWithClientContext(ctx context.Context, cacheDir string, client HTTPDoer) (err error)
- func WriteCompilerCacheFile(cacheDir string, data []byte) error
- func WritePackageCacheFile(cacheDir string, data []byte) error
- func WriteRuntimeCacheFile(cacheDir string, data []byte) error
- type CacheExtractRequest
- type Compiler
- type Compilers
- type ExtractFunc
- type GitHubReleasesAPI
- type HTTPDoer
- type ReleaseAssetAPIRequest
- type ReleaseAssetDownloadRequest
- type ReleaseAssetRequest
- 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(request CacheExtractRequest) (bool, error)
FromCache first checks if a file is cached, then extracts it if present.
func FromNetWithClient ¶
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 GetPackageListWithClient ¶
func GetPackageListWithClient(cacheDir string, client HTTPDoer) (packages []pawnpackage.Package, err error)
func MigrateOldConfig ¶
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 ¶
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 ¶
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 ¶
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 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 ¶
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.
func GetCompilerListContext ¶
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 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 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 ¶
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.