Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: allow adding attribute via a context function #25

Merged
merged 1 commit into from
Aug 13, 2024

Conversation

teleivo
Copy link
Contributor

@teleivo teleivo commented May 11, 2024

Context keys should be kept private to avoid collisions with other packages https://pkg.go.dev/context#Context.Value. WithContextFunc allows you to add slog.Attrs with slog.Values from the context.Context in such situations.

Implements #24

This is useful if you only have access to the context values via functions.
@teleivo
Copy link
Contributor Author

teleivo commented May 11, 2024

@orandin in

l.contextKeys = make(map[string]string, 0)
the map is made with space for 0 elements https://pkg.go.dev/builtin#make. Do you know why? I can do so as well, but I don't think we should since we will add one element within the WithContextFunc and WithContextValue. Maybe I am missing something 🤔

@teleivo
Copy link
Contributor Author

teleivo commented Jun 16, 2024

@orandin could you please have a look at the PR, thanks a lot!

@teleivo
Copy link
Contributor Author

teleivo commented Jul 31, 2024

@orandin could you please review the PR. Thanks a lot!

@orandin orandin self-assigned this Aug 6, 2024
@orandin orandin added the enhancement New feature or request label Aug 6, 2024
@orandin
Copy link
Owner

orandin commented Aug 6, 2024

Sorry for the delay, I'm going to review the PR this week

@orandin
Copy link
Owner

orandin commented Aug 13, 2024

@orandin in

l.contextKeys = make(map[string]string, 0)

the map is made with space for 0 elements https://pkg.go.dev/builtin#make. Do you know why? I can do so as well, but I don't think we should since we will add one element within the WithContextFunc and WithContextValue. Maybe I am missing something 🤔

Indeed, it is redundant size hint. We can remove the size.

Nice contribution! I'm going to merge this PR.
Thank you @teleivo for your contribution and for your patience.

@orandin orandin merged commit 42ee180 into orandin:master Aug 13, 2024
@teleivo
Copy link
Contributor Author

teleivo commented Aug 16, 2024

@orandin in

l.contextKeys = make(map[string]string, 0)

the map is made with space for 0 elements https://pkg.go.dev/builtin#make. Do you know why? I can do so as well, but I don't think we should since we will add one element within the WithContextFunc and WithContextValue. Maybe I am missing something 🤔

Indeed, it is redundant size hint. We can remove the size.

Nice contribution! I'm going to merge this PR. Thank you @teleivo for your contribution and for your patience.

Thank you @orandin 🥳

@teleivo teleivo deleted the with-context-func branch August 16, 2024 11:53
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants