1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
package main
import (
"encoding/json"
"os"
"github.com/lxc/incus/v6/shared/simplestreams"
)
func writeIndex(products *simplestreams.Products) error {
// Update the product list.
productNames := make([]string, 0, len(products.Products))
for name := range products.Products {
productNames = append(productNames, name)
}
// Write a new index file.
stream := simplestreams.Stream{
Format: "index:1.0",
Index: map[string]simplestreams.StreamIndex{
"images": {
DataType: "image-downloads",
Path: "streams/v1/images.json",
Format: "products:1.0",
Products: productNames,
},
},
}
body, err := json.Marshal(&stream)
if err != nil {
return err
}
err = os.WriteFile("streams/v1/index.json", body, 0o644)
if err != nil {
return err
}
return nil
}
|