mirror of
https://github.com/lightninglabs/aperture.git
synced 2026-01-31 15:14:26 +01:00
aperture: add NewConfig function
Add a NewConfig func so that all pointer variables in the config object can be initialised so that we can avoid needing to do nil checks everywhere.
This commit is contained in:
11
aperture.go
11
aperture.go
@@ -181,9 +181,10 @@ func (a *Aperture) Start(errChan chan error) error {
|
||||
var err error
|
||||
|
||||
// Start the prometheus exporter.
|
||||
if err := StartPrometheusExporter(a.cfg.Prometheus); err != nil {
|
||||
return fmt.Errorf("unable to start the prometheus exporter: "+
|
||||
"%v", err)
|
||||
err = StartPrometheusExporter(a.cfg.Prometheus)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to start the prometheus "+
|
||||
"exporter: %v", err)
|
||||
}
|
||||
|
||||
// Initialize our etcd client.
|
||||
@@ -281,7 +282,7 @@ func (a *Aperture) Start(errChan chan error) error {
|
||||
// will only be reached through the onion services, which already
|
||||
// provide encryption, so running this additional HTTP server should be
|
||||
// relatively safe.
|
||||
if a.cfg.Tor != nil && (a.cfg.Tor.V2 || a.cfg.Tor.V3) {
|
||||
if a.cfg.Tor.V2 || a.cfg.Tor.V3 {
|
||||
torController, err := initTorListener(a.cfg, a.etcdClient)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -363,7 +364,7 @@ func fileExists(name string) bool {
|
||||
func getConfig() (*Config, error) {
|
||||
// Pre-parse command line flags to determine whether we've been pointed
|
||||
// to a custom config file.
|
||||
cfg := &Config{}
|
||||
cfg := NewConfig()
|
||||
if _, err := flags.Parse(cfg); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
17
config.go
17
config.go
@@ -128,10 +128,8 @@ type Config struct {
|
||||
}
|
||||
|
||||
func (c *Config) validate() error {
|
||||
if c.Authenticator != nil {
|
||||
if err := c.Authenticator.validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := c.Authenticator.validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if c.ListenAddr == "" {
|
||||
@@ -140,3 +138,14 @@ func (c *Config) validate() error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewConfig initializes a new Config variable.
|
||||
func NewConfig() *Config {
|
||||
return &Config{
|
||||
Etcd: &EtcdConfig{},
|
||||
Authenticator: &AuthConfig{},
|
||||
Tor: &TorConfig{},
|
||||
HashMail: &HashMailConfig{},
|
||||
Prometheus: &PrometheusConfig{},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,6 +163,8 @@ func setupAperture(t *testing.T) {
|
||||
MessageRate: time.Millisecond,
|
||||
MessageBurstAllowance: math.MaxUint32,
|
||||
},
|
||||
Prometheus: &PrometheusConfig{},
|
||||
Tor: &TorConfig{},
|
||||
}
|
||||
aperture := NewAperture(apertureCfg)
|
||||
errChan := make(chan error)
|
||||
|
||||
Reference in New Issue
Block a user