mirror of
https://github.com/caddyserver/caddy.git
synced 2024-11-29 20:24:11 +08:00
f3596f734d
Turns out having each server block share a single server.Config during initialization when the Setup functions are being called was a bad idea. Sure, startup and shutdown functions were only executed once, but they had no idea what their hostname or port was. So here we revert to the old way of doing things where Setup may be called multiple times per server block (once per host associated with the block, to be precise), but the Setup functions now know their host and port since the config belongs to exactly one virtualHost. To have something happen just once per server block, use OncePerServerBlock, a new function available on each Controller.
30 lines
903 B
Go
30 lines
903 B
Go
// Package parse provides facilities for parsing configuration files.
|
|
package parse
|
|
|
|
import "io"
|
|
|
|
// ServerBlocks parses the input just enough to organize tokens,
|
|
// in order, by server block. No further parsing is performed.
|
|
// Server blocks are returned in the order in which they appear.
|
|
func ServerBlocks(filename string, input io.Reader) ([]serverBlock, error) {
|
|
p := parser{Dispenser: NewDispenser(filename, input)}
|
|
blocks, err := p.parseAll()
|
|
return blocks, err
|
|
}
|
|
|
|
// allTokens lexes the entire input, but does not parse it.
|
|
// It returns all the tokens from the input, unstructured
|
|
// and in order.
|
|
func allTokens(input io.Reader) (tokens []token) {
|
|
l := new(lexer)
|
|
l.load(input)
|
|
for l.next() {
|
|
tokens = append(tokens, l.token)
|
|
}
|
|
return
|
|
}
|
|
|
|
// Set of directives that are valid (unordered). Populated
|
|
// by config package's init function.
|
|
var ValidDirectives = make(map[string]struct{})
|