package database import ( "context" "encoding/json" "fmt" "os" "path/filepath" files "github.com/ipfs/go-ipfs-files" "github.com/ipfs/go-ipfs/core" "github.com/ipfs/go-ipfs/core/coreapi" "github.com/ipfs/go-ipfs/core/node/libp2p" "github.com/ipfs/go-ipfs/plugin/loader" "github.com/ipfs/go-ipfs/repo/fsrepo" icore "github.com/ipfs/interface-go-ipfs-core" ) func setupPlugins(path string) error { plugins, err := loader.NewPluginLoader(filepath.Join(path, "plugins")) if err != nil { return fmt.Errorf("error loading plugins: %s", err) } if err := plugins.Initialize(); err != nil { return fmt.Errorf("error initializing plugins: %s", err) } if err := plugins.Inject(); err != nil { return fmt.Errorf("error initializing plugins: %s", err) } return nil } func createNode(ctx context.Context, repoPath string) (icore.CoreAPI, error) { repo, err := fsrepo.Open(repoPath) if err != nil { return nil, err } nodeOptions := &core.BuildCfg{ Online: true, Routing: libp2p.DHTOption, Repo: repo, ExtraOpts: map[string]bool{ "pubsub": true, }, } node, err := core.NewNode(ctx, nodeOptions) if err != nil { return nil, err } // Attach the Core API to the constructed node return coreapi.NewCoreAPI(node) } func getUnixfsNode(path string) (files.Node, error) { st, err := os.Stat(path) if err != nil { return nil, err } f, err := files.NewSerialFile(path, false, st) if err != nil { return nil, err } return f, nil } func structToMap(v interface{}) (map[string]interface{}) { var vMap map[string]interface{} data, _ := json.Marshal(v) json.Unmarshal(data, &vMap) return vMap }