本文整理汇总了Golang中github.com/bitrise-io/stepman/models.StepCollectionModel.GetDownloadLocations方法的典型用法代码示例。如果您正苦于以下问题:Golang StepCollectionModel.GetDownloadLocations方法的具体用法?Golang StepCollectionModel.GetDownloadLocations怎么用?Golang StepCollectionModel.GetDownloadLocations使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/bitrise-io/stepman/models.StepCollectionModel
的用法示例。
在下文中一共展示了StepCollectionModel.GetDownloadLocations方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: DownloadStep
// DownloadStep ...
func DownloadStep(collectionURI string, collection models.StepCollectionModel, id, version, commithash string) error {
downloadLocations, err := collection.GetDownloadLocations(id, version)
if err != nil {
return err
}
route, found := ReadRoute(collectionURI)
if !found {
return fmt.Errorf("No routing found for lib: %s", collectionURI)
}
stepPth := GetStepCacheDirPath(route, id, version)
if exist, err := pathutil.IsPathExists(stepPth); err != nil {
return err
} else if exist {
return nil
}
success := false
for _, downloadLocation := range downloadLocations {
switch downloadLocation.Type {
case "zip":
err := retry.Times(2).Wait(3 * time.Second).Try(func(attempt uint) error {
return cmdex.DownloadAndUnZIP(downloadLocation.Src, stepPth)
})
if err != nil {
log.Warn("Failed to download step.zip: ", err)
} else {
success = true
return nil
}
case "git":
err := retry.Times(2).Wait(3 * time.Second).Try(func(attempt uint) error {
return cmdex.GitCloneTagOrBranchAndValidateCommitHash(downloadLocation.Src, stepPth, version, commithash)
})
if err != nil {
log.Warnf("Failed to clone step (%s): %v", downloadLocation.Src, err)
} else {
success = true
return nil
}
default:
return fmt.Errorf("Failed to download: Invalid download location (%#v) for step %#v (%#v)", downloadLocation, id, version)
}
}
if !success {
return errors.New("Failed to download step")
}
return nil
}
示例2: DownloadStep
// DownloadStep ...
func DownloadStep(collectionURI string, collection models.StepCollectionModel, id, version, commithash string) error {
log.Debugf("Download Step: %#v (%#v)\n", id, version)
downloadLocations, err := collection.GetDownloadLocations(id, version)
if err != nil {
return err
}
route, found := ReadRoute(collectionURI)
if !found {
return fmt.Errorf("No routing found for lib: %s", collectionURI)
}
stepPth := GetStepCacheDirPath(route, id, version)
if exist, err := pathutil.IsPathExists(stepPth); err != nil {
return err
} else if exist {
log.Debug("[STEPMAN] - Step already downloaded")
return nil
}
success := false
for _, downloadLocation := range downloadLocations {
switch downloadLocation.Type {
case "zip":
log.Debug("[STEPMAN] - Downloading step from: ", downloadLocation.Src)
if err := cmdex.DownloadAndUnZIP(downloadLocation.Src, stepPth); err != nil {
log.Warn("[STEPMAN] - Failed to download step.zip: ", err)
} else {
success = true
return nil
}
case "git":
log.Debug("[STEPMAN] - Git clone step from: ", downloadLocation.Src)
if err := cmdex.GitCloneTagOrBranchAndValidateCommitHash(downloadLocation.Src, stepPth, version, commithash); err != nil {
log.Warnf("[STEPMAN] - Failed to clone step (%s): %v", downloadLocation.Src, err)
} else {
success = true
return nil
}
default:
return fmt.Errorf("[STEPMAN] - Failed to download: Invalid download location (%#v) for step %#v (%#v)", downloadLocation, id, version)
}
}
if !success {
return errors.New("Failed to download step")
}
return nil
}