Commit b0d2931a authored by ale's avatar ale

Load configuration files in sorted order

Allows us to use rc.d-style setup where later files override contents
from previous ones, useful in a configuration management context.
parent 53e98a2c
Pipeline #2170 passed with stages
in 1 minute and 26 seconds
......@@ -4,6 +4,7 @@ import (
"io/ioutil"
"log"
"path/filepath"
"sort"
"git.autistici.org/ai3/go-common/clientutil"
"gopkg.in/yaml.v2"
......@@ -81,12 +82,21 @@ func loadStandaloneBackendConfig(path string) (map[string]yaml.MapSlice, error)
return out, nil
}
// Sort a string slice.
type filesList []string
func (l filesList) Len() int { return len(l) }
func (l filesList) Swap(i, j int) { l[i], l[j] = l[j], l[i] }
func (l filesList) Less(i, j int) bool { return l[i] < l[j] }
// Apply a function to all files matching a glob pattern (errors are ignored).
// Files are visited in sorted order.
func forAllFiles(pattern string, f func(string)) {
files, err := filepath.Glob(pattern)
if err != nil {
return
}
sort.Sort(filesList(files))
for _, file := range files {
f(file)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment