How to create go.mod file for a go project

On this post, I have added my notes to create go.mod file for a go project

How to create go.mod file for a go project ?

Newyork:authentication-service esumit$ GO111MODULE=on go mod init
go: creating new go.mod: module github.com/authentication-service
go: copying requirements from Gopkg.lock
Newyork:authentication-service esumit$

It has created the following /Users/esumit/go/src/github.com/authentication-service/go.mod file and following /Users/esumit/go/src/github.com/authentication-service/Gopkg.lock file.

 

How to point Go module dependency in go.mod to a latest commit in a repo?

go get github.com/someone/some_module@af044c0995fe

go get bitbucket.org/xxx/xxxx@c9771545b35bb24c6f49e879f058109700110874
go: downloading bitbucket.org/xxxx/xxxx v1.0.1-0.20200911043127-c9771545b35b
go: extracting bitbucket.org/xxx/xxxx v1.0.1-0.20200911043127-c9771545b35b

$ export GO111MODULE=on
$ export GOPROXY=direct
$ export GOSUMDB=off
$ go get -v -u github.com/alessiosavi/GoGPUtils@v0.0.9
go: finding github.com/alessiosavi/GoGPUtils v0.0.9
go: downloading github.com/alessiosavi/GoGPUtils v0.0.9
go: extracting github.com/alessiosavi/GoGPUtils v0.0.9
-> unzip /var/folders/zb/5p8cwfhj29gf_m8vdy8ylmlr00jwcj/T/tmp.6HERCDpw/pkg/mod/cache/download/github.com/alessiosavi/!go!g!p!utils/@v/v0.0.9.zip: case-insensitive file name collision: “tests/fileutils/FindMe.txt” and “tests/fileutils/findme.txt”
go get github.com/alessiosavi/GoGPUtils@v0.0.9: unzip /var/folders/zb/5p8cwfhj29gf_m8vdy8ylmlr00jwcj/T/tmp.6HERCDpw/pkg/mod/cache/download/github.com/alessiosavi/!go!g!p!utils/@v/v0.0.9.zip: case-insensitive file name collision: “tests/fileutils/FindMe.txt” and “tests/fileutils/findme.txt”

Go env

>>) ✗ go env
GOARCH=”amd64″
GOBIN=”/Users/esumit/go/bin”
GOCACHE=”/Users/esumit/Library/Caches/go-build”
GOEXE=””
GOFLAGS=” -mod=”
GOHOSTARCH=”amd64″
GOHOSTOS=”darwin”
GOOS=”darwin”
GOPATH=”/Users/esumit/go”
GOPROXY=”direct”
GORACE=””
GOROOT=”/Users/esumit/Documents/Go/go”
GOTMPDIR=””
GOTOOLDIR=”/Users/esumit/Documents/Go/go/pkg/tool/darwin_amd64″
GCCGO=”gccgo”
CC=”clang”
CXX=”clang++”
CGO_ENABLED=”1″
GOMOD=”/Users/esumit/go/src/bitbucket.org/xxxx/xxx/xxx/xxx/go.mod”
CGO_CFLAGS=”-g -O2″
CGO_CPPFLAGS=””
CGO_CXXFLAGS=”-g -O2″
CGO_FFLAGS=”-g -O2″
CGO_LDFLAGS=”-g -O2″
PKG_CONFIG=”pkg-config”
GOGCCFLAGS=”-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/zx/p7stj86d2hd4qt2y92_prr700000gn/T/go-build074334311=/tmp/go-build -gno-record-gcc-switches -fno-common”

go.mod

module github.com/authentication-service

go 1.12

require (
   github.com/aws/aws-sdk-go v1.13.1
   github.com/go-ini/ini v1.32.0
   github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8
)

Gopkg.lock

# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.


[[projects]]
  name = "github.com/aws/aws-sdk-go"
  packages = [
    "aws",
    "aws/awserr",
    "aws/awsutil",
    "aws/client",
    "aws/client/metadata",
    "aws/corehandlers",
    "aws/credentials",
    "aws/credentials/ec2rolecreds",
    "aws/credentials/endpointcreds",
    "aws/credentials/stscreds",
    "aws/defaults",
    "aws/ec2metadata",
    "aws/endpoints",
    "aws/request",
    "aws/session",
    "aws/signer/v4",
    "internal/sdkrand",
    "internal/shareddefaults",
    "private/protocol",
    "private/protocol/json/jsonutil",
    "private/protocol/jsonrpc",
    "private/protocol/query",
    "private/protocol/query/queryutil",
    "private/protocol/rest",
    "private/protocol/xml/xmlutil",
    "service/cognitoidentityprovider",
    "service/sts"
  ]
  revision = "f9a6880d84e16e2a37055793e17164a228d637f4"
  version = "v1.13.1"

[[projects]]
  name = "github.com/go-ini/ini"
  packages = ["."]
  revision = "32e4c1e6bc4e7d0d8451aa6b75200d19e37a536a"
  version = "v1.32.0"

[[projects]]
  name = "github.com/jmespath/go-jmespath"
  packages = ["."]
  revision = "0b12d6b5"

[solve-meta]
  analyzer-name = "dep"
  analyzer-version = 1
  inputs-digest = "8a070958c442d9bece3a61833384485544a391ed340072ed7295954426ae55ac"
  solver-name = "gps-cdcl"
  solver-version = 1

Fetch Dependencies

Newyork:authentication-service esumit$ GO111MODULE=on go get -u
go: finding github.com/go-ini/ini v1.32.0
go: finding github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8
go: finding github.com/aws/aws-sdk-go v1.13.1
go: finding github.com/go-ini/ini v1.57.0
go: finding github.com/aws/aws-sdk-go v1.31.7
go: finding github.com/stretchr/testify v1.6.0
go: finding gopkg.in/check.v1 latest
go: finding gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
go: finding golang.org/x/sys latest
go: finding golang.org/x/crypto latest
go: finding golang.org/x/net latest
go: finding golang.org/x/tools latest
go: finding gopkg.in/yaml.v3 latest
go: finding golang.org/x/xerrors latest
go: finding github.com/yuin/goldmark v1.1.31
go: finding golang.org/x/sync latest
go: finding github.com/oluu/authentication-service/authentication latest
go: finding github.com/oluu/authentication-service/identity latest
go: finding github.com/oluu/authentication-service latest
go: downloading github.com/oluu/authentication-service v0.0.0-20180227163211-1c2033ea7730
go: extracting github.com/oluu/authentication-service v0.0.0-20180227163211-1c2033ea7730
go: downloading github.com/aws/aws-sdk-go v1.31.7
go: extracting github.com/aws/aws-sdk-go v1.31.7
go: downloading github.com/jmespath/go-jmespath v0.3.0
go: extracting github.com/jmespath/go-jmespath v0.3.0
Newyork:authentication-service esumit$ 

 go env

Newyork:authentication-service esumit$ go env
GOARCH=”amd64″
GOBIN=”/Users/esumit/go/bin”
GOCACHE=”/Users/esumit/Library/Caches/go-build”
GOEXE=””
GOFLAGS=””
GOHOSTARCH=”amd64″
GOHOSTOS=”darwin”
GOOS=”darwin”
GOPATH=”/Users/esumit/go”
GOPROXY=””
GORACE=””
GOROOT=”/Users/esumit/Documents/Go/go”
GOTMPDIR=””
GOTOOLDIR=”/Users/esumit/Documents/Go/go/pkg/tool/darwin_amd64″
GCCGO=”gccgo”
CC=”clang”
CXX=”clang++”
CGO_ENABLED=”1″
GOMOD=””
CGO_CFLAGS=”-g -O2″
CGO_CPPFLAGS=””
CGO_CXXFLAGS=”-g -O2″
CGO_FFLAGS=”-g -O2″
CGO_LDFLAGS=”-g -O2″
PKG_CONFIG=”pkg-config”
GOGCCFLAGS=”-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/zx/p7stj86d2hd4qt2y92_prr700000gn/T/go-build001875696=/tmp/go-build -gno-record-gcc-switches -fno-common”
Newyork:authentication-service esumit$
Newyork:authentication-service esumit$

go version
go version go1.12.7 darwin/amd64
Newyork:authentication-service esumit$

 

Before go mod tidy

module github.com/authentication-service

go 1.12

require (
   github.com/aws/aws-sdk-go v1.31.7
   github.com/go-ini/ini v1.57.0
   github.com/jmespath/go-jmespath v0.3.0
   github.com/oluu/authentication-service v0.0.0-20180227163211-1c2033ea7730
   github.com/stretchr/objx v0.2.0 // indirect
   github.com/stretchr/testify v1.6.0 // indirect
   github.com/yuin/goldmark v1.1.31 // indirect
   golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37 // indirect
   golang.org/x/mod v0.3.0 // indirect
   golang.org/x/net v0.0.0-20200528225125-3c3fba18258b // indirect
   golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a // indirect
   golang.org/x/sys v0.0.0-20200523222454-059865788121 // indirect
   golang.org/x/text v0.3.2 // indirect
   golang.org/x/tools v0.0.0-20200530233709-52effbd89c51 // indirect
   gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
   gopkg.in/yaml.v3 v3.0.0-20200506231410-2ff61e1afc86 // indirect
)

After Go Mod Tidy

module github.com/authentication-service

go 1.12

require (
	github.com/aws/aws-sdk-go v1.31.7
	github.com/davecgh/go-spew v1.1.1 // indirect
	github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
	github.com/oluu/authentication-service v0.0.0-20180227163211-1c2033ea7730
	github.com/stretchr/testify v1.6.0 // indirect
	golang.org/x/net v0.0.0-20200528225125-3c3fba18258b // indirect
	golang.org/x/text v0.3.2 // indirect
	gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
	gopkg.in/yaml.v3 v3.0.0-20200506231410-2ff61e1afc86 // indirect
)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s