Skip to content

Commit

Permalink
feat(plugins): add a bit of documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Stebalien committed Jun 28, 2019
1 parent 4badef2 commit 4bbe007
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ require (
go4.org v0.0.0-20190313082347-94abd6928b1d // indirect
golang.org/x/sync v0.0.0-20190423024810-112230192c58 // indirect
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb
google.golang.org/appengine v1.4.0 // indirect
gopkg.in/cheggaaa/pb.v1 v1.0.28
gotest.tools/gotestsum v0.3.4
)
Expand Down
12 changes: 11 additions & 1 deletion plugin/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,15 @@ func (ls loaderState) String() string {
}
}

// PluginLoader keeps track of loaded plugins
// PluginLoader keeps track of loaded plugins.
//
// To use:
// 1. Load any desired plugins with Load and LoadDirectory. Preloaded plugins
// will automatically be loaded.
// 2. Call Initialize to run all initialization logic.
// 3. Call Inject to register the plugins.
// 4. Optionally call Start to start plugins.
// 5. Call Close to close all plugins.
type PluginLoader struct {
state loaderState
plugins map[string]plugin.Plugin
Expand Down Expand Up @@ -96,6 +104,7 @@ func (loader *PluginLoader) transition(from, to loaderState) error {
return nil
}

// Load loads a plugin into the plugin loader.
func (loader *PluginLoader) Load(pl plugin.Plugin) error {
if err := loader.assertState(loaderLoading); err != nil {
return err
Expand All @@ -113,6 +122,7 @@ func (loader *PluginLoader) Load(pl plugin.Plugin) error {
return nil
}

// LoadDirectory loads a directory of plugins into the plugin loader.
func (loader *PluginLoader) LoadDirectory(pluginDir string) error {
if err := loader.assertState(loaderLoading); err != nil {
return err
Expand Down

0 comments on commit 4bbe007

Please sign in to comment.