refactor: moved a lot of flags & added comments

Comments added to fix the golint errors on exported things need comments
This commit is contained in:
2021-08-02 07:36:35 +01:00
parent 9070806f8d
commit 38d8b51bd5
18 changed files with 330 additions and 248 deletions

View File

@ -22,6 +22,7 @@ type Image struct {
URL string `json:"url"`
}
// Feature represents a JSON struct for a recipes features
type Feature struct {
Backups string `json:"backups"`
Email string `json:"email"`
@ -31,6 +32,7 @@ type Feature struct {
Tests string `json:"tests"`
}
// Tag represents a git tag
type Tag = string
type Service = string
type ServiceMeta struct {
@ -39,6 +41,7 @@ type ServiceMeta struct {
Tag string `json:"tag"`
}
// App reprents an App in the abra catalogue
type App struct {
Category string `json:"category"`
DefaultBranch string `json:"default_branch"`
@ -51,6 +54,7 @@ type App struct {
Website string `json:"website"`
}
// EnsureExists checks the app has been cloned locally
func (a App) EnsureExists() error {
appDir := path.Join(config.ABRA_DIR, "apps", strings.ToLower(a.Name))
if _, err := os.Stat(appDir); os.IsNotExist(err) {
@ -63,6 +67,7 @@ func (a App) EnsureExists() error {
return nil
}
// EnsureVersion checks if an given version is used for the app
func (a App) EnsureVersion(version string) error {
appDir := path.Join(config.ABRA_DIR, "apps", strings.ToLower(a.Name))
@ -103,6 +108,7 @@ func (a App) EnsureVersion(version string) error {
return nil
}
// LatestVersion returns the latest version of the app
func (a App) LatestVersion() string {
var latestVersion string
for tag := range a.Versions {
@ -115,6 +121,7 @@ func (a App) LatestVersion() string {
type Name = string
type AppsCatalogue map[Name]App
// Flatten converts AppCatalogue to slice
func (a AppsCatalogue) Flatten() []App {
apps := make([]App, 0, len(a))
for name := range a {
@ -131,11 +138,11 @@ func (a ByAppName) Less(i, j int) bool {
return strings.ToLower(a[i].Name) < strings.ToLower(a[j].Name)
}
var AppsCatalogueURL = "https://apps.coopcloud.tech"
var appsCatalogueURL = "https://apps.coopcloud.tech"
func AppsCatalogueFSIsLatest() (bool, error) {
func appsCatalogueFSIsLatest() (bool, error) {
httpClient := &http.Client{Timeout: 5 * time.Second}
res, err := httpClient.Head(AppsCatalogueURL)
res, err := httpClient.Head(appsCatalogueURL)
if err != nil {
return false, err
}
@ -166,47 +173,47 @@ func AppsCatalogueFSIsLatest() (bool, error) {
func ReadAppsCatalogue() (AppsCatalogue, error) {
apps := make(AppsCatalogue)
appsFSIsLatest, err := AppsCatalogueFSIsLatest()
appsFSIsLatest, err := appsCatalogueFSIsLatest()
if err != nil {
return nil, err
}
if !appsFSIsLatest {
if err := ReadAppsCatalogueWeb(&apps); err != nil {
if err := readAppsCatalogueWeb(&apps); err != nil {
return nil, err
}
return apps, nil
}
if err := ReadAppsCatalogueFS(&apps); err != nil {
if err := readAppsCatalogueFS(&apps); err != nil {
return nil, err
}
return apps, nil
}
func ReadAppsCatalogueFS(target interface{}) error {
appsJsonFS, err := ioutil.ReadFile(config.APPS_JSON)
func readAppsCatalogueFS(target interface{}) error {
appsJSONFS, err := ioutil.ReadFile(config.APPS_JSON)
if err != nil {
return err
}
if err := json.Unmarshal(appsJsonFS, &target); err != nil {
if err := json.Unmarshal(appsJSONFS, &target); err != nil {
return err
}
return nil
}
func ReadAppsCatalogueWeb(target interface{}) error {
if err := readJson(AppsCatalogueURL, &target); err != nil {
func readAppsCatalogueWeb(target interface{}) error {
if err := readJson(appsCatalogueURL, &target); err != nil {
return err
}
appsJson, err := json.MarshalIndent(target, "", " ")
appsJSON, err := json.MarshalIndent(target, "", " ")
if err != nil {
return err
}
if err := ioutil.WriteFile(config.APPS_JSON, appsJson, 0644); err != nil {
if err := ioutil.WriteFile(config.APPS_JSON, appsJSON, 0644); err != nil {
return err
}