Add config migration to plugin package
Add reset registrations function to plugin package Signed-off-by: Derek McGowan <derek@mcg.dev>
This commit is contained in:
parent
f58158e2d3
commit
0320ad1843
@ -17,6 +17,7 @@
|
|||||||
package plugin
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
@ -116,6 +117,15 @@ type Registration struct {
|
|||||||
InitFn func(*InitContext) (interface{}, error)
|
InitFn func(*InitContext) (interface{}, error)
|
||||||
// Disable the plugin from loading
|
// Disable the plugin from loading
|
||||||
Disable bool
|
Disable bool
|
||||||
|
|
||||||
|
// ConfigMigration allows a plugin to migrate configurations from an older
|
||||||
|
// version to handle plugin renames or moving of features from one plugin
|
||||||
|
// to another in a later version.
|
||||||
|
// The configuration map is keyed off the plugin name and the value
|
||||||
|
// is the configuration for that objects, with the structure defined
|
||||||
|
// for the plugin. No validation is done on the value before performing
|
||||||
|
// the migration.
|
||||||
|
ConfigMigration func(context.Context, int, map[string]interface{}) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init the registered plugin
|
// Init the registered plugin
|
||||||
@ -182,6 +192,13 @@ func Register(r *Registration) {
|
|||||||
register.r = append(register.r, r)
|
register.r = append(register.r, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reset removes all global registrations
|
||||||
|
func Reset() {
|
||||||
|
register.Lock()
|
||||||
|
defer register.Unlock()
|
||||||
|
register.r = nil
|
||||||
|
}
|
||||||
|
|
||||||
func checkUnique(r *Registration) error {
|
func checkUnique(r *Registration) error {
|
||||||
for _, registered := range register.r {
|
for _, registered := range register.r {
|
||||||
if r.URI() == registered.URI() {
|
if r.URI() == registered.URI() {
|
||||||
|
Loading…
Reference in New Issue
Block a user