Historically we've insisted that the Context be passed explicitly so that it's always visible in the code and accessible to refactoring tools. In reality, tools that assist in context plumbing don't exist yet, and there are examples of putting Context inside some other structs in the standard library, like http.Request. A Transaction pays a similar role to a Request in programs, so I can see an argument for putting the Context inside it. But I prefer the explicit code with both parameters. This makes it clear to the reader that the functions are operating within a Transaction and where to find the Context for each call. On Wed, Feb 8, 2017 at 7:14 AM Henrik Johansson <dahankz...@gmail.com> wrote:
> The Context as "a bag of stuff" is attractive since it makes your code > easier to refactor (knock, knock) but gives me void* or as Jakob said > map[string]interface{} vibes. > > I think I think it should be avoided but probably not unconditionally. I > guess there can be cases where it makes sense. > > > ons 8 feb. 2017 kl 13:02 skrev Jakob Borg <ja...@nym.se>: > > On 7 Feb 2017, at 03:57, Steven Roth <st...@rothskeller.net> wrote: > > My question is whether putting the transaction in the context using > context.WithValue is a reasonable and appropriate use of that mechanism. > If not, why not? > > In my opinion, this is morally equivalent to a > > func Something(params map[interface{}]interface{}) > > which is a horrible API that no-one here would accept. If the function > needs a sql.Tx that should be one of the parameters. That the function also > takes a Context is beside the point. > > //jb > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.