Skip to content
This repository has been archived by the owner on Aug 14, 2023. It is now read-only.

Commit

Permalink
added Set as a group variant of Plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
johnabass committed Oct 20, 2021
1 parent 5cca993 commit 5f3f47a
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,60 @@ func (pl Plugin) Provide() fx.Option {

return fx.Options(options...)
}

// Set describes how to load multiple plugins as a bundle and integrate each of them
// into an enclosing fx.App.
type Set struct {
// Group is the optional value group to place each plugin in this set into. If this
// field is unset, the loaded plugins are not added as components.
Group string

// Paths are the plugin paths to load.
Paths []string

// IgnoreMissingConstructors controls what happens if a symbol in the Constructors
// field is not present in any of the plugins. If this field is true, missing constructor
// symbols are silently ignored. Otherwise, missing constructor symbols will shortcircuit
// application startup with one or more errors.
IgnoreMissingConstructors bool

// Constructors are the optional exported functions from each plugin that participate
// in dependency injection. Each constructor is passed to fx.Provide.
Constructors []string

// IgnoreMissingLifecycle controls what happens if OnStart or OnStop are not symbols
// in each plugin. If this field is true and either OnStart or OnStop are not present,
// no error is raised. Otherwise, application startup is shortcircuited with one or
// more errors.
IgnoreMissingLifecycle bool

// OnStart is the optional exported function that should be called when the enclosing
// application is started.
OnStart string

// OnStop is the optional exported function that should be called when the enclosing
// application is stopped.
OnStop string
}

func (s Set) Provide() fx.Option {
var options []fx.Option
for _, path := range s.Paths {
options = append(options,
Plugin{
Group: s.Group,
Anonymous: len(s.Group) == 0,
Path: path,

IgnoreMissingConstructors: s.IgnoreMissingConstructors,
Constructors: s.Constructors,

IgnoreMissingLifecycle: s.IgnoreMissingLifecycle,
OnStart: s.OnStart,
OnStop: s.OnStop,
}.Provide(),
)
}

return fx.Options(options...)
}

0 comments on commit 5f3f47a

Please sign in to comment.