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

Return an interface instead of a struct #159

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Itxaka
Copy link
Contributor

@Itxaka Itxaka commented Mar 1, 2024

No description provided.

@@ -165,7 +165,7 @@ func peers2AddrInfo(peers []string) []peer.AddrInfo {
var infiniteResourceLimits = rcmgr.InfiniteLimits.ToPartialLimitConfig().System

// ToOpts returns node and vpn options from a configuration
func (c Config) ToOpts(l *logger.Logger) ([]node.Option, []vpn.Option, error) {
func (c Config) ToOpts() ([]node.Option, []vpn.Option, 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.

the logger was not really being used in this function anywhere

@Itxaka Itxaka force-pushed the logger_iface branch 2 times, most recently from 9f210fc to abfa7e4 Compare March 1, 2024 12:14
@mudler
Copy link
Owner

mudler commented Mar 1, 2024

I'm quite against returning interfaces - I do believe structs are much better so the consumer actually can tie together without being bound to a specific interface that needs to be satisfied. Ideally the consumer should just take care of that bit. Why is this needed?

@Itxaka
Copy link
Contributor Author

Itxaka commented Mar 1, 2024

I'm quite against returning interfaces - I do believe structs are much better so the consumer actually can tie together without being bound to a specific interface that needs to be satisfied. Ideally the consumer should just take care of that bit. Why is this needed?

mainly because you are bounded tto send the exact struct that this function needs. With an interface you can pass any object that implements that interface so in this case the caller can have its own logger implementation and pass that instead of forcing the caller to pass as struct. Thats the whole point of the interface thingie in golang no?

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.

2 participants