// LoadConfig loads configuration for a pool integrator daemon from the
// filesystem and passed command line args
LoadConfig loads configuration for a pool integrator daemon from the
filesystem and passed command line args
// LoadConfig loads configuration for a pool integrator daemon from the // filesystem and passed command line args
func LoadConfig() (*Config, error) {
	var err error
	cfg := &Config{
		Port:         DefaultPort,
		LogLevelName: "INFO",
		KeyFile:  filepath.Join(defaultDataDir, "rpc.key"),
		CertFile: filepath.Join(defaultDataDir, "rpc.cert"),
		StakepooldConfigFile: filepath.Join(dcrutil.AppDataDir("stakepoold", false), "stakepoold.conf"),
	}
	parser := flags.NewParser(cfg, flags.Default)
	_, err = parser.Parse()
	if err != nil {
		e, ok := err.(*flags.Error)
		if ok && e.Type == flags.ErrHelp {
			return nil, ErrHelpRequested
		}
		parser.WriteHelp(os.Stderr)
		return nil, errors.Wrapf(err, "error parsing arguments")
	}
	if cfg.ShowVersion {
		return nil, ErrVersionRequested
	}
	if cfg.StakepooldConfigFile != "" {
		if _, err = os.Stat(cfg.StakepooldConfigFile); os.IsNotExist(err) {
			return nil, errors.Errorf("stakepoold config file does not exist: %s",
				cfg.StakepooldConfigFile)
		}
		err = loadConfigFromStakepoold(cfg)
		if err != nil {
			return nil, errors.Wrapf(err, "error parsing config from "+
				"stakepoold.conf")
		}
		if err = hasFullConfig(cfg); err != nil {
			return nil, errors.Wrap(err, "missing config arguments after reading "+
				"config from stakepoold")
		}
	} else if err = hasFullConfig(cfg); err != nil {
		return nil, errors.Wrap(err, "missing config arguments when not reading "+
			"config from stakepoold")
	}
	logLvl, ok := slog.LevelFromString(cfg.LogLevelName)
	if !ok {
		return nil, errors.Errorf("Invalid log level name %s", cfg.LogLevelName)
	}
	cfg.LogLevel = logLvl
	return cfg, nil
}
func LoadConfig ( ) ( * Config , error ) { var err error cfg := & Config { Port : DefaultPort , LogLevelName : " " , KeyFile : filepath . Join ( defaultDataDir , " " ) , CertFile : filepath . Join ( defaultDataDir , " " ) , StakepooldConfigFile : filepath . Join ( dcrutil . AppDataDir ( " " , false ) , " " ) , } parser := flags . NewParser ( cfg , flags . Default ) _ , err = parser . Parse ( ) if err != nil { e , ok := err . ( * flags . Error ) if ok && e . Type == flags . ErrHelp { return nil , ErrHelpRequested } parser . WriteHelp ( os . Stderr ) return nil , errors . Wrapf ( err , " " ) } if cfg . ShowVersion { return nil , ErrVersionRequested } if cfg . StakepooldConfigFile != " " { if _ , err = os . Stat ( cfg . StakepooldConfigFile ) ; os . IsNotExist ( err ) { return nil , errors . Errorf ( " " , cfg . StakepooldConfigFile ) } err = loadConfigFromStakepoold ( cfg ) if err != nil { return nil , errors . Wrapf ( err , " " + " " ) } if err = hasFullConfig ( cfg ) ; err != nil { return nil , errors . Wrap ( err , " " + " " ) } } else if err = hasFullConfig ( cfg ) ; err != nil { return nil , errors . Wrap ( err , " " + " " ) } logLvl , ok := slog . LevelFromString ( cfg . LogLevelName ) if ! ok { return nil , errors . Errorf ( " " , cfg . LogLevelName ) } cfg . LogLevel = logLvl return cfg , nil }
LoadConfig loads configuration for a pool integrator daemon from the
filesystem and passed command line args
LoadConfig loads configuration for a pool integrator daemon from the filesystem and passed command line args