github.com/eliastor/durgaform@v0.0.0-20220816172711-d0ab2d17673e/internal/getmodules/installer.go (about) 1 package getmodules 2 3 import ( 4 "context" 5 ) 6 7 // PackageFetcher is a low-level utility for fetching remote module packages 8 // into local filesystem directories in preparation for use by higher-level 9 // module installer functionality implemented elsewhere. 10 // 11 // A PackageFetcher works only with entire module packages and never with 12 // the individual modules within a package. 13 // 14 // A particular PackageFetcher instance remembers the target directory of 15 // any successfully-installed package so that it can optimize future calls 16 // that have the same package address by copying the local directory tree, 17 // rather than fetching the package from its origin repeatedly. There is 18 // no way to reset this cache, so a particular PackageFetcher instance should 19 // live only for the duration of a single initialization process. 20 type PackageFetcher struct { 21 getter reusingGetter 22 } 23 24 func NewPackageFetcher() *PackageFetcher { 25 return &PackageFetcher{ 26 getter: reusingGetter{}, 27 } 28 } 29 30 // FetchPackage downloads or otherwise retrieves the filesystem inside the 31 // package at the given address into the given local installation directory. 32 // 33 // packageAddr must be formatted as if it were the result of an 34 // addrs.ModulePackage.String() call. It's only defined as a raw string here 35 // because the getmodules package can't import the addrs package due to 36 // that creating a package dependency cycle. 37 // 38 // PackageFetcher only works with entire packages. If the caller is processing 39 // a module source address which includes a subdirectory portion then the 40 // caller must resolve that itself, possibly with the help of the 41 // getmodules.SplitPackageSubdir and getmodules.ExpandSubdirGlobs functions. 42 func (f *PackageFetcher) FetchPackage(ctx context.Context, instDir string, packageAddr string) error { 43 return f.getter.getWithGoGetter(ctx, instDir, packageAddr) 44 }