According to Go documents, go get
is deprecated since Go 1.17. However, running command go install
may give similar errors. Here is my case. When I ran go install
in a directory where there' s a go.mod
file, the error was gone. You may try to create a new go.mod
and check whether or not the issue is there.
% go install
go: cannot find main module, but found .git/config in /Users/xxxx/Documents/learn-terraform-lambda-api-gateway
to create a module there, run:
cd .. && go mod init
% go mod init
go: cannot determine module path for source directory /Users/xxxx/Documents/learn-terraform-lambda-api-gateway/hello-world
(outside GOPATH, module path must be specified)
Example usage:
'go mod init example.com/m' to initialize a v0 or v1 module
'go mod init example.com/m/v2' to initialize a v2 module
Run 'go help mod init' for more information.
% go mod init example.com/m
go: creating new go.mod: module example.com/m
go: to add module requirements and sums:
go mod tidy
% go mod tidy
go: finding module for package github.com/aws/aws-lambda-go/lambda
go: found github.com/aws/aws-lambda-go/lambda in github.com/aws/aws- lambda-go v1.32.0
go: downloading github.com/stretchr/testify v1.6.1
go: downloading github.com/davecgh/go-spew v1.1.1
go: downloading github.com/pmezard/go-difflib v1.0.0
go: downloading gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776
% go install