Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sampleconfig: Use embed with external files. #3185

Merged
merged 1 commit into from
Sep 19, 2023

Conversation

davecgh
Copy link
Member

@davecgh davecgh commented Sep 17, 2023

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.

Copy link
Member

@jholdstock jholdstock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice improvement. README can be updated.

Package sampleconfig provides a single function that returns the contents of the sample configuration file for dcrd.

@davecgh
Copy link
Member Author

davecgh commented Sep 18, 2023

Nice improvement. README can be updated.

Nice catch. It was previously updated because there was only intended to be a single function, but alas, since the dcrctl bits were missed there are now multiple. Updated.

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.
@davecgh davecgh merged commit a20782d into decred:master Sep 19, 2023
2 checks passed
@davecgh davecgh deleted the embed_sample_configs branch September 19, 2023 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants