anz-bank / pkg

Common ANZ Go packages
https://pkg.go.dev/github.com/anz-bank/pkg
Apache License 2.0
2 stars 9 forks source link

WithFunc opens bug possibilities #19

Closed jamesrom closed 4 years ago

jamesrom commented 4 years ago

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 https://github.com/anz-bank/pkg/issues/18#issuecomment-581704464

anzdaddy commented 4 years ago

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