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

🍀 Proposal: Use embed to read the default config #603

Closed
iyear opened this issue May 25, 2022 · 5 comments
Closed

🍀 Proposal: Use embed to read the default config #603

iyear opened this issue May 25, 2022 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@iyear
Copy link
Member

iyear commented May 25, 2022

What Would You Like to Add? Why is This Needed?

In internal/pkg/show/config, the default config is all written in text. Why not use embed to import template files?

This way you can have highlighting and the separate files are easy to maintain.

Design

All the default config vars are placed in one file(internal/pkg/show/config/config.go), and the default config yaml files are placed in the configs dir.

Take githubactions-* as an example:

var (
	//go:embed configs/githubactions-golang.yaml
	GithubActionsGolangDefaultConfig string
	
	//go:embed configs/githubactions-nodejs.yaml
	GithubActionsNodejsDefaultConfig string

	//go:embed configs/githubactions-python.yaml
	GithubActionsPythonDefaultConfig string
)

Anything else

Similarly, all code that involves templates can be done like this。

Issues that may be affected:
#596 #597 #598

@daniel-hutao
Copy link
Member

It's so cool! This idea is especially awesome!

Let's discuss a simple design that I think would look like as below:

  1. add a plugins directory in the examples directory, which puts all the template configuration of all the plugins, similar to: argocd.yaml file contain the default configuration of argocd.
  2. delete all the files in the internal/pkg/show/config/plugin directory, because all the content in it is put under examples/plugins
  3. update the implementation of the internal/pkg/show/config package to include ideas that you can use according to your "talent"
  4. internal/pkg/show/config/defaultconfig.go can probably be left untouched, because this piece of logic will be refactored soon, I'm working on it. 🍀 Proposal: More Friendly Quickstart Config Template Output #597

@daniel-hutao daniel-hutao added the enhancement New feature or request label May 26, 2022
@iyear
Copy link
Member Author

iyear commented May 26, 2022

@daniel-hutao

I'm currently having a problem with go:embed not working . or .. which means that the parent directory cannot be referenced.

My idea is to create a configs.go in examples dir that reads all these yaml files and provides them to the rest of the program.

Related Issues:
golang/go#46056
golang/go#41191 (comment)

@daniel-hutao
Copy link
Member

How about to put the yaml files to internal/pkg/show/config? @iyear

@iyear
Copy link
Member Author

iyear commented May 26, 2022

@daniel-hutao The latest commit has moved the plugin yaml default config to that dir, but quickstart.yaml will not be read..

I still think the golang/go#41191 (comment) approach is appropriate, as all examples can be exposed to other packages.

@iyear
Copy link
Member Author

iyear commented May 26, 2022

Or I'll start by making the current DefaultConfig standalone as a file. #597 I'll do it later and now I fix this issue.

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