MCPcopy Create free account
hub / github.com/gotenberg/gotenberg / MustRegisterModule

Function MustRegisterModule

pkg/gotenberg/modules.go:99–122  ·  view source on GitHub ↗

MustRegisterModule registers a module. To register a module, create an init() method in the module main go file: func init() { gotenberg.MustRegisterModule(YourModule{}) } Then, in the main command (github.com/gotenberg/gotenberg/v8/cmd/gotenberg), import the module: imports ( // Gotenber

(mod Module)

Source from the content-addressed store, hash-verified

97// _ "your_module_path"
98// )
99func MustRegisterModule(mod Module) {
100 desc := mod.Descriptor()
101
102 if desc.ID == "" {
103 panic("module with an empty ID cannot be registered")
104 }
105
106 if desc.New == nil {
107 panic("module New function cannot be nil")
108 }
109
110 if val := desc.New(); val == nil {
111 panic("module New function cannot return a nil instance")
112 }
113
114 descriptorsMu.Lock()
115 defer descriptorsMu.Unlock()
116
117 if _, ok := descriptors[desc.ID]; ok {
118 panic(fmt.Sprintf("module %s is already registered", desc.ID))
119 }
120
121 descriptors[desc.ID] = desc
122}
123
124// GetModuleDescriptors returns the descriptors of all registered modules.
125func GetModuleDescriptors() []ModuleDescriptor {

Callers 13

initFunction · 0.92
initFunction · 0.92
initFunction · 0.92
initFunction · 0.92
initFunction · 0.92
initFunction · 0.92
initFunction · 0.92
initFunction · 0.92
initFunction · 0.92
initFunction · 0.92
initFunction · 0.92
initFunction · 0.92

Calls 1

DescriptorMethod · 0.65

Tested by 1

TestMustRegisterModuleFunction · 0.68