New creates a stub with the given plugin and options. ManualLaunchOption only apply when the plugin is launched manually. If launched by the secrets runtime, they are ignored. If logger is nil, a default logger will be created and used.
(p ExternalPlugin, config Config, opts ...ManualLaunchOption)
| 63 | // If launched by the secrets runtime, they are ignored. |
| 64 | // If logger is nil, a default logger will be created and used. |
| 65 | func New(p ExternalPlugin, config Config, opts ...ManualLaunchOption) (Stub, error) { |
| 66 | if err := config.Valid(); err != nil { |
| 67 | return nil, err |
| 68 | } |
| 69 | if config.Logger == nil { |
| 70 | config.Logger = logging.NewDefaultLogger("plugin") |
| 71 | } |
| 72 | cfg, err := newCfg(p, opts...) |
| 73 | if err != nil { |
| 74 | return nil, err |
| 75 | } |
| 76 | cfg.Config = config |
| 77 | stub := &stub{ |
| 78 | name: cfg.name, |
| 79 | factory: func(ctx context.Context, onClose func(error)) (io.Closer, error) { |
| 80 | return setup(ctx, *cfg, onClose) |
| 81 | }, |
| 82 | } |
| 83 | config.Logger.Printf("Created plugin %s", cfg.name) |
| 84 | |
| 85 | return stub, nil |
| 86 | } |
| 87 | |
| 88 | // Run the plugin. Start event processing then wait for an error or getting stopped. |
| 89 | func (stub *stub) Run(ctx context.Context) error { |