mirror of
https://github.com/lightninglabs/lightning-terminal.git
synced 2026-08-13 12:33:36 +02:00
config: introduce the concept of DevConfig
In this commit, we introduce a DevConfig struct which is embedded in the main lit Config struct. It is defined in two separate files that are made mutually exclusive using the `dev` build tag. The idea of this struct is that it allows us to expose additional config options to LiT if we build in a development environment such as our itests. In other words, we will be able to start developing features and testing them before making them available to users via the production build. As of this commit, both implementations of the struct are the same.
This commit is contained in:
parent
a06bade973
commit
7a091fc773
4 changed files with 87 additions and 2 deletions
|
|
@ -11,6 +11,7 @@ run:
|
|||
- watchtowerrpc
|
||||
- neutrinorpc
|
||||
- peersrpc
|
||||
- dev
|
||||
|
||||
linters-settings:
|
||||
govet:
|
||||
|
|
|
|||
17
config.go
17
config.go
|
|
@ -237,6 +237,13 @@ type Config struct {
|
|||
// over an in-memory connection on startup. This is only set in
|
||||
// integrated lnd mode.
|
||||
lndAdminMacaroon []byte
|
||||
|
||||
// DevConfig is a config struct that is empty if lit is built without
|
||||
// the `dev` flag (in other words when it is build for a production
|
||||
// environment). This allows us to have config values that are then
|
||||
// only available in development mode which lets us run itests against
|
||||
// features not yet available in production.
|
||||
*DevConfig
|
||||
}
|
||||
|
||||
// lndConnectParams returns the connection parameters to connect to the local
|
||||
|
|
@ -337,8 +344,9 @@ func defaultConfig() *Config {
|
|||
Autopilot: &autopilotserver.Config{
|
||||
PingCadence: time.Hour,
|
||||
},
|
||||
Firewall: firewall.DefaultConfig(),
|
||||
Accounts: &accounts.Config{},
|
||||
Firewall: firewall.DefaultConfig(),
|
||||
Accounts: &accounts.Config{},
|
||||
DevConfig: defaultDevConfig(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -467,6 +475,11 @@ func loadAndValidateConfig(interceptor signal.Interceptor) (*Config, error) {
|
|||
)
|
||||
}
|
||||
|
||||
err = cfg.DevConfig.Validate(litDir, cfg.Network)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Initiate our listeners. For now, we only support listening on one
|
||||
// port at a time because we can only pass in one pre-configured RPC
|
||||
// listener into lnd.
|
||||
|
|
|
|||
38
config_dev.go
Normal file
38
config_dev.go
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
//go:build dev
|
||||
|
||||
package terminal
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/lightninglabs/lightning-terminal/accounts"
|
||||
"github.com/lightningnetwork/lnd/clock"
|
||||
)
|
||||
|
||||
// DevConfig is a struct that holds the configuration options for a development
|
||||
// environment. The purpose of this struct is to hold config options for
|
||||
// features not yet available in production. Since our itests are built with
|
||||
// the dev tag, we can test these features in our itests.
|
||||
//
|
||||
// nolint:lll
|
||||
type DevConfig struct {
|
||||
}
|
||||
|
||||
// Validate checks that all the values set in our DevConfig are valid and uses
|
||||
// the passed parameters to override any defaults if necessary.
|
||||
func (c *DevConfig) Validate(dbDir, network string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// defaultDevConfig returns a new DevConfig with default values set.
|
||||
func defaultDevConfig() *DevConfig {
|
||||
return &DevConfig{}
|
||||
}
|
||||
|
||||
// NewAccountStore creates a new account store based on the chosen database
|
||||
// backend.
|
||||
func NewAccountStore(cfg *Config, clock clock.Clock) (accounts.Store, error) {
|
||||
return accounts.NewBoltStore(
|
||||
filepath.Dir(cfg.MacaroonPath), accounts.DBFilename, clock,
|
||||
)
|
||||
}
|
||||
33
config_prod.go
Normal file
33
config_prod.go
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
//go:build !dev
|
||||
|
||||
package terminal
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/lightninglabs/lightning-terminal/accounts"
|
||||
"github.com/lightningnetwork/lnd/clock"
|
||||
)
|
||||
|
||||
// DevConfig is an empty shell struct that allows us to build without the dev
|
||||
// tag. This struct is embedded in the main Config struct, and it adds no new
|
||||
// functionality in a production build.
|
||||
type DevConfig struct{}
|
||||
|
||||
// defaultDevConfig returns an empty DevConfig struct.
|
||||
func defaultDevConfig() *DevConfig {
|
||||
return &DevConfig{}
|
||||
}
|
||||
|
||||
// Validate is a no-op function during a production build.
|
||||
func (c *DevConfig) Validate(_, _ string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewAccountStore creates a new account store using the default Bolt backend
|
||||
// since in production, this is the only backend supported currently.
|
||||
func NewAccountStore(cfg *Config, clock clock.Clock) (accounts.Store, error) {
|
||||
return accounts.NewBoltStore(
|
||||
filepath.Dir(cfg.MacaroonPath), accounts.DBFilename, clock,
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue