Add getAllSites() function to sites.go

This commit is contained in:
Noah 2024-03-10 22:19:25 -05:00
parent 8c52e842b0
commit b07e9a78d8

23
site.go
View File

@ -12,24 +12,35 @@ import (
"github.com/gogs/git-module" "github.com/gogs/git-module"
) )
// startAllSites attempts to start every server in 'sites_dir' // getAllSites gets every site installed
func startAllSites() DeployError { func getAllSites() ([]string, DeployError) {
sites_dir := configuration.sites_dir sites_dir := configuration.sites_dir
files, err := os.ReadDir(sites_dir) files, err := os.ReadDir(sites_dir)
var sites []string
if err != nil { if err != nil {
return newDeployError(1, "startAllSites", return sites, newDeployError(1, "startAllSites", fmt.Sprintf("Failed to read sites from '%s'", sites_dir), fmt.Sprint(err))
fmt.Sprintf("Failed to read sites from '%s'", sites_dir), fmt.Sprint(err))
} }
for _, file := range files { for _, file := range files {
if !file.IsDir() { if !file.IsDir() {
continue continue
} }
err := startSite(file.Name()) sites = append(sites, file.Name())
}
return sites, DeployError{}
}
// startAllSites attempts to start every site
func startAllSites() DeployError {
sites, err := getAllSites()
if err.code != 0 {
return err
}
for _, site := range sites {
err := startSite(site)
if err.code != 0 { if err.code != 0 {
return err return err
} }
} }
return DeployError{} return DeployError{}
} }