mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-10 02:40:11 +08:00
WIP cleanup config handling in core
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
This commit is contained in:
parent
6b72593bc0
commit
9bcf072ccb
@ -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 {
|
||||
if cfg == nil {
|
||||
cfg = new(BuildCfg)
|
||||
func IPFS(ctx context.Context, bcfg *BuildCfg) fx.Option {
|
||||
if bcfg == nil {
|
||||
bcfg = new(BuildCfg)
|
||||
}
|
||||
|
||||
bcfgOpts, cfg := bcfg.options(ctx)
|
||||
if cfg == nil {
|
||||
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())
|
||||
|
||||
Loading…
Reference in New Issue
Block a user