1
0
mirror of https://github.com/rancher/os.git synced 2025-09-05 00:37:12 +00:00

Support service cache update

This commit is contained in:
Jason-ZW
2019-02-25 17:48:31 +08:00
committed by niusmallnan
parent 364c9c115d
commit 66cffc0a91
6 changed files with 108 additions and 18 deletions

View File

@@ -193,3 +193,38 @@ func LoadMultiEngineResource(name string) ([]byte, error) {
return nil, err
}
func UpdateCaches(urls []string, key string) error {
for _, url := range urls {
indexURL := fmt.Sprintf("%s/index.yml", url)
content, err := UpdateCache(indexURL)
if err != nil {
return err
}
services := make(map[string][]string)
err = yaml.Unmarshal(content, &services)
if err != nil {
return err
}
list := services[key]
for _, name := range list {
serviceURL := serviceURL(url, name)
// no need to handle error
UpdateCache(serviceURL)
}
}
return nil
}
func UpdateCache(location string) ([]byte, error) {
if err := cacheRemove(location); err != nil {
return []byte{}, err
}
content, err := LoadResource(location, true)
if err != nil {
return []byte{}, err
}
return content, nil
}