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

refactor global config into a dedicated internal package #26

Merged
merged 2 commits into from
Mar 23, 2020

Conversation

stefanotorresi
Copy link
Collaborator

@stefanotorresi stefanotorresi commented Mar 23, 2020

Since the code about configuration was growing a bit too much in main.go, this PR moves it into a dedicated package.

It also introduces a better mechanism to set sap-control-url: a default value is now provided (localhost:50013), and the http:// prefix is internally added in case it's missing, to avoid unfriendly protocol errors that could previously occur.

return nil
}

func sanitizeConfigValues(config *viper.Viper) {
Copy link
Contributor

Choose a reason for hiding this comment

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

perhaps the name of this helper function is better to be called

sanitizeSAPControlUrl` something like this

the current name of the function imply a not single-responsability and is to vague

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I had originally done it how you're suggesting, but then I realized that we have to pass the whole configuration as a pointer argument and mutate it in place anyways, while a single responsibility function would have to be a pure one, getting a string in and putting another string out.
We can re-evaluate this in case we add more validators, but for the time being we only have one.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would imho suggest the contra-approach. I would for the time beeing use a not-generic function istead of generalizing it ( I guess we will never sanitize anh other urls).

I think the function name should not depend of the fact we give it a pointer as argument ( this is 2ndary).

We should rather have clearly in mind what the function does. Reading the function name, I guess it manipulate multiples stuff but in fact doesn't

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm speaking here only about the name

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

hmm okay, fair enough! I guess YAGNI comes into place here. I'll change both names!

return config, nil
}

func validateConfigValues(config *viper.Viper) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

validateSAPConfigUrl or something like this

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

same as #26 (comment)

Copy link
Contributor

@MalloZup MalloZup left a comment

Choose a reason for hiding this comment

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

thx

@stefanotorresi stefanotorresi merged commit 1c29eed into SUSE:master Mar 23, 2020
@stefanotorresi stefanotorresi deleted the config-refactoring branch March 23, 2020 18:24
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