mirror of
https://git.sr.ht/~emersion/tlstunnel
synced 2024-11-19 15:53:50 +01: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:
parent
af78c6600c
commit
8d2b9202b5
@ -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
|
||||
}
|
||||
|
4
main.go
4
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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user