Module returns a module which satisfies the requested interface. func (m *YourModule) Provision(ctx *gotenberg.Context) error { mod, _ := ctx.Module(new(ModuleInterface)) real := mod.(ModuleInterface) } If the module has not yet been initialized, this method initializes it. Otherwise, return
(kind any)
| 46 | // If the module has not yet been initialized, this method |
| 47 | // initializes it. Otherwise, returns the already initialized instance. |
| 48 | func (ctx *Context) Module(kind any) (any, error) { |
| 49 | mods, err := ctx.Modules(kind) |
| 50 | if err != nil { |
| 51 | return nil, fmt.Errorf("get module: %w", err) |
| 52 | } |
| 53 | |
| 54 | if len(mods) != 1 { |
| 55 | return nil, fmt.Errorf("expected to have one and only one %s module", kind) |
| 56 | } |
| 57 | |
| 58 | return mods[0], nil |
| 59 | } |
| 60 | |
| 61 | // Modules return the list of modules which satisfies the requested interface. |
| 62 | // |