Use ParseDurations when applying json to cluster Config

License: MIT
Signed-off-by: Robert Ignat <robert.ignat91@gmail.com>
This commit is contained in:
Robert Ignat 2019-02-11 15:56:46 +02:00
parent da58eae2c9
commit 15ac8cd79b

View File

@ -322,14 +322,6 @@ for more information.`)
} }
func (cfg *Config) applyConfigJSON(jcfg *configJSON) error { func (cfg *Config) applyConfigJSON(jcfg *configJSON) error {
parseDuration := func(txt string) time.Duration {
d, _ := time.ParseDuration(txt)
if txt != "" && d == 0 {
logger.Warningf("%s is not a valid duration. Default will be used", txt)
}
return d
}
config.SetIfNotDefault(jcfg.PeerstoreFile, &cfg.PeerstoreFile) config.SetIfNotDefault(jcfg.PeerstoreFile, &cfg.PeerstoreFile)
id, err := peer.IDB58Decode(jcfg.ID) id, err := peer.IDB58Decode(jcfg.ID)
@ -376,15 +368,15 @@ func (cfg *Config) applyConfigJSON(jcfg *configJSON) error {
config.SetIfNotDefault(rplMin, &cfg.ReplicationFactorMin) config.SetIfNotDefault(rplMin, &cfg.ReplicationFactorMin)
config.SetIfNotDefault(rplMax, &cfg.ReplicationFactorMax) config.SetIfNotDefault(rplMax, &cfg.ReplicationFactorMax)
stateSyncInterval := parseDuration(jcfg.StateSyncInterval) err = config.ParseDurations("cluster",
ipfsSyncInterval := parseDuration(jcfg.IPFSSyncInterval) &config.DurationOpt{Duration: jcfg.StateSyncInterval, Dst: &cfg.StateSyncInterval, Name: "state_sync_interval"},
monitorPingInterval := parseDuration(jcfg.MonitorPingInterval) &config.DurationOpt{Duration: jcfg.IPFSSyncInterval, Dst: &cfg.IPFSSyncInterval, Name: "ipfs_sync_interval"},
peerWatchInterval := parseDuration(jcfg.PeerWatchInterval) &config.DurationOpt{Duration: jcfg.MonitorPingInterval, Dst: &cfg.MonitorPingInterval, Name: "monitor_ping_interval"},
&config.DurationOpt{Duration: jcfg.PeerWatchInterval, Dst: &cfg.PeerWatchInterval, Name: "peer_watch_interval"},
config.SetIfNotDefault(stateSyncInterval, &cfg.StateSyncInterval) )
config.SetIfNotDefault(ipfsSyncInterval, &cfg.IPFSSyncInterval) if err != nil {
config.SetIfNotDefault(monitorPingInterval, &cfg.MonitorPingInterval) return err
config.SetIfNotDefault(peerWatchInterval, &cfg.PeerWatchInterval) }
cfg.LeaveOnShutdown = jcfg.LeaveOnShutdown cfg.LeaveOnShutdown = jcfg.LeaveOnShutdown
cfg.DisableRepinning = jcfg.DisableRepinning cfg.DisableRepinning = jcfg.DisableRepinning