Commit d3860f95 authored by Matthew Holt's avatar Matthew Holt

Make RegisterPlugin() more consistent, having name as first argument

parent 9b4134b2
......@@ -8,8 +8,7 @@ import (
)
func init() {
caddy.RegisterPlugin(caddy.Plugin{
Name: "basicauth",
caddy.RegisterPlugin("basicauth", caddy.Plugin{
ServerType: "http",
Action: setup,
})
......
......@@ -6,8 +6,7 @@ import (
)
func init() {
caddy.RegisterPlugin(caddy.Plugin{
Name: "bind",
caddy.RegisterPlugin("bind", caddy.Plugin{
ServerType: "http",
Action: setupBind,
})
......
......@@ -11,8 +11,7 @@ import (
)
func init() {
caddy.RegisterPlugin(caddy.Plugin{
Name: "browse",
caddy.RegisterPlugin("browse", caddy.Plugin{
ServerType: "http",
Action: setup,
})
......
......@@ -16,8 +16,7 @@ import (
)
func init() {
caddy.RegisterPlugin(caddy.Plugin{
Name: "errors",
caddy.RegisterPlugin("errors", caddy.Plugin{
ServerType: "http",
Action: setup,
})
......
......@@ -10,8 +10,7 @@ import (
)
func init() {
caddy.RegisterPlugin(caddy.Plugin{
Name: "expvar",
caddy.RegisterPlugin("expvar", caddy.Plugin{
ServerType: "http",
Action: setup,
})
......
......@@ -6,8 +6,7 @@ import (
)
func init() {
caddy.RegisterPlugin(caddy.Plugin{
Name: "ext",
caddy.RegisterPlugin("ext", caddy.Plugin{
ServerType: "http",
Action: setup,
})
......
......@@ -10,8 +10,7 @@ import (
)
func init() {
caddy.RegisterPlugin(caddy.Plugin{
Name: "fastcgi",
caddy.RegisterPlugin("fastcgi", caddy.Plugin{
ServerType: "http",
Action: setup,
})
......
......@@ -17,8 +17,7 @@ import (
)
func init() {
caddy.RegisterPlugin(caddy.Plugin{
Name: "gzip",
caddy.RegisterPlugin("gzip", caddy.Plugin{
ServerType: "http",
Action: setup,
})
......
......@@ -6,8 +6,7 @@ import (
)
func init() {
caddy.RegisterPlugin(caddy.Plugin{
Name: "header",
caddy.RegisterPlugin("header", caddy.Plugin{
ServerType: "http",
Action: setup,
})
......
......@@ -6,8 +6,7 @@ import (
)
func init() {
caddy.RegisterPlugin(caddy.Plugin{
Name: "internal",
caddy.RegisterPlugin("internal", caddy.Plugin{
ServerType: "http",
Action: setup,
})
......
......@@ -11,8 +11,7 @@ import (
)
func init() {
caddy.RegisterPlugin(caddy.Plugin{
Name: "log",
caddy.RegisterPlugin("log", caddy.Plugin{
ServerType: "http",
Action: setup,
})
......
......@@ -10,8 +10,7 @@ import (
)
func init() {
caddy.RegisterPlugin(caddy.Plugin{
Name: "markdown",
caddy.RegisterPlugin("markdown", caddy.Plugin{
ServerType: "http",
Action: setup,
})
......
......@@ -9,8 +9,7 @@ import (
)
func init() {
caddy.RegisterPlugin(caddy.Plugin{
Name: "mime",
caddy.RegisterPlugin("mime", caddy.Plugin{
ServerType: "http",
Action: setup,
})
......
......@@ -6,8 +6,7 @@ import (
)
func init() {
caddy.RegisterPlugin(caddy.Plugin{
Name: "pprof",
caddy.RegisterPlugin("pprof", caddy.Plugin{
ServerType: "http",
Action: setup,
})
......
......@@ -6,8 +6,7 @@ import (
)
func init() {
caddy.RegisterPlugin(caddy.Plugin{
Name: "proxy",
caddy.RegisterPlugin("proxy", caddy.Plugin{
ServerType: "http",
Action: setup,
})
......
......@@ -8,8 +8,7 @@ import (
)
func init() {
caddy.RegisterPlugin(caddy.Plugin{
Name: "redir",
caddy.RegisterPlugin("redir", caddy.Plugin{
ServerType: "http",
Action: setup,
})
......
......@@ -10,8 +10,7 @@ import (
)
func init() {
caddy.RegisterPlugin(caddy.Plugin{
Name: "rewrite",
caddy.RegisterPlugin("rewrite", caddy.Plugin{
ServerType: "http",
Action: setup,
})
......
......@@ -9,8 +9,7 @@ import (
)
func init() {
caddy.RegisterPlugin(caddy.Plugin{
Name: "root",
caddy.RegisterPlugin("root", caddy.Plugin{
ServerType: "http",
Action: setupRoot,
})
......
......@@ -8,8 +8,7 @@ import (
)
func init() {
caddy.RegisterPlugin(caddy.Plugin{
Name: "templates",
caddy.RegisterPlugin("templates", caddy.Plugin{
ServerType: "http",
Action: setup,
})
......
......@@ -6,8 +6,7 @@ import (
)
func init() {
caddy.RegisterPlugin(caddy.Plugin{
Name: "websocket",
caddy.RegisterPlugin("websocket", caddy.Plugin{
ServerType: "http",
Action: setup,
})
......
......@@ -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
......
......@@ -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
......
......@@ -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.
......
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