From 8d2b9202b56e61095f4c25c203e26609640eb29e Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 9 Sep 2020 11:00:00 +0200 Subject: [PATCH] Require frontend blocks to have the name "frontend" This allows us to easily add other kind of toplevel directives, e.g. for global configuration options. --- config.go | 8 ++++---- main.go | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/config.go b/config.go index 9032094..f802747 100644 --- a/config.go +++ b/config.go @@ -47,7 +47,7 @@ func (d *Directive) ChildByName(name string) *Directive { return nil } -func Load(path string) ([]*Directive, error) { +func Load(path string) (*Directive, error) { f, err := os.Open(path) if err != nil { return nil, err @@ -57,7 +57,7 @@ func Load(path string) ([]*Directive, error) { return Parse(f) } -func Parse(r io.Reader) ([]*Directive, error) { +func Parse(r io.Reader) (*Directive, error) { scanner := bufio.NewScanner(r) var directives []*Directive @@ -66,7 +66,7 @@ func Parse(r io.Reader) ([]*Directive, error) { l := scanner.Text() words, err := shlex.Split(l) if err != nil { - return directives, fmt.Errorf("failed to parse config file: %v", err) + return nil, fmt.Errorf("failed to parse config file: %v", err) } else if len(words) == 0 { continue } @@ -98,5 +98,5 @@ func Parse(r io.Reader) ([]*Directive, error) { return nil, fmt.Errorf("failed to read config file: %v", err) } - return directives, nil + return &Directive{Children: directives}, nil } diff --git a/main.go b/main.go index 1a5f357..867930a 100644 --- a/main.go +++ b/main.go @@ -10,14 +10,14 @@ import ( ) func main() { - directives, err := Load("config") + cfg, err := Load("config") if err != nil { log.Fatalf("failed to load config file: %v", err) } srv := NewServer() - for _, d := range directives { + for _, d := range cfg.ChildrenByName("frontend") { if err := parseFrontend(srv, d); err != nil { log.Fatalf("failed to parse frontend: %v", err) }