Unverified Commit ad4f02cb authored by Steven Allen's avatar Steven Allen Committed by GitHub

Merge pull request #6576 from ipfs/feat/easier-preload

feat: improve plugin preload logic
parents f455c8ba 09d51774
...@@ -15,6 +15,13 @@ import ( ...@@ -15,6 +15,13 @@ import (
opentracing "github.com/opentracing/opentracing-go" opentracing "github.com/opentracing/opentracing-go"
) )
var preloadPlugins []plugin.Plugin
// Preload adds one or more plugins to the preload list. This should _only_ be called during init.
func Preload(plugins ...plugin.Plugin) {
preloadPlugins = append(preloadPlugins, plugins...)
}
var log = logging.Logger("plugin/loader") var log = logging.Logger("plugin/loader")
var loadPluginsFunc = func(string) ([]plugin.Plugin, error) { var loadPluginsFunc = func(string) ([]plugin.Plugin, error) {
......
package loader package loader
import ( import (
"github.com/ipfs/go-ipfs/plugin"
pluginbadgerds "github.com/ipfs/go-ipfs/plugin/plugins/badgerds" pluginbadgerds "github.com/ipfs/go-ipfs/plugin/plugins/badgerds"
pluginflatfs "github.com/ipfs/go-ipfs/plugin/plugins/flatfs" pluginflatfs "github.com/ipfs/go-ipfs/plugin/plugins/flatfs"
pluginipldgit "github.com/ipfs/go-ipfs/plugin/plugins/git" pluginipldgit "github.com/ipfs/go-ipfs/plugin/plugins/git"
...@@ -12,9 +11,9 @@ import ( ...@@ -12,9 +11,9 @@ import (
// This file is being generated as part of plugin build process // This file is being generated as part of plugin build process
// To change it, modify the plugin/loader/preload.sh // To change it, modify the plugin/loader/preload.sh
var preloadPlugins = []plugin.Plugin{ func init() {
pluginipldgit.Plugins[0], Preload(pluginipldgit.Plugins...)
pluginbadgerds.Plugins[0], Preload(pluginbadgerds.Plugins...)
pluginflatfs.Plugins[0], Preload(pluginflatfs.Plugins...)
pluginlevelds.Plugins[0], Preload(pluginlevelds.Plugins...)
} }
...@@ -10,7 +10,6 @@ cat <<EOL ...@@ -10,7 +10,6 @@ cat <<EOL
package loader package loader
import ( import (
"github.com/ipfs/go-ipfs/plugin"
EOL EOL
to_preload | while read -r name path num; do to_preload | while read -r name path num; do
...@@ -25,12 +24,14 @@ cat <<EOL ...@@ -25,12 +24,14 @@ cat <<EOL
// This file is being generated as part of plugin build process // This file is being generated as part of plugin build process
// To change it, modify the plugin/loader/preload.sh // To change it, modify the plugin/loader/preload.sh
var preloadPlugins = []plugin.Plugin{ func init() {
EOL EOL
to_preload | while read -r name path num; do to_preload | while read -r name path num; do
echo "plugin$name.Plugins[$num]," case "$num" in
'*') echo " Preload(plugin$name.Plugins...)" ;; # All plugins
*) echo " Preload(plugin$name.Plugins[$num])" ;; # A specific plugin
esac
done done
echo "}" echo "}"
# this file contains plugins to be preloaded # this file contains plugins to be preloaded
# empty lines or starting with '#' are ignored # empty lines or starting with '#' are ignored
# #
# name go-path number of the sub-plugin # name go-path number of the sub-plugin or *
ipldgit github.com/ipfs/go-ipfs/plugin/plugins/git 0 ipldgit github.com/ipfs/go-ipfs/plugin/plugins/git *
badgerds github.com/ipfs/go-ipfs/plugin/plugins/badgerds 0 badgerds github.com/ipfs/go-ipfs/plugin/plugins/badgerds *
flatfs github.com/ipfs/go-ipfs/plugin/plugins/flatfs 0 flatfs github.com/ipfs/go-ipfs/plugin/plugins/flatfs *
levelds github.com/ipfs/go-ipfs/plugin/plugins/levelds 0 levelds github.com/ipfs/go-ipfs/plugin/plugins/levelds *
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment