Commit 17709a7d authored by Matthew Holt's avatar Matthew Holt

Defer loading directives until needed (fix for previous commit)

This change is still experimental.
parent 5a691fba
...@@ -455,7 +455,7 @@ func startWithListenerFds(cdyfile Input, inst *Instance, restartFds map[string]r ...@@ -455,7 +455,7 @@ func startWithListenerFds(cdyfile Input, inst *Instance, restartFds map[string]r
return err return err
} }
err = executeDirectives(inst, cdyfile.Path(), stype.Directives, sblocks) err = executeDirectives(inst, cdyfile.Path(), stype.Directives(), sblocks)
if err != nil { if err != nil {
return err return err
} }
......
...@@ -26,7 +26,7 @@ func init() { ...@@ -26,7 +26,7 @@ func init() {
flag.BoolVar(&QUIC, "quic", false, "Use experimental QUIC") flag.BoolVar(&QUIC, "quic", false, "Use experimental QUIC")
caddy.RegisterServerType(serverType, caddy.ServerType{ caddy.RegisterServerType(serverType, caddy.ServerType{
Directives: directives, Directives: func() []string { return directives },
DefaultInput: func() caddy.Input { DefaultInput: func() caddy.Input {
if Port == DefaultPort && Host != "" { if Port == DefaultPort && Host != "" {
// by leaving the port blank in this case we give auto HTTPS // by leaving the port blank in this case we give auto HTTPS
......
...@@ -79,7 +79,7 @@ func ValidDirectives(serverType string) []string { ...@@ -79,7 +79,7 @@ func ValidDirectives(serverType string) []string {
if err != nil { if err != nil {
return nil return nil
} }
return stype.Directives return stype.Directives()
} }
// ServerListener pairs a server to its listener and/or packetconn. // ServerListener pairs a server to its listener and/or packetconn.
...@@ -145,10 +145,11 @@ func RegisterServerType(typeName string, srv ServerType) { ...@@ -145,10 +145,11 @@ func RegisterServerType(typeName string, srv ServerType) {
// ServerType contains information about a server type. // ServerType contains information about a server type.
type ServerType struct { type ServerType struct {
// List of directives, in execution order, that are // Function that returns the list of directives, in
// valid for this server type. Directives should be // execution order, that are valid for this server
// one word if possible and lower-cased. // type. Directives should be one word if possible
Directives []string // and lower-cased.
Directives func() []string
// DefaultInput returns a default config input if none // DefaultInput returns a default config input if none
// is otherwise loaded. This is optional, but highly // is otherwise loaded. This is optional, but highly
......
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