1
1
Fork 0
mirror of https://git.sr.ht/~emersion/tlstunnel synced 2024-05-11 13:46:03 +02:00

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.
This commit is contained in:
Simon Ser 2020-09-09 11:00:00 +02:00
parent af78c6600c
commit 8d2b9202b5
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
2 changed files with 6 additions and 6 deletions

View File

@ -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
}

View File

@ -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)
}