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

Use variadic function to pass parameters instead of Config struct #454

Merged
merged 2 commits into from
Feb 10, 2017

Conversation

groob
Copy link
Contributor

@groob groob commented Feb 9, 2017

Using function to pass optional params makes the API more consistent
with the rest of go-kit packages.

For #427

Following up on discussion in #427 (comment)

Why not use functional options for level.New instead of Config?

There's no practical difference, but I can in hindsight see the value of using functional options for consistency with the rest of package log. I'd accept a PR :)

I thought it was important to get this change in before #449 and ultimately 1.0.0 to avoid making breaking changes in a stable API.

Using function to pass optional params makes the API more consistent
with the rest of go-kit packages.

For go-kit#427
Copy link
Member

@peterbourgon peterbourgon left a comment

Choose a reason for hiding this comment

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

Yep, I'm basically into it. On review I think it's OK that the functional option operates on an unexported struct. Just a couple of tiny things to look at. Thanks so much for the effort!

// will be squelched, and ErrNotAllowed returned.
Allowed []string
// New wraps the logger and implements level checking. See the commentary on the
// Option functions for a detailed description of how to configure levels.
Copy link
Member

Choose a reason for hiding this comment

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

Would you mind adding an extra sentence of commentary describing the default behavior with no options set?

level.Allowed(level.AllowWarnAndAbove()),
level.ErrNotAllowed(myError),
}
logger := level.New(log.NewNopLogger(), opts...)
Copy link
Member

Choose a reason for hiding this comment

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

Any reason not to inline these? I'm not fussed, just curious.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No specific reason. I usually prefer to create a slice when I have multiple options because it looks more organized, especially if there's a chance the list of options will grow in the future.

I'd be glad to change it if you have the opposite preference.

Copy link
Member

Choose a reason for hiding this comment

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

Cool! No worries.

@peterbourgon
Copy link
Member

Brilliant, thanks for the contribution!

@peterbourgon peterbourgon merged commit a59216a into go-kit:master Feb 10, 2017
@groob groob deleted the level_options branch February 10, 2017 05:17
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