MCPcopy
hub / github.com/caddyserver/caddy / RegisterModule

Function RegisterModule

modules.go:138–161  ·  modules.go::RegisterModule

RegisterModule registers a module by receiving a plain/empty value of the module. For registration to 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 panics if the module's info is

(instance Module)

Source from the content-addressed store, hash-verified

136// incomplete or invalid, or if the module is already
137// registered.
138func RegisterModule(instance Module) {
139 mod := instance.CaddyModule()
140
141 if mod.ID == "" {
142 panic("module ID missing")
143 }
144 if mod.ID == "caddy" || mod.ID == "admin" {
145 panic(fmt.Sprintf("module ID '%s' is reserved", mod.ID))
146 }
147 if mod.New == nil {
148 panic("missing ModuleInfo.New")
149 }
150 if val := mod.New(); val == nil {
151 panic("ModuleInfo.New must return a non-nil module instance")
152 }
153
154 modulesMu.Lock()
155 defer modulesMu.Unlock()
156
157 if _, ok := modules[string(mod.ID)]; ok {
158 panic(fmt.Sprintf("module already registered: %s", mod.ID))
159 }
160 modules[string(mod.ID)] = mod
161}
162
163// GetModule returns module information from its ID (full name).
164func GetModule(name string) (ModuleInfo, error) {

Callers 5

initFunction · 0.85
TestETagsFunction · 0.85
TestManageIdentityFunction · 0.85

Calls 1

CaddyModuleMethod · 0.65

Tested by 4

TestETagsFunction · 0.68
TestManageIdentityFunction · 0.68