// LoadConfig loads the daemon config from the local config file.
LoadConfig loads the daemon config from the local config file.
// LoadConfig loads the daemon config from the local config file .
func LoadConfig() (*Config, error) {
	var err error
	preCfg := &Config{
		ConfigFile: defaultCfgFilePath,
	}
	preParser := flags.NewParser(preCfg, flags.Default)
	_, err = preParser.Parse()
	if err != nil {
		e, ok := err.(*flags.Error)
		if ok && e.Type == flags.ErrHelp {
			return nil, ErrHelpRequested
		}
		preParser.WriteHelp(os.Stderr)
		return nil, errors.Wrapf(err, "error parsing arguments")
	}
	if preCfg.ShowVersion {
		return nil, ErrVersionRequested
	}
	configFilePath := preCfg.ConfigFile
	cfg := &Config{
		Port:         8475,
		MinAmount:    2.0,
		LogLevel:     slog.LevelInfo,
		LogLevelName: slog.LevelInfo.String(),
		LogDir:       filepath.Join(defaultDataDir, "logs"),
		DataDir:      defaultDataDir,
		KeyFile:  filepath.Join(defaultDataDir, "rpc.key"),
		CertFile: filepath.Join(defaultDataDir, "rpc.cert"),
		DcrdHost: "localhost:19109",
		DcrdUser: "USER",
		DcrdPass: "PASSWORD",
		DcrdCert: filepath.Join(dcrutil.AppDataDir("dcrd", false), "rpc.cert"),
		DcrwHost: "localhost:19110",
		DcrwUser: "USER",
		DcrwPass: "PASSWORD",
		DcrwCert: filepath.Join(dcrutil.AppDataDir("dcrwallet", false), "rpc.cert"),
		MaxSessionDuration:          30 * time.Second,
		StakeDiffChangeStopWindow:   5,
		PublishTransactions:         false,
		AllowPublicSession:          false,
		ValidateVoteAddressOnWallet: false,
		PoolSubsidyWalletMasterPub:  "",
		PoolFee:                     splitticket.MaxPoolFeeRateMainnet,
		KeepAliveTime:    60 * time.Second,
		KeepAliveTimeout: 5 * time.Second,
	}
	parser := flags.NewParser(cfg, flags.Default)
	err = flags.NewIniParser(parser).ParseFile(configFilePath)
	if err != nil {
		return nil, err
	}
	_, err = parser.Parse()
	if err != nil {
		return nil, err
	}
	logLvl, ok := slog.LevelFromString(cfg.LogLevelName)
	if !ok {
		return nil, errors.Errorf("Uknown log level: %s", cfg.LogLevelName)
	}
	cfg.LogLevel = logLvl
	return cfg, nil
}
func LoadConfig ( ) ( * Config , error ) { var err error preCfg := & Config { ConfigFile : defaultCfgFilePath , } preParser := flags . NewParser ( preCfg , flags . Default ) _ , err = preParser . Parse ( ) if err != nil { e , ok := err . ( * flags . Error ) if ok && e . Type == flags . ErrHelp { return nil , ErrHelpRequested } preParser . WriteHelp ( os . Stderr ) return nil , errors . Wrapf ( err , " " ) } if preCfg . ShowVersion { return nil , ErrVersionRequested } configFilePath := preCfg . ConfigFile cfg := & Config { Port : 8475 , MinAmount : 2.0 , LogLevel : slog . LevelInfo , LogLevelName : slog . LevelInfo . String ( ) , LogDir : filepath . Join ( defaultDataDir , " " ) , DataDir : defaultDataDir , KeyFile : filepath . Join ( defaultDataDir , " " ) , CertFile : filepath . Join ( defaultDataDir , " " ) , DcrdHost : " " , DcrdUser : " " , DcrdPass : " " , DcrdCert : filepath . Join ( dcrutil . AppDataDir ( " " , false ) , " " ) , DcrwHost : " " , DcrwUser : " " , DcrwPass : " " , DcrwCert : filepath . Join ( dcrutil . AppDataDir ( " " , false ) , " " ) , MaxSessionDuration : 30 * time . Second , StakeDiffChangeStopWindow : 5 , PublishTransactions : false , AllowPublicSession : false , ValidateVoteAddressOnWallet : false , PoolSubsidyWalletMasterPub : " " , PoolFee : splitticket . MaxPoolFeeRateMainnet , KeepAliveTime : 60 * time . Second , KeepAliveTimeout : 5 * time . Second , } parser := flags . NewParser ( cfg , flags . Default ) err = flags . NewIniParser ( parser ) . ParseFile ( configFilePath ) if err != nil { return nil , err } _ , err = parser . Parse ( ) if err != nil { return nil , err } logLvl , ok := slog . LevelFromString ( cfg . LogLevelName ) if ! ok { return nil , errors . Errorf ( " " , cfg . LogLevelName ) } cfg . LogLevel = logLvl return cfg , nil }
LoadConfig loads the daemon config from the local config file.
LoadConfig loads the daemon config from the local config file .