Documentation
¶
Overview ¶
Helper methods for working with archived/compressed files.
These functions are separated into their own package to limit the dependencies pulled in when using magex if you are not using archived files.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DownloadToGopathBin ¶
func DownloadToGopathBin(opts DownloadArchiveOptions) error
DownloadToGopathBin downloads an archived file to GOPATH/bin.
Example ¶
package main
import (
"log"
"github.com/carolynvs/magex/pkg/archive"
"github.com/carolynvs/magex/pkg/downloads"
"github.com/carolynvs/magex/pkg/gopath"
)
func main() {
opts := archive.DownloadArchiveOptions{
DownloadOptions: downloads.DownloadOptions{
UrlTemplate: "https://get.helm.sh/helm-{{.VERSION}}-{{.GOOS}}-{{.GOARCH}}{{.EXT}}",
Name: "helm",
Version: "v3.5.3",
},
ArchiveExtensions: map[string]string{
"darwin": ".tar.gz",
"linux": ".tar.gz",
"windows": ".zip",
},
TargetFileTemplate: "{{.GOOS}}-{{.GOARCH}}/helm{{.EXT}}",
}
err := archive.DownloadToGopathBin(opts)
if err != nil {
log.Fatal("could not download helm")
}
// Add GOPATH/bin to PATH if necessary so that we can immediately
// use the installed tool
gopath.EnsureGopathBin()
}
func ExtractBinaryFromArchiveHook ¶
func ExtractBinaryFromArchiveHook(opts DownloadArchiveOptions) downloads.PostDownloadHook
ExtractBinaryFromArchiveHook is the default hook for DownloadToGopathBin.
Types ¶
type DownloadArchiveOptions ¶
type DownloadArchiveOptions struct {
downloads.DownloadOptions
// ArchiveExtensions maps from the GOOS to the expected extension. Required.
// For example, windows may use .zip while darwin/linux uses .tgz.
ArchiveExtensions map[string]string
// TargetFileTemplate specifies the path to the target binary in the archive. Required.
// Supports the same templating as downloads.DownloadOptions.UrlTemplate.
TargetFileTemplate string
}
DownloadArchiveOptions are the set of options available for DownloadToGopathBin.
Click to show internal directories.
Click to hide internal directories.