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

Turn config into a singleton #45

Merged
merged 2 commits into from Jun 21, 2022
Merged

Turn config into a singleton #45

merged 2 commits into from Jun 21, 2022

Conversation

samcoe
Copy link
Contributor

@samcoe samcoe commented May 30, 2022

This is a follow up PR to #44.

Changes in this PR:

  • export ConfigDir, StateDir, DataDir
  • add Codespaces support in tokenForHost
  • When using Read the loaded config will be cached in a global singleton variable so that subsequent calls to Read will not need to access the filesystem again.

cc cli/cli#5560

@samcoe samcoe self-assigned this May 30, 2022
@samcoe samcoe force-pushed the singleton-config branch 2 times, most recently from cccef90 to 0186f20 Compare May 31, 2022 06:51
@samcoe samcoe marked this pull request as ready for review May 31, 2022 06:56
@samcoe samcoe requested a review from mislav May 31, 2022 06:56
// TODO: Make global config singleton using sync.Once
// so as not to read from file every time.
return load(generalConfigFile(), hostsConfigFile())
var Read = func() (*Config, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changing this to be a variable for testing purposes seemed to be the best approach here to bypass having to deal with sync.Once in tests.

Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

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

Love how much simpler the test setup is with this 👌

Base automatically changed from config-integration to trunk June 21, 2022 14:36
@samcoe samcoe enabled auto-merge (squash) June 21, 2022 14:42
@samcoe samcoe merged commit f06a22b into trunk Jun 21, 2022
@samcoe samcoe deleted the singleton-config branch June 21, 2022 14:43
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.

None yet

2 participants