snippetgoMajor
How do I import a specific version of a package using go get?
Viewed 0 times
howpackageusinggetspecificversionimport
Problem
coming from a
Then I used to import that version of that package in my project just with:
Now, I want to do the same thing with
Is it possible to install a specific version of a package? If so, using a centralized
I would do something like this:
But then, how can I make a difference during the import?
Node environment I used to install a specific version of a vendor lib into the project folder (node_modules) by telling npm to install that version of that lib from the package.json or even directly from the console, like so:$ npm install express@4.0.0Then I used to import that version of that package in my project just with:
var express = require('express');Now, I want to do the same thing with
go. How can I do that?Is it possible to install a specific version of a package? If so, using a centralized
$GOPATH, how can I import one version instead of another?I would do something like this:
$ go get github.com/wilk/uuid@0.0.1
$ go get github.com/wilk/uuid@0.0.2But then, how can I make a difference during the import?
Solution
Go 1.11 will have a feature called go modules and you can simply add a dependency with a version. Follow these steps:
Here's more info on that topic - https://github.com/golang/go/wiki/Modules
go mod init .
go mod edit -require github.com/wilk/uuid@0.0.1
go get -v -t ./...
go build
go installHere's more info on that topic - https://github.com/golang/go/wiki/Modules
Code Snippets
go mod init .
go mod edit -require github.com/wilk/uuid@0.0.1
go get -v -t ./...
go build
go installContext
Stack Overflow Q#24855081, score: 83
Revisions (0)
No revisions yet.