提交 9bcf072c 作者: Łukasz Magiera

WIP cleanup config handling in core

License: MIT
Signed-off-by: 's avatarŁukasz Magiera <magik6k@gmail.com>
上级 6b72593b
......@@ -84,10 +84,10 @@ func (cfg *BuildCfg) fillDefaults() error {
}
// options creates fx option group from this build config
func (cfg *BuildCfg) options(ctx context.Context) fx.Option {
func (cfg *BuildCfg) options(ctx context.Context) (fx.Option, *cfg.Config) {
err := cfg.fillDefaults()
if err != nil {
return fx.Error(err)
return fx.Error(err), nil
}
repoOption := fx.Provide(func(lc fx.Lifecycle) repo.Repo {
......@@ -112,12 +112,17 @@ func (cfg *BuildCfg) options(ctx context.Context) fx.Option {
return cfg.Routing
})
conf, err := cfg.Repo.Config()
if err != nil {
return fx.Error(err), nil
}
return fx.Options(
repoOption,
hostOption,
routingOption,
metricsCtx,
)
), conf
}
func defaultRepo(dstore repo.Datastore) (repo.Repo, error) {
......
......@@ -9,6 +9,7 @@ import (
offline "github.com/ipfs/go-ipfs-exchange-offline"
offroute "github.com/ipfs/go-ipfs-routing/offline"
uio "github.com/ipfs/go-unixfs/io"
"github.com/ipfs/go-path/resolver"
"go.uber.org/fx"
)
......@@ -122,21 +123,33 @@ func Networked(cfg *BuildCfg) fx.Option {
}
// IPFS builds a group of fx Options based on the passed BuildCfg
func IPFS(ctx context.Context, cfg *BuildCfg) fx.Option {
func IPFS(ctx context.Context, bcfg *BuildCfg) fx.Option {
if bcfg == nil {
bcfg = new(BuildCfg)
}
bcfgOpts, cfg := bcfg.options(ctx)
if cfg == nil {
cfg = new(BuildCfg)
return bcfgOpts // error
}
// TEMP: setting global sharding switch here
uio.UseHAMTSharding = cfg.Experimental.ShardingEnabled
return fx.Options(
cfg.options(ctx),
bcfgOpts,
fx.Provide(baseProcess),
fx.Invoke(setupSharding),
Storage(cfg),
Storage(bcfg),
Identity,
IPNS,
Networked(cfg),
Networked(bcfg),
Core,
)
......
......@@ -3,8 +3,6 @@ package node
import (
"context"
config "github.com/ipfs/go-ipfs-config"
uio "github.com/ipfs/go-unixfs/io"
"github.com/jbenet/goprocess"
"github.com/pkg/errors"
"go.uber.org/fx"
......@@ -45,11 +43,6 @@ func maybeProvide(opt interface{}, enable bool) fx.Option {
return fx.Options()
}
func setupSharding(cfg *config.Config) {
// TEMP: setting global sharding switch here
uio.UseHAMTSharding = cfg.Experimental.ShardingEnabled
}
// baseProcess creates a goprocess which is closed when the lifecycle signals it to stop
func baseProcess(lc fx.Lifecycle) goprocess.Process {
p := goprocess.WithParent(goprocess.Background())
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论