github.com/decred/dcrlnd@v0.7.6/kvdb/etcd/config.go (about)

     1  package etcd
     2  
     3  import "fmt"
     4  
     5  // Config holds etcd configuration alongside with configuration related to our higher level interface.
     6  type Config struct {
     7  	Embedded bool `long:"embedded" description:"Use embedded etcd instance instead of the external one. Note: use for testing only."`
     8  
     9  	EmbeddedClientPort uint16 `long:"embedded_client_port" description:"Client port to use for the embedded instance. Note: use for testing only."`
    10  
    11  	EmbeddedPeerPort uint16 `long:"embedded_peer_port" description:"Peer port to use for the embedded instance. Note: use for testing only."`
    12  
    13  	EmbeddedLogFile string `long:"embedded_log_file" description:"Optional log file to use for embedded instance logs. note: use for testing only."`
    14  
    15  	Host string `long:"host" description:"Etcd database host."`
    16  
    17  	User string `long:"user" description:"Etcd database user."`
    18  
    19  	Pass string `long:"pass" description:"Password for the database user."`
    20  
    21  	Namespace string `long:"namespace" description:"The etcd namespace to use."`
    22  
    23  	DisableTLS bool `long:"disabletls" description:"Disable TLS for etcd connection. Caution: use for development only."`
    24  
    25  	CertFile string `long:"cert_file" description:"Path to the TLS certificate for etcd RPC."`
    26  
    27  	KeyFile string `long:"key_file" description:"Path to the TLS private key for etcd RPC."`
    28  
    29  	InsecureSkipVerify bool `long:"insecure_skip_verify" description:"Whether we intend to skip TLS verification"`
    30  
    31  	CollectStats bool `long:"collect_stats" description:"Whether to collect etcd commit stats."`
    32  
    33  	MaxMsgSize int `long:"max_msg_size" description:"The maximum message size in bytes that we may send to etcd."`
    34  
    35  	// SingleWriter should be set to true if we intend to only allow a
    36  	// single writer to the database at a time.
    37  	SingleWriter bool
    38  }
    39  
    40  // CloneWithSubNamespace clones the current configuration and returns a new
    41  // instance with the given sub namespace applied by appending it to the main
    42  // namespace.
    43  func (c *Config) CloneWithSubNamespace(subNamespace string) *Config {
    44  	ns := c.Namespace
    45  	if len(ns) == 0 {
    46  		ns = subNamespace
    47  	} else {
    48  		ns = fmt.Sprintf("%s/%s", ns, subNamespace)
    49  	}
    50  
    51  	return &Config{
    52  		Embedded:           c.Embedded,
    53  		EmbeddedClientPort: c.EmbeddedClientPort,
    54  		EmbeddedPeerPort:   c.EmbeddedPeerPort,
    55  		Host:               c.Host,
    56  		User:               c.User,
    57  		Pass:               c.Pass,
    58  		Namespace:          ns,
    59  		DisableTLS:         c.DisableTLS,
    60  		CertFile:           c.CertFile,
    61  		KeyFile:            c.KeyFile,
    62  		InsecureSkipVerify: c.InsecureSkipVerify,
    63  		CollectStats:       c.CollectStats,
    64  		SingleWriter:       c.SingleWriter,
    65  	}
    66  }
    67  
    68  // CloneWithSingleWriter clones the current configuration and returns a new
    69  // instance with the single writer property set to true.
    70  func (c *Config) CloneWithSingleWriter() *Config {
    71  	return &Config{
    72  		Embedded:           c.Embedded,
    73  		EmbeddedClientPort: c.EmbeddedClientPort,
    74  		EmbeddedPeerPort:   c.EmbeddedPeerPort,
    75  		Host:               c.Host,
    76  		User:               c.User,
    77  		Pass:               c.Pass,
    78  		Namespace:          c.Namespace,
    79  		DisableTLS:         c.DisableTLS,
    80  		CertFile:           c.CertFile,
    81  		KeyFile:            c.KeyFile,
    82  		InsecureSkipVerify: c.InsecureSkipVerify,
    83  		CollectStats:       c.CollectStats,
    84  		SingleWriter:       true,
    85  	}
    86  }