loadModule calls the Provision and/or Validate methods of the requested module if it satisfies the [Provisioner] and/or [Validator] interfaces.
(id string, instance any)
| 102 | // loadModule calls the Provision and/or Validate methods of the requested |
| 103 | // module if it satisfies the [Provisioner] and/or [Validator] interfaces. |
| 104 | func (ctx *Context) loadModule(id string, instance any) error { |
| 105 | if prov, ok := instance.(Provisioner); ok { |
| 106 | // The instance can be provisioned. |
| 107 | err := prov.Provision(ctx) |
| 108 | if err != nil { |
| 109 | return fmt.Errorf("provision module %s: %w", id, err) |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | if validator, ok := instance.(Validator); ok { |
| 114 | // The instance can be validated. |
| 115 | err := validator.Validate() |
| 116 | if err != nil { |
| 117 | return fmt.Errorf("validate module %s: %w", id, err) |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | ctx.moduleInstances[id] = instance |
| 122 | |
| 123 | return nil |
| 124 | } |