Proposal: add context import path upgrade to go tool fix #17040

SamWhited opened this Issue Sep 9, 2016 · 7 comments


None yet

5 participants

SamWhited commented Sep 9, 2016 edited

It would be convenient if go tool fix had a rule (possibly off by default?) added to upgrade imports of the context package to the new version in the standard library.

Here is a CL that I'm using to upgrade my projects:

This makes the new rewrites list read as follows:

Available rewrites are:

        Change imports of to context

        Change imports of{exact,types} to go/{constant,types}

        Adapt element key to IPAddr, UDPAddr or TCPAddr composite literals.

        Add element keys to Config composite literals.

This isn't strictly the same as some of the other rewrites in the tool because the old context package is still perfectly usable, so maybe it would be best to leave this fix off by default and allow it to be manually specified.


CL mentions this issue.


You likely want to remain with the old package for quite a while to support building with Go <1.7. I think perhaps we'd want to do this a year or more from now.

@quentinmit quentinmit added this to the Go1.8Maybe milestone Sep 12, 2016
SamWhited commented Sep 12, 2016 edited

Agreed, having it off by default seems sensible, but going ahead and putting it in the tool seems like it would be nice for those who explicitly want to upgrade.

SamWhited commented Sep 12, 2016 edited

I've updated the CL to require -force context for the fix to be run (it looks like force wasn't otherwise used). Would this be an acceptible way to do it? The behavior could then be changed after the 1.8 release cycle or whenever the Go team decides it's more appropriate to be default-on.

adg commented Sep 12, 2016

We still ship and use go tool fix? Flashback!


But yeah, SGTM. Opt-in sounds good.

@gopherbot gopherbot pushed a commit that closed this issue Sep 15, 2016
@SamWhited @bradfitz SamWhited + bradfitz cmd/fix: add fix
Fixes #17040

Change-Id: I3682cc0367b919084c280d7dc64746495c1d4aaa
Reviewed-by: Brad Fitzpatrick <>
Run-TryBot: Brad Fitzpatrick <>
TryBot-Result: Gobot Gobot <>
@gopherbot gopherbot closed this in 22d3bf1 Sep 15, 2016
@Thomasdezeeuw Thomasdezeeuw referenced this issue in grpc/grpc-go Sep 15, 2016

Go 1.7 uses import "context" #711

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment