Skip to content

Commit dcba353

Browse files
committed
Add config migration to plugin package
Add reset registrations function to plugin package Signed-off-by: Derek McGowan <derek@mcg.dev>
1 parent 189ccdb commit dcba353

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

plugin.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package plugin
1818

1919
import (
20+
"context"
2021
"errors"
2122
"fmt"
2223
"sync"
@@ -116,6 +117,15 @@ type Registration struct {
116117
InitFn func(*InitContext) (interface{}, error)
117118
// Disable the plugin from loading
118119
Disable bool
120+
121+
// ConfigMigration allows a plugin to migrate configurations from an older
122+
// version to handle plugin renames or moving of features from one plugin
123+
// to another in a later version.
124+
// The configuration map is keyed off the plugin name and the value
125+
// is the configuration for that objects, with the structure defined
126+
// for the plugin. No validation is done on the value before performing
127+
// the migration.
128+
ConfigMigration func(context.Context, int, map[string]interface{}) error
119129
}
120130

121131
// Init the registered plugin
@@ -182,6 +192,13 @@ func Register(r *Registration) {
182192
register.r = append(register.r, r)
183193
}
184194

195+
// Reset removes all global registrations
196+
func Reset() {
197+
register.Lock()
198+
defer register.Unlock()
199+
register.r = nil
200+
}
201+
185202
func checkUnique(r *Registration) error {
186203
for _, registered := range register.r {
187204
if r.URI() == registered.URI() {

0 commit comments

Comments
 (0)