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 ( ...@@ -8,8 +8,7 @@ import (
) )
func init() { func init() {
caddy.RegisterPlugin(caddy.Plugin{ caddy.RegisterPlugin("basicauth", caddy.Plugin{
Name: "basicauth",
ServerType: "http", ServerType: "http",
Action: setup, Action: setup,
}) })
......
...@@ -6,8 +6,7 @@ import ( ...@@ -6,8 +6,7 @@ import (
) )
func init() { func init() {
caddy.RegisterPlugin(caddy.Plugin{ caddy.RegisterPlugin("bind", caddy.Plugin{
Name: "bind",
ServerType: "http", ServerType: "http",
Action: setupBind, Action: setupBind,
}) })
......
...@@ -11,8 +11,7 @@ import ( ...@@ -11,8 +11,7 @@ import (
) )
func init() { func init() {
caddy.RegisterPlugin(caddy.Plugin{ caddy.RegisterPlugin("browse", caddy.Plugin{
Name: "browse",
ServerType: "http", ServerType: "http",
Action: setup, Action: setup,
}) })
......
...@@ -16,8 +16,7 @@ import ( ...@@ -16,8 +16,7 @@ import (
) )
func init() { func init() {
caddy.RegisterPlugin(caddy.Plugin{ caddy.RegisterPlugin("errors", caddy.Plugin{
Name: "errors",
ServerType: "http", ServerType: "http",
Action: setup, Action: setup,
}) })
......
...@@ -10,8 +10,7 @@ import ( ...@@ -10,8 +10,7 @@ import (
) )
func init() { func init() {
caddy.RegisterPlugin(caddy.Plugin{ caddy.RegisterPlugin("expvar", caddy.Plugin{
Name: "expvar",
ServerType: "http", ServerType: "http",
Action: setup, Action: setup,
}) })
......
...@@ -6,8 +6,7 @@ import ( ...@@ -6,8 +6,7 @@ import (
) )
func init() { func init() {
caddy.RegisterPlugin(caddy.Plugin{ caddy.RegisterPlugin("ext", caddy.Plugin{
Name: "ext",
ServerType: "http", ServerType: "http",
Action: setup, Action: setup,
}) })
......
...@@ -10,8 +10,7 @@ import ( ...@@ -10,8 +10,7 @@ import (
) )
func init() { func init() {
caddy.RegisterPlugin(caddy.Plugin{ caddy.RegisterPlugin("fastcgi", caddy.Plugin{
Name: "fastcgi",
ServerType: "http", ServerType: "http",
Action: setup, Action: setup,
}) })
......
...@@ -17,8 +17,7 @@ import ( ...@@ -17,8 +17,7 @@ import (
) )
func init() { func init() {
caddy.RegisterPlugin(caddy.Plugin{ caddy.RegisterPlugin("gzip", caddy.Plugin{
Name: "gzip",
ServerType: "http", ServerType: "http",
Action: setup, Action: setup,
}) })
......
...@@ -6,8 +6,7 @@ import ( ...@@ -6,8 +6,7 @@ import (
) )
func init() { func init() {
caddy.RegisterPlugin(caddy.Plugin{ caddy.RegisterPlugin("header", caddy.Plugin{
Name: "header",
ServerType: "http", ServerType: "http",
Action: setup, Action: setup,
}) })
......
...@@ -6,8 +6,7 @@ import ( ...@@ -6,8 +6,7 @@ import (
) )
func init() { func init() {
caddy.RegisterPlugin(caddy.Plugin{ caddy.RegisterPlugin("internal", caddy.Plugin{
Name: "internal",
ServerType: "http", ServerType: "http",
Action: setup, Action: setup,
}) })
......
...@@ -11,8 +11,7 @@ import ( ...@@ -11,8 +11,7 @@ import (
) )
func init() { func init() {
caddy.RegisterPlugin(caddy.Plugin{ caddy.RegisterPlugin("log", caddy.Plugin{
Name: "log",
ServerType: "http", ServerType: "http",
Action: setup, Action: setup,
}) })
......
...@@ -10,8 +10,7 @@ import ( ...@@ -10,8 +10,7 @@ import (
) )
func init() { func init() {
caddy.RegisterPlugin(caddy.Plugin{ caddy.RegisterPlugin("markdown", caddy.Plugin{
Name: "markdown",
ServerType: "http", ServerType: "http",
Action: setup, Action: setup,
}) })
......
...@@ -9,8 +9,7 @@ import ( ...@@ -9,8 +9,7 @@ import (
) )
func init() { func init() {
caddy.RegisterPlugin(caddy.Plugin{ caddy.RegisterPlugin("mime", caddy.Plugin{
Name: "mime",
ServerType: "http", ServerType: "http",
Action: setup, Action: setup,
}) })
......
...@@ -6,8 +6,7 @@ import ( ...@@ -6,8 +6,7 @@ import (
) )
func init() { func init() {
caddy.RegisterPlugin(caddy.Plugin{ caddy.RegisterPlugin("pprof", caddy.Plugin{
Name: "pprof",
ServerType: "http", ServerType: "http",
Action: setup, Action: setup,
}) })
......
...@@ -6,8 +6,7 @@ import ( ...@@ -6,8 +6,7 @@ import (
) )
func init() { func init() {
caddy.RegisterPlugin(caddy.Plugin{ caddy.RegisterPlugin("proxy", caddy.Plugin{
Name: "proxy",
ServerType: "http", ServerType: "http",
Action: setup, Action: setup,
}) })
......
...@@ -8,8 +8,7 @@ import ( ...@@ -8,8 +8,7 @@ import (
) )
func init() { func init() {
caddy.RegisterPlugin(caddy.Plugin{ caddy.RegisterPlugin("redir", caddy.Plugin{
Name: "redir",
ServerType: "http", ServerType: "http",
Action: setup, Action: setup,
}) })
......
...@@ -10,8 +10,7 @@ import ( ...@@ -10,8 +10,7 @@ import (
) )
func init() { func init() {
caddy.RegisterPlugin(caddy.Plugin{ caddy.RegisterPlugin("rewrite", caddy.Plugin{
Name: "rewrite",
ServerType: "http", ServerType: "http",
Action: setup, Action: setup,
}) })
......
...@@ -9,8 +9,7 @@ import ( ...@@ -9,8 +9,7 @@ import (
) )
func init() { func init() {
caddy.RegisterPlugin(caddy.Plugin{ caddy.RegisterPlugin("root", caddy.Plugin{
Name: "root",
ServerType: "http", ServerType: "http",
Action: setupRoot, Action: setupRoot,
}) })
......
...@@ -8,8 +8,7 @@ import ( ...@@ -8,8 +8,7 @@ import (
) )
func init() { func init() {
caddy.RegisterPlugin(caddy.Plugin{ caddy.RegisterPlugin("templates", caddy.Plugin{
Name: "templates",
ServerType: "http", ServerType: "http",
Action: setup, Action: setup,
}) })
......
...@@ -6,8 +6,7 @@ import ( ...@@ -6,8 +6,7 @@ import (
) )
func init() { func init() {
caddy.RegisterPlugin(caddy.Plugin{ caddy.RegisterPlugin("websocket", caddy.Plugin{
Name: "websocket",
ServerType: "http", ServerType: "http",
Action: setup, Action: setup,
}) })
......
...@@ -16,10 +16,7 @@ import ( ...@@ -16,10 +16,7 @@ import (
) )
func init() { func init() {
caddy.RegisterPlugin(caddy.Plugin{ caddy.RegisterPlugin("tls", caddy.Plugin{Action: setupTLS})
Name: "tls",
Action: setupTLS,
})
} }
// setupTLS sets up the TLS configuration and installs certificates that // setupTLS sets up the TLS configuration and installs certificates that
......
...@@ -135,11 +135,6 @@ type ServerType struct { ...@@ -135,11 +135,6 @@ type ServerType struct {
// Plugin is a type which holds information about a plugin. // Plugin is a type which holds information about a plugin.
type Plugin struct { 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. // ServerType is the type of server this plugin is for.
// Can be empty if not applicable, or if the plugin // Can be empty if not applicable, or if the plugin
// can associate with any server type. // can associate with any server type.
...@@ -154,17 +149,22 @@ type Plugin struct { ...@@ -154,17 +149,22 @@ type Plugin struct {
// themselves, even if they do not perform an action associated // themselves, even if they do not perform an action associated
// with a directive. It is important for the process to know // with a directive. It is important for the process to know
// which plugins are available. // 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") panic("plugin must have a name")
} }
if _, ok := plugins[plugin.ServerType]; !ok { if _, ok := plugins[plugin.ServerType]; !ok {
plugins[plugin.ServerType] = make(map[string]Plugin) plugins[plugin.ServerType] = make(map[string]Plugin)
} }
if _, dup := plugins[plugin.ServerType][plugin.Name]; dup { if _, dup := plugins[plugin.ServerType][name]; dup {
panic("plugin named " + plugin.Name + " already registered for server type " + plugin.ServerType) 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 // RegisterParsingCallback registers callback to be called after
......
...@@ -9,14 +9,8 @@ import ( ...@@ -9,14 +9,8 @@ import (
) )
func init() { func init() {
caddy.RegisterPlugin(caddy.Plugin{ caddy.RegisterPlugin("startup", caddy.Plugin{Action: Startup})
Name: "startup", caddy.RegisterPlugin("shutdown", caddy.Plugin{Action: Shutdown})
Action: Startup,
})
caddy.RegisterPlugin(caddy.Plugin{
Name: "shutdown",
Action: Shutdown,
})
} }
// Startup registers a startup callback to execute during server start. // 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