mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 18:37:45 +08:00
* chore: apply go fix modernizers from Go 1.26
automated refactoring: interface{} to any, slices.Contains,
and other idiomatic updates.
* feat(ci): add `go fix` check to Go analysis workflow
ensures Go 1.26 modernizers are applied, fails CI if `go fix ./...`
produces any changes (similar to existing `go fmt` enforcement)
91 lines
1.9 KiB
Go
91 lines
1.9 KiB
Go
package flatfs
|
|
|
|
import (
|
|
"fmt"
|
|
"path/filepath"
|
|
|
|
"github.com/ipfs/kubo/plugin"
|
|
"github.com/ipfs/kubo/repo"
|
|
"github.com/ipfs/kubo/repo/fsrepo"
|
|
|
|
flatfs "github.com/ipfs/go-ds-flatfs"
|
|
)
|
|
|
|
// Plugins is exported list of plugins that will be loaded.
|
|
var Plugins = []plugin.Plugin{
|
|
&flatfsPlugin{},
|
|
}
|
|
|
|
type flatfsPlugin struct{}
|
|
|
|
var _ plugin.PluginDatastore = (*flatfsPlugin)(nil)
|
|
|
|
func (*flatfsPlugin) Name() string {
|
|
return "ds-flatfs"
|
|
}
|
|
|
|
func (*flatfsPlugin) Version() string {
|
|
return "0.1.0"
|
|
}
|
|
|
|
func (*flatfsPlugin) Init(_ *plugin.Environment) error {
|
|
return nil
|
|
}
|
|
|
|
func (*flatfsPlugin) DatastoreTypeName() string {
|
|
return "flatfs"
|
|
}
|
|
|
|
type datastoreConfig struct {
|
|
path string
|
|
shardFun *flatfs.ShardIdV1
|
|
syncField bool
|
|
}
|
|
|
|
// DatastoreConfigParser returns a configuration stub for a flatfs datastore
|
|
// from the given parameters.
|
|
func (*flatfsPlugin) DatastoreConfigParser() fsrepo.ConfigFromMap {
|
|
return func(params map[string]any) (fsrepo.DatastoreConfig, error) {
|
|
var c datastoreConfig
|
|
var ok bool
|
|
var err error
|
|
|
|
c.path, ok = params["path"].(string)
|
|
if !ok {
|
|
return nil, fmt.Errorf("'path' field is missing or not boolean")
|
|
}
|
|
|
|
sshardFun, ok := params["shardFunc"].(string)
|
|
if !ok {
|
|
return nil, fmt.Errorf("'shardFunc' field is missing or not a string")
|
|
}
|
|
c.shardFun, err = flatfs.ParseShardFunc(sshardFun)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
c.syncField, ok = params["sync"].(bool)
|
|
if !ok {
|
|
return nil, fmt.Errorf("'sync' field is missing or not boolean")
|
|
}
|
|
return &c, nil
|
|
}
|
|
}
|
|
|
|
func (c *datastoreConfig) DiskSpec() fsrepo.DiskSpec {
|
|
return map[string]any{
|
|
"type": "flatfs",
|
|
"path": c.path,
|
|
"shardFunc": c.shardFun.String(),
|
|
}
|
|
}
|
|
|
|
func (c *datastoreConfig) Create(path string) (repo.Datastore, error) {
|
|
p := c.path
|
|
if !filepath.IsAbs(p) {
|
|
p = filepath.Join(path, p)
|
|
}
|
|
|
|
return flatfs.CreateOrOpen(p, c.shardFun, c.syncField)
|
|
}
|