- #GOLAND GO MODULES INSTALL#
- #GOLAND GO MODULES MOD#
- #GOLAND GO MODULES UPDATE#
- #GOLAND GO MODULES CODE#
pborman/uuid v1.2.1 h1:+ZZIw58t/ozdjRaXh/3awHfmWRbzYxJoAdNJxe/3pvw= google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= Do a cat go.sum /google/uuid v1.0.0 h1:b4Gk+7WdP/d3HZH8EJsZpvV7EtDOgaZLtnaNGIu1adA= It lists direct dependency which was specified in the uuid file along with exact version of the dependency as well. After running this command let’s now let’s again examine the contents of go.mod file
#GOLAND GO MODULES UPDATE#
This command will download all the dependencies that are required in your source files and update go.mod file with that dependency. Notice that we have imported the dependency in the uuid.go as well "/pborman/uuid" Uuid := strings.Replace(uuidWithHyphen.String(), "-", "", -1) Your go.mod file should like below module learnĪlso let’s create a file named uuid.go in the same directory with below contents Remove the dependency we added earlier in the go.mod file. Remove any dependency which is mentioned in the go.mod file but not imported in any of the source files.Add any dependency which is imported in the source files.
#GOLAND GO MODULES MOD#
When we run go mod tidy command then it will do two things Basically, go mod tidy command makes sure that your go.mod files reflect the dependencies that you have actually used in your project. This method we already saw in the above example.
#GOLAND GO MODULES CODE#
Add the dependency to your source code and do a go mod tidy Also it will update the go.sum file with the checksum and version of all direct and indirect dependencies. Once you do a go build after using this in the source files, the //indirect will be removed automatically by go. The dependency will be marked as //indirect as it is not being used in any of the source files. Now run below command export GO111MODULE=on Remove the uuid dependency we added above from go.mod file and clean up go.sum file. Simply doing a go get will also the add the dependency in the go.mod file. go mod download command is used when you want to pre download the dependencies without build or running it. go run will also download and and run the binary as well.
#GOLAND GO MODULES INSTALL#
go build as well as go install also will download the dependencies and also build the binary. This command will download the /pborman/uuid module as well all its dependencies. Fo that we can use the below command go mod download Now we need to download the newly added dependency as well. With this dependency go.mod file will look like below module learn Add below dependency to the go.mod file require /pborman/uuid v1.2.1 We can add direct dependency to the go.mod file too. Now let’s explore different ways of adding a dependency Directly adding it to the go.mod file Since it is an empty module it doesn’t have any direct dependency specified yet. This command will create a go.mod file in the same directory. Let’s explore some ways of adding dependency to your projectīefore looking at each of the ways, again let’s create a module first go mod init learn Also, any dependency that is mentioned in the go.mod file but not imported in any of the source files of the module is also treated as an indirect dependency.