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

Embedding default configurations in released binary #18

Open
bhayes-zd opened this issue May 12, 2021 · 1 comment
Open

Embedding default configurations in released binary #18

bhayes-zd opened this issue May 12, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@bhayes-zd
Copy link

Hey there 👋 Love the project and thanks for all your work here!

Suggestion

For all files in the config/ directory, I think this is a perfect use case to embed your configurations in the binary utilizing go:embed.

This would essentially alleviate the requirement for users to install the repository locally to setup the go-earlybird project using your shell scripts because the binary would already have the configs packaged in via embed.FS rather than reading the user's local filesystem for the baseline configs. This then opens up the door for you to distribute an easily packagable go get command, brew install or whatever package manager user's would like because everything they need is right there in the executable.

This could be the default and then allow users to provide additional configs if they choose to by reading the ~/.go-earlybird/foo directory. As mentioned here in your utils.go

Specifics

Referenced Earlybird Config Directory
Additional documentation on embed.FS

So right here where you are reading in the config with an os.Open, if you switch this to use the new embed.FS, you'll get this end result.

Current

//LoadConfig parses json configuration file into structure
func LoadConfig(cfg interface{}, path string) (err error) {

	jsonFile, err := os.Open(path)
	// if we os.Open returns an error then handle it
	if err != nil {
		return err
	}
...

Proposed Change

+ //go:embed config/
+var embeddedConfig embed.FS

//LoadConfig parses json configuration file into structure
func LoadConfig(cfg interface{}, path string) (err error) {

+	jsonFile, err := embeddedConfig.Open(path)
	// if we embeddedConfig.Open returns an error then handle it
	if err != nil {
		return err
	}
...
@grinish21 grinish21 added the enhancement New feature or request label May 12, 2021
@grinish21
Copy link
Member

Great Suggestion @bhayes-zd Will definitely explore this and get back to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants