diff --git a/caddyhttp/basicauth/setup.go b/caddyhttp/basicauth/setup.go index d911f3bd5..e9c691b38 100644 --- a/caddyhttp/basicauth/setup.go +++ b/caddyhttp/basicauth/setup.go @@ -8,8 +8,7 @@ import ( ) func init() { - caddy.RegisterPlugin(caddy.Plugin{ - Name: "basicauth", + caddy.RegisterPlugin("basicauth", caddy.Plugin{ ServerType: "http", Action: setup, }) diff --git a/caddyhttp/bind/bind.go b/caddyhttp/bind/bind.go index fd60f8d1e..460bd5b0e 100644 --- a/caddyhttp/bind/bind.go +++ b/caddyhttp/bind/bind.go @@ -6,8 +6,7 @@ import ( ) func init() { - caddy.RegisterPlugin(caddy.Plugin{ - Name: "bind", + caddy.RegisterPlugin("bind", caddy.Plugin{ ServerType: "http", Action: setupBind, }) diff --git a/caddyhttp/browse/setup.go b/caddyhttp/browse/setup.go index 88f7d44d4..690f97d24 100644 --- a/caddyhttp/browse/setup.go +++ b/caddyhttp/browse/setup.go @@ -11,8 +11,7 @@ import ( ) func init() { - caddy.RegisterPlugin(caddy.Plugin{ - Name: "browse", + caddy.RegisterPlugin("browse", caddy.Plugin{ ServerType: "http", Action: setup, }) diff --git a/caddyhttp/errors/errors.go b/caddyhttp/errors/errors.go index 2527b0069..f933adcd1 100644 --- a/caddyhttp/errors/errors.go +++ b/caddyhttp/errors/errors.go @@ -16,8 +16,7 @@ import ( ) func init() { - caddy.RegisterPlugin(caddy.Plugin{ - Name: "errors", + caddy.RegisterPlugin("errors", caddy.Plugin{ ServerType: "http", Action: setup, }) diff --git a/caddyhttp/expvar/setup.go b/caddyhttp/expvar/setup.go index 4883d7ef3..4bbe69f08 100644 --- a/caddyhttp/expvar/setup.go +++ b/caddyhttp/expvar/setup.go @@ -10,8 +10,7 @@ import ( ) func init() { - caddy.RegisterPlugin(caddy.Plugin{ - Name: "expvar", + caddy.RegisterPlugin("expvar", caddy.Plugin{ ServerType: "http", Action: setup, }) diff --git a/caddyhttp/extensions/setup.go b/caddyhttp/extensions/setup.go index 3d46e77e8..4a1917a14 100644 --- a/caddyhttp/extensions/setup.go +++ b/caddyhttp/extensions/setup.go @@ -6,8 +6,7 @@ import ( ) func init() { - caddy.RegisterPlugin(caddy.Plugin{ - Name: "ext", + caddy.RegisterPlugin("ext", caddy.Plugin{ ServerType: "http", Action: setup, }) diff --git a/caddyhttp/fastcgi/setup.go b/caddyhttp/fastcgi/setup.go index 1b417108e..dd32c593f 100644 --- a/caddyhttp/fastcgi/setup.go +++ b/caddyhttp/fastcgi/setup.go @@ -10,8 +10,7 @@ import ( ) func init() { - caddy.RegisterPlugin(caddy.Plugin{ - Name: "fastcgi", + caddy.RegisterPlugin("fastcgi", caddy.Plugin{ ServerType: "http", Action: setup, }) diff --git a/caddyhttp/gzip/gzip.go b/caddyhttp/gzip/gzip.go index dfee6c2e9..ed95156a3 100644 --- a/caddyhttp/gzip/gzip.go +++ b/caddyhttp/gzip/gzip.go @@ -17,8 +17,7 @@ import ( ) func init() { - caddy.RegisterPlugin(caddy.Plugin{ - Name: "gzip", + caddy.RegisterPlugin("gzip", caddy.Plugin{ ServerType: "http", Action: setup, }) diff --git a/caddyhttp/header/setup.go b/caddyhttp/header/setup.go index 56034921c..be0320045 100644 --- a/caddyhttp/header/setup.go +++ b/caddyhttp/header/setup.go @@ -6,8 +6,7 @@ import ( ) func init() { - caddy.RegisterPlugin(caddy.Plugin{ - Name: "header", + caddy.RegisterPlugin("header", caddy.Plugin{ ServerType: "http", Action: setup, }) diff --git a/caddyhttp/internalsrv/setup.go b/caddyhttp/internalsrv/setup.go index a77edce90..ed69c22b8 100644 --- a/caddyhttp/internalsrv/setup.go +++ b/caddyhttp/internalsrv/setup.go @@ -6,8 +6,7 @@ import ( ) func init() { - caddy.RegisterPlugin(caddy.Plugin{ - Name: "internal", + caddy.RegisterPlugin("internal", caddy.Plugin{ ServerType: "http", Action: setup, }) diff --git a/caddyhttp/log/log.go b/caddyhttp/log/log.go index 1f0b5f0bc..e266f84f5 100644 --- a/caddyhttp/log/log.go +++ b/caddyhttp/log/log.go @@ -11,8 +11,7 @@ import ( ) func init() { - caddy.RegisterPlugin(caddy.Plugin{ - Name: "log", + caddy.RegisterPlugin("log", caddy.Plugin{ ServerType: "http", Action: setup, }) diff --git a/caddyhttp/markdown/setup.go b/caddyhttp/markdown/setup.go index 4bf9426aa..5c15417f0 100644 --- a/caddyhttp/markdown/setup.go +++ b/caddyhttp/markdown/setup.go @@ -10,8 +10,7 @@ import ( ) func init() { - caddy.RegisterPlugin(caddy.Plugin{ - Name: "markdown", + caddy.RegisterPlugin("markdown", caddy.Plugin{ ServerType: "http", Action: setup, }) diff --git a/caddyhttp/mime/setup.go b/caddyhttp/mime/setup.go index bb5c40e0f..28e31a7ce 100644 --- a/caddyhttp/mime/setup.go +++ b/caddyhttp/mime/setup.go @@ -9,8 +9,7 @@ import ( ) func init() { - caddy.RegisterPlugin(caddy.Plugin{ - Name: "mime", + caddy.RegisterPlugin("mime", caddy.Plugin{ ServerType: "http", Action: setup, }) diff --git a/caddyhttp/pprof/setup.go b/caddyhttp/pprof/setup.go index 1c82b856b..7a66cf001 100644 --- a/caddyhttp/pprof/setup.go +++ b/caddyhttp/pprof/setup.go @@ -6,8 +6,7 @@ import ( ) func init() { - caddy.RegisterPlugin(caddy.Plugin{ - Name: "pprof", + caddy.RegisterPlugin("pprof", caddy.Plugin{ ServerType: "http", Action: setup, }) diff --git a/caddyhttp/proxy/setup.go b/caddyhttp/proxy/setup.go index 07d9ac953..600589020 100644 --- a/caddyhttp/proxy/setup.go +++ b/caddyhttp/proxy/setup.go @@ -6,8 +6,7 @@ import ( ) func init() { - caddy.RegisterPlugin(caddy.Plugin{ - Name: "proxy", + caddy.RegisterPlugin("proxy", caddy.Plugin{ ServerType: "http", Action: setup, }) diff --git a/caddyhttp/redirect/setup.go b/caddyhttp/redirect/setup.go index 31fbd7afd..bc838115a 100644 --- a/caddyhttp/redirect/setup.go +++ b/caddyhttp/redirect/setup.go @@ -8,8 +8,7 @@ import ( ) func init() { - caddy.RegisterPlugin(caddy.Plugin{ - Name: "redir", + caddy.RegisterPlugin("redir", caddy.Plugin{ ServerType: "http", Action: setup, }) diff --git a/caddyhttp/rewrite/setup.go b/caddyhttp/rewrite/setup.go index 317b21d4d..9cf3b33b0 100644 --- a/caddyhttp/rewrite/setup.go +++ b/caddyhttp/rewrite/setup.go @@ -10,8 +10,7 @@ import ( ) func init() { - caddy.RegisterPlugin(caddy.Plugin{ - Name: "rewrite", + caddy.RegisterPlugin("rewrite", caddy.Plugin{ ServerType: "http", Action: setup, }) diff --git a/caddyhttp/root/root.go b/caddyhttp/root/root.go index b4e485d1f..d96309f9c 100644 --- a/caddyhttp/root/root.go +++ b/caddyhttp/root/root.go @@ -9,8 +9,7 @@ import ( ) func init() { - caddy.RegisterPlugin(caddy.Plugin{ - Name: "root", + caddy.RegisterPlugin("root", caddy.Plugin{ ServerType: "http", Action: setupRoot, }) diff --git a/caddyhttp/templates/setup.go b/caddyhttp/templates/setup.go index e291b532d..70363f91f 100644 --- a/caddyhttp/templates/setup.go +++ b/caddyhttp/templates/setup.go @@ -8,8 +8,7 @@ import ( ) func init() { - caddy.RegisterPlugin(caddy.Plugin{ - Name: "templates", + caddy.RegisterPlugin("templates", caddy.Plugin{ ServerType: "http", Action: setup, }) diff --git a/caddyhttp/websocket/setup.go b/caddyhttp/websocket/setup.go index fe930de1e..5939aafb5 100644 --- a/caddyhttp/websocket/setup.go +++ b/caddyhttp/websocket/setup.go @@ -6,8 +6,7 @@ import ( ) func init() { - caddy.RegisterPlugin(caddy.Plugin{ - Name: "websocket", + caddy.RegisterPlugin("websocket", caddy.Plugin{ ServerType: "http", Action: setup, }) diff --git a/caddytls/setup.go b/caddytls/setup.go index f9cfc9847..9db647e84 100644 --- a/caddytls/setup.go +++ b/caddytls/setup.go @@ -16,10 +16,7 @@ import ( ) func init() { - caddy.RegisterPlugin(caddy.Plugin{ - Name: "tls", - Action: setupTLS, - }) + caddy.RegisterPlugin("tls", caddy.Plugin{Action: setupTLS}) } // setupTLS sets up the TLS configuration and installs certificates that diff --git a/plugins.go b/plugins.go index f66e24cda..21a909325 100644 --- a/plugins.go +++ b/plugins.go @@ -135,11 +135,6 @@ type ServerType struct { // Plugin is a type which holds information about a plugin. type Plugin struct { - // The plugin must have a name: lower case and one word. - // If this plugin has an action, it must be the name of - // the directive to attach to. A name is always required. - Name string - // ServerType is the type of server this plugin is for. // Can be empty if not applicable, or if the plugin // can associate with any server type. @@ -154,17 +149,22 @@ type Plugin struct { // themselves, even if they do not perform an action associated // with a directive. It is important for the process to know // which plugins are available. -func RegisterPlugin(plugin Plugin) { - if plugin.Name == "" { +// +// The plugin MUST have a name: lower case and one word. +// If this plugin has an action, it must be the name of +// the directive that invokes it. A name is always required +// and must be unique for the server type. +func RegisterPlugin(name string, plugin Plugin) { + if name == "" { panic("plugin must have a name") } if _, ok := plugins[plugin.ServerType]; !ok { plugins[plugin.ServerType] = make(map[string]Plugin) } - if _, dup := plugins[plugin.ServerType][plugin.Name]; dup { - panic("plugin named " + plugin.Name + " already registered for server type " + plugin.ServerType) + if _, dup := plugins[plugin.ServerType][name]; dup { + panic("plugin named " + name + " already registered for server type " + plugin.ServerType) } - plugins[plugin.ServerType][plugin.Name] = plugin + plugins[plugin.ServerType][name] = plugin } // RegisterParsingCallback registers callback to be called after diff --git a/startupshutdown/startupshutdown.go b/startupshutdown/startupshutdown.go index 911e1b015..0a14e0c82 100644 --- a/startupshutdown/startupshutdown.go +++ b/startupshutdown/startupshutdown.go @@ -9,14 +9,8 @@ import ( ) func init() { - caddy.RegisterPlugin(caddy.Plugin{ - Name: "startup", - Action: Startup, - }) - caddy.RegisterPlugin(caddy.Plugin{ - Name: "shutdown", - Action: Shutdown, - }) + caddy.RegisterPlugin("startup", caddy.Plugin{Action: Startup}) + caddy.RegisterPlugin("shutdown", caddy.Plugin{Action: Shutdown}) } // Startup registers a startup callback to execute during server start.