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

WithFunc opens bug possibilities #19

Closed
jamesrom opened this issue Feb 4, 2020 · 1 comment · Fixed by #22
Closed

WithFunc opens bug possibilities #19

jamesrom opened this issue Feb 4, 2020 · 1 comment · Fixed by #22

Comments

@jamesrom
Copy link

jamesrom commented Feb 4, 2020

Regarding the WithFunc, it was added just for more flexibility should a field value depends on context or anything else.

YAGNI. Can you give a specific example of a problem it solves? I can give an example of a problem it introduces: you've now got a way to get into an infinite loop without really realising it.

fields.WithFunc("foo", func(ctx context.Context) interface{} {
    return util.getValueOfFoo(ctx)
}).Onto(ctx)

// somewhere else, some utility package etc
func getValueOfFoo(ctx context.Context) string {
    log.From(ctx).Info("getting value of foo") // infinite recursion here
    return "bar"
}

Originally posted by @jamesrom in #18 (comment)

@anzdaddy
Copy link
Member

anzdaddy commented Feb 4, 2020

It was just a nice-to-have. Let's remove it.

nofun97 added a commit to nofun97/pkg that referenced this issue Feb 5, 2020
@nofun97 nofun97 mentioned this issue Feb 5, 2020
nofun97 added a commit that referenced this issue Feb 15, 2020
* removed WithFunc, fixes #19

* renamed WithCtxRef to WithContextRef

* changed to WithContextKey
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 a pull request may close this issue.

2 participants