Reputation: 597
I am using github.com/go-chi/jwtauth v1.2.0
, however as soon as I run my main.go
my go.mod
changes the library version to github.com/go-chi/jwtauth v4.0.3+incompatible
which is an older version and doesn't have the functionality that I need. I tried to change the version back manually in the go.mod
file, and the library updates for me, however as soon as I run the command go run main.go
it reverts back to the old version. Why could this be happening and how could i solve this problem?
Thank you.
Upvotes: 0
Views: 2436
Reputation: 2085
The reason for this is because the module author upgraded the module to officially support Go modules (i.e. go mod
). To do this and to keep the same URL, they had to set the module version to 1.x
. As a consequence, go mod
thinks that 4.x
is later than 1.x
when in fact it is not (it's reasonable to think a larger number is later).
Some module authors create a new version, such as v5
, but this would change the URL that the module is fetched from. Some authors are OK with this, others not so much.
In Go 1.16, there is the ability to retract
previous versions of the module - this is a mark in the go.mod
file that tells go not to use that version. Some authors may do this instead.
Hopefully this explains the why, and how some module authors are changing. It doesn't quite fix your problem in this case, but the -mod=readonly
works.
FWIW, the module author here has created v5.x
now, so this problem won't exist for this particular module.
Upvotes: 0
Reputation: 1
go mod tidy
ensures that the go.mod file matches the source code in the module. It adds any missing module requirements necessary to build the current module's packages and dependencies, and it removes requirements on modules that don't provide any relevant packages. It also adds any missing entries to go.sum and removes unnecessary entries.
Go Modules Reference
Upvotes: -1
Reputation: 273366
You can use -mod=readonly
to ask Go tools not to touch your go.mod
. In fact, this is the by default case in Go 1.16, so I recommend you upgrade.
[FWIW, version v4.0.3 sounds like a newer version than v1.2.0]
Upvotes: 2