Commit 6f7f5cb2 authored by ale's avatar ale

Allow specifying multiple objects in YAML source/handler files

Support both single-object and lists when reading handlers and sources
from YAML files in a directory.
parent 5d7f1781
Pipeline #3335 passed with stages
in 2 minutes and 2 seconds
......@@ -107,15 +107,22 @@ func (c *Config) parse() (*runtimeAssets, error) {
}, merr.OrNil()
}
// The following functions read YAML files from .d-style directories. To be nice
// to the user, each file can contain either a single object or a list of
// multiple objects.
func readHandlersFromDir(dir string) ([]HandlerSpec, error) {
var out []HandlerSpec
err := foreachYAMLFile(dir, func(path string) error {
var spec HandlerSpec
var specs []HandlerSpec
log.Printf("reading handler: %s", path)
if err := readYAMLFile(path, &spec); err != nil {
return err
if err := readYAMLFile(path, &specs); err != nil {
var spec HandlerSpec
if err := readYAMLFile(path, &spec); err != nil {
return err
}
specs = []HandlerSpec{spec}
}
out = append(out, spec)
out = append(out, specs...)
return nil
})
return out, err
......@@ -124,12 +131,16 @@ func readHandlersFromDir(dir string) ([]HandlerSpec, error) {
func readSourcesFromDir(dir string) ([]SourceSpec, error) {
var out []SourceSpec
err := foreachYAMLFile(dir, func(path string) error {
var spec SourceSpec
var specs []SourceSpec
log.Printf("reading source: %s", path)
if err := readYAMLFile(path, &spec); err != nil {
return err
if err := readYAMLFile(path, &specs); err != nil {
var spec SourceSpec
if err := readYAMLFile(path, &spec); err != nil {
return err
}
specs = []SourceSpec{spec}
}
out = append(out, spec)
out = append(out, specs...)
return nil
})
return out, err
......
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