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)
| 97 | // _ "your_module_path" |
| 98 | // ) |
| 99 | func 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. |
| 125 | func GetModuleDescriptors() []ModuleDescriptor { |