docs: more docs for catalogue package [ci skip]

This commit is contained in:
decentral1se 2021-09-05 00:17:28 +02:00
parent cb637ca89e
commit fb75567729
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC

View File

@ -148,6 +148,7 @@ func (r RecipeCatalogue) Flatten() []Recipe {
return recipes return recipes
} }
// ByRecipeName sorts recipes by name.
type ByRecipeName []Recipe type ByRecipeName []Recipe
func (r ByRecipeName) Len() int { return len(r) } func (r ByRecipeName) Len() int { return len(r) }
@ -156,6 +157,8 @@ func (r ByRecipeName) Less(i, j int) bool {
return strings.ToLower(r[i].Name) < strings.ToLower(r[j].Name) return strings.ToLower(r[i].Name) < strings.ToLower(r[j].Name)
} }
// recipeCatalogueFSIsLatest checks whether the recipe catalogue stored locally
// is up to date.
func recipeCatalogueFSIsLatest() (bool, error) { func recipeCatalogueFSIsLatest() (bool, error) {
httpClient := &http.Client{Timeout: web.Timeout} httpClient := &http.Client{Timeout: web.Timeout}
res, err := httpClient.Head(RecipeCatalogueURL) res, err := httpClient.Head(RecipeCatalogueURL)
@ -186,6 +189,7 @@ func recipeCatalogueFSIsLatest() (bool, error) {
return true, nil return true, nil
} }
// ReadRecipeCatalogue reads the recipe catalogue.
func ReadRecipeCatalogue() (RecipeCatalogue, error) { func ReadRecipeCatalogue() (RecipeCatalogue, error) {
recipes := make(RecipeCatalogue) recipes := make(RecipeCatalogue)
@ -208,6 +212,7 @@ func ReadRecipeCatalogue() (RecipeCatalogue, error) {
return recipes, nil return recipes, nil
} }
// readRecipeCatalogueFS reads the catalogue from the file system.
func readRecipeCatalogueFS(target interface{}) error { func readRecipeCatalogueFS(target interface{}) error {
recipesJSONFS, err := ioutil.ReadFile(config.APPS_JSON) recipesJSONFS, err := ioutil.ReadFile(config.APPS_JSON)
if err != nil { if err != nil {
@ -219,6 +224,7 @@ func readRecipeCatalogueFS(target interface{}) error {
return nil return nil
} }
// readRecipeCatalogueWeb reads the catalogue from the web.
func readRecipeCatalogueWeb(target interface{}) error { func readRecipeCatalogueWeb(target interface{}) error {
if err := web.ReadJSON(RecipeCatalogueURL, &target); err != nil { if err := web.ReadJSON(RecipeCatalogueURL, &target); err != nil {
return err return err
@ -236,6 +242,7 @@ func readRecipeCatalogueWeb(target interface{}) error {
return nil return nil
} }
// VersionsOfService lists the version of a service.
func VersionsOfService(recipe, serviceName string) ([]string, error) { func VersionsOfService(recipe, serviceName string) ([]string, error) {
catalogue, err := ReadRecipeCatalogue() catalogue, err := ReadRecipeCatalogue()
if err != nil { if err != nil {