-
Notifications
You must be signed in to change notification settings - Fork 592
Fields helper accepts both map and slice #352
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
Conversation
No extra allocation for variadic arguments or slice of key/value pairs
I'm not a big fan of the name of the method. Ideally it should be What I have in mind (but convinced by any of them):
Ideas are welcome. |
@rs Pushed the change to go with first option Fields(interface). It is less confusing than variadic version, also has less overhead. Tried to optimize logr Zap wrapper before, learned that passing arguments with variadic spread down to call stack does hurt its performance. Does it look good for you? |
Looks good. Could you please add some tests and an example? |
@rs Would you please create a new git tag (for go mod)? Thanks! |
done |
Just wondering, is there any way Fields() can detect errors and call Example: https://go.dev/play/p/ulHc0WIqlC0 |
Useful for logging wrappers like zerologr to reuse the same code for Fields helper (which requires map). No extra allocation for variadic arguments or slice of key/value pairs. It avoids stack copy overhead from variadic arguments (as in Zap ...Fields)