diff options
-rw-r--r-- | caddyconfig/configadapters.go | 9 | ||||
-rw-r--r-- | modules.go | 19 | ||||
-rw-r--r-- | modules/caddyhttp/app.go | 5 | ||||
-rw-r--r-- | modules/caddyhttp/caddyhttp.go | 5 |
4 files changed, 16 insertions, 22 deletions
diff --git a/caddyconfig/configadapters.go b/caddyconfig/configadapters.go index 96d7e10c4..2c466c425 100644 --- a/caddyconfig/configadapters.go +++ b/caddyconfig/configadapters.go @@ -101,13 +101,14 @@ func JSONIndent(val interface{}) ([]byte, error) { } // RegisterAdapter registers a config adapter with the given name. -// This should usually be done at init-time. -func RegisterAdapter(name string, adapter Adapter) error { +// This should usually be done at init-time. It panics if the +// adapter cannot be registered successfully. +func RegisterAdapter(name string, adapter Adapter) { if _, ok := configAdapters[name]; ok { - return fmt.Errorf("%s: already registered", name) + panic(fmt.Errorf("%s: already registered", name)) } configAdapters[name] = adapter - return caddy.RegisterModule(adapterModule{name, adapter}) + caddy.RegisterModule(adapterModule{name, adapter}) } // GetAdapter returns the adapter with the given name, diff --git a/modules.go b/modules.go index d8d6fdd60..584a2984b 100644 --- a/modules.go +++ b/modules.go @@ -125,33 +125,32 @@ type ModuleMap map[string]json.RawMessage // be properly recorded, this should be called in the // init phase of runtime. Typically, the module package // will do this as a side-effect of being imported. -// This function returns an error if the module's info -// is incomplete or invalid, or if the module is -// already registered. -func RegisterModule(instance Module) error { +// This function panics if the module's info is +// incomplete or invalid, or if the module is already +// registered. +func RegisterModule(instance Module) { mod := instance.CaddyModule() if mod.ID == "" { - return fmt.Errorf("module ID missing") + panic("module ID missing") } if mod.ID == "caddy" || mod.ID == "admin" { - return fmt.Errorf("module ID '%s' is reserved", mod.ID) + panic(fmt.Sprintf("module ID '%s' is reserved", mod.ID)) } if mod.New == nil { - return fmt.Errorf("missing ModuleInfo.New") + panic("missing ModuleInfo.New") } if val := mod.New(); val == nil { - return fmt.Errorf("ModuleInfo.New must return a non-nil module instance") + panic("ModuleInfo.New must return a non-nil module instance") } modulesMu.Lock() defer modulesMu.Unlock() if _, ok := modules[string(mod.ID)]; ok { - return fmt.Errorf("module already registered: %s", mod.ID) + panic(fmt.Sprintf("module already registered: %s", mod.ID)) } modules[string(mod.ID)] = mod - return nil } // GetModule returns module information from its ID (full name). diff --git a/modules/caddyhttp/app.go b/modules/caddyhttp/app.go index 292f9341b..8e7f3eaac 100644 --- a/modules/caddyhttp/app.go +++ b/modules/caddyhttp/app.go @@ -30,10 +30,7 @@ import ( ) func init() { - err := caddy.RegisterModule(App{}) - if err != nil { - caddy.Log().Fatal(err.Error()) - } + caddy.RegisterModule(App{}) } // App is a robust, production-ready HTTP server. diff --git a/modules/caddyhttp/caddyhttp.go b/modules/caddyhttp/caddyhttp.go index 6666d3eb0..6dbf7738d 100644 --- a/modules/caddyhttp/caddyhttp.go +++ b/modules/caddyhttp/caddyhttp.go @@ -30,10 +30,7 @@ import ( func init() { weakrand.Seed(time.Now().UnixNano()) - err := caddy.RegisterModule(tlsPlaceholderWrapper{}) - if err != nil { - caddy.Log().Fatal(err.Error()) - } + caddy.RegisterModule(tlsPlaceholderWrapper{}) } // RequestMatcher is a type that can match to a request. |