Skip to content

Commit

Permalink
sampleconfig: Use embed with external files.
Browse files Browse the repository at this point in the history
This updates the sampleconfig package to make use of Go's embed
functionality introduced in Go 1.16 which is acceptable since the
containing module requires Go 1.19.

Embedded files are preferable because they bring the benefits of both
external files in the repository that are easier to work with for
external tools and the ability to access their content programmatically
without having to deal with the various issues typically brought about
by programmatically accessing external files.

Also, when this was last updated to change the exported variable for
dcrd's sample config file over to a function (so it can't be mutated and
the implementation details can be changed if needed), the case for
dcrctl was missed.  Moreover, the existence of both configs makes the
func name FileContents ambiguous.

Unfortunately, those things can't be changed now without causing a major
module version bump to the main dcrd module which we really want to
avoid.

So, in order to address those things without needing a major module
version bump, this deprecates the FileContents func and
DcrctlSampleConfig variable and introduces two new functions named Dcrd
and Dcrctl that return the respective embedded sample configs.
  • Loading branch information
davecgh committed Sep 18, 2023
1 parent 5204b35 commit e55f072
Show file tree
Hide file tree
Showing 5 changed files with 424 additions and 397 deletions.
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ func createDefaultConfigFile(destPath string, authType string) error {
return err
}

cfg := sampleconfig.FileContents()
cfg := sampleconfig.Dcrd()

// Set a randomized rpcuser and rpcpass if the authorization type is basic.
if authType == authTypeBasic {
Expand Down
10 changes: 5 additions & 5 deletions sampleconfig/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ sampleconfig
[![ISC License](https://img.shields.io/badge/license-ISC-blue.svg)](http://copyfree.org)
[![Doc](https://img.shields.io/badge/doc-reference-blue.svg)](https://pkg.go.dev/github.com/decred/dcrd/sampleconfig)

Package sampleconfig provides a single function that returns the contents of
the sample configuration file for dcrd. This is provided for tools that perform
automatic configuration and would like to ensure the generated configuration
file not only includes the specifically configured values, but also provides
samples of other configuration options.
Package sampleconfig provides functions that return the contents of sample
configuration files for dcrd and dcrctl. This is provided for tools that
perform automatic configuration and would like to ensure the generated
configuration files not only includes the specifically configured values, but
also provides samples of other configuration options.

## Installation and Updating

Expand Down
39 changes: 39 additions & 0 deletions sampleconfig/sample-dcrctl.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[Application Options]

; ------------------------------------------------------------------------------
; Network settings
; ------------------------------------------------------------------------------

; Use testnet (cannot be used with simnet=1).
; testnet=1

; Use simnet (cannot be used with testnet=1).
; simnet=1

; The duration of inactivity before a peer is timed out.
; Valid time units are {s,m,h}. Minimum 15 seconds.
; peeridletimeout=120s


; ------------------------------------------------------------------------------
; RPC client settings
; ------------------------------------------------------------------------------

; Connect via a SOCKS5 proxy.
; proxy=127.0.0.1:9050
; proxyuser=
; proxypass=

; Username and password to authenticate connections to a Decred RPC server
; (usually dcrd or dcrwallet)
; rpcuser=
; rpcpass=

; RPC server to connect to
; rpcserver=localhost

; Wallet RPC server to connect to
; walletrpcserver=localhost

; RPC server certificate chain file for validation
; rpccert=~/.dcrd/rpc.cert
Loading

0 comments on commit e55f072

Please sign in to comment.