From 17709a7d3f1a6ee0c34bdb81c6332b1339ea7085 Mon Sep 17 00:00:00 2001
From: Matthew Holt <mholt@users.noreply.github.com>
Date: Thu, 25 Aug 2016 00:15:18 -0600
Subject: [PATCH] Defer loading directives until needed (fix for previous
 commit)

This change is still experimental.
---
 caddy.go                       |  2 +-
 caddyhttp/httpserver/plugin.go |  2 +-
 plugins.go                     | 11 ++++++-----
 3 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/caddy.go b/caddy.go
index b0ec1af66..76ebc0134 100644
--- a/caddy.go
+++ b/caddy.go
@@ -455,7 +455,7 @@ func startWithListenerFds(cdyfile Input, inst *Instance, restartFds map[string]r
 		return err
 	}
 
-	err = executeDirectives(inst, cdyfile.Path(), stype.Directives, sblocks)
+	err = executeDirectives(inst, cdyfile.Path(), stype.Directives(), sblocks)
 	if err != nil {
 		return err
 	}
diff --git a/caddyhttp/httpserver/plugin.go b/caddyhttp/httpserver/plugin.go
index 1a932523c..685db0bce 100644
--- a/caddyhttp/httpserver/plugin.go
+++ b/caddyhttp/httpserver/plugin.go
@@ -26,7 +26,7 @@ func init() {
 	flag.BoolVar(&QUIC, "quic", false, "Use experimental QUIC")
 
 	caddy.RegisterServerType(serverType, caddy.ServerType{
-		Directives: directives,
+		Directives: func() []string { return directives },
 		DefaultInput: func() caddy.Input {
 			if Port == DefaultPort && Host != "" {
 				// by leaving the port blank in this case we give auto HTTPS
diff --git a/plugins.go b/plugins.go
index bf1371709..92526ad81 100644
--- a/plugins.go
+++ b/plugins.go
@@ -79,7 +79,7 @@ func ValidDirectives(serverType string) []string {
 	if err != nil {
 		return nil
 	}
-	return stype.Directives
+	return stype.Directives()
 }
 
 // ServerListener pairs a server to its listener and/or packetconn.
@@ -145,10 +145,11 @@ func RegisterServerType(typeName string, srv ServerType) {
 
 // ServerType contains information about a server type.
 type ServerType struct {
-	// List of directives, in execution order, that are
-	// valid for this server type. Directives should be
-	// one word if possible and lower-cased.
-	Directives []string
+	// Function that returns the list of directives, in
+	// execution order, that are valid for this server
+	// type. Directives should be one word if possible
+	// and lower-cased.
+	Directives func() []string
 
 	// DefaultInput returns a default config input if none
 	// is otherwise loaded. This is optional, but highly