Files
athens/pkg/module/fetch.go
Rohan Chakravarthy bbe1ce1873 zip.Close() also clears the GOPATH of the underlying diskRef (#367)
* zip.Close() also clears underlying diskRef

* remove unnecessary constructor

* use GoBinPath() in example
2018-07-31 12:38:45 -04:00

33 lines
791 B
Go

package module
import (
"context"
"github.com/gomods/athens/pkg/storage"
)
// Fetch downloads the module@version using the fetcher and stores it in storage
func Fetch(ctx context.Context, s storage.Backend, fetcher Fetcher, mod, version string, mf *Filter) error {
if !mf.ShouldProcess(mod) {
return NewErrModuleExcluded(mod)
}
if s.Exists(ctx, mod, version) {
return NewErrModuleAlreadyFetched("module.Fetch", mod, version)
}
moduleRef, err := fetcher.Fetch(mod, version)
if err != nil {
return err
}
// pretend like moduleLoc has $version.info, $version.mod and $version.zip in it :)
module, err := moduleRef.Read()
if err != nil {
return err
}
defer module.Zip.Close()
return s.Save(context.Background(), mod, version, module.Mod, module.Zip, module.Info)
}