Build dependencis for aws-sdk-go fails on Go version 1.13 - go

I have been trying to build a module on Go v1.13 with dependencies on github.com/aws/aws-lambda-go and github.com/aws/aws-sdk-go which fail on the two imports:
"github.com/aws/aws-sdk-go/aws/service/s3"
"github.com/aws/aws-sdk-go/aws/service/s3/s3manager"
The stderr is as follows for GOOS=linux GOARCH=amd64 go build -o dist/api ./api where the api directory contains my module definition:
api/main.go:11:2: cannot find package "github.com/aws/aws-sdk-go/aws/service/s3" in any of:
/usr/local/go/src/github.com/aws/aws-sdk-go/aws/service/s3 (from $GOROOT)
/u/go/src/github.com/aws/aws-sdk-go/aws/service/s3 (from $GOPATH)
api/main.go:12:2: cannot find package "github.com/aws/aws-sdk-go/aws/service/s3/s3manager" in any of:
/usr/local/go/src/github.com/aws/aws-sdk-go/aws/service/s3/s3manager (from $GOROOT)
/u/go/src/github.com/aws/aws-sdk-go/aws/service/s3/s3manager (from $GOPATH)
Honestly, I have no clue why this is happening and any inputs would be appreciated.
Already tried using go get to ensure that the dependencies have been pulled:
$ go get github.com/aws/aws-sdk-go
and the requested import paths are present under $GOPATH/src/github.com/aws/aws-sdk/go/aws/service/s3 and $GOPATH/src/github.com/aws/aws-sdk/go/aws/service/s3/s3manager
Also, tried clearing the cache using go clean --cache --modcache whilst removing previously pulled modules.
On closer inspection, something that I completely overlooked, the import path is /u/go/src/github.com/aws/aws-sdk-go/aws/service/s3 instead of /u/go/src/github.com/aws/aws-sdk-go/service/s3 with the former having an additional aws subpath inside aws-sdk-go.

Just realized the copy/paste error I had made in the code.
import (
"github.com/aws/aws-sdk-go/aws/service/s3"
"github.com/aws/aws-sdk-go/aws/service/s3/s3manager"
)
instead of
import (
"github.com/aws/aws-sdk-go/service/s3"
"github.com/aws/aws-sdk-go/service/s3/s3manager"
)

Related

How should I resolve this import problem with gorilla/mux?

could not import github.com/gorilla/mux (cannot find package "github.com/gorilla/mux" in any of
C:\Program Files\Go\src\github.com\gorilla\mux (from $GOROOT)
C:\Users\lenovo\go\src\github.com\gorilla\mux (from $GOPATH))compilerBrokenImport
I have installed gorilla mux using the cmd "go get github.com/gorilla/mux" but I'm getting this error.enter image description here
Looks like you didn't run "go mod init" before the "go get".
In cmd, try this:
cd [the dir of your source code]
go mod init
go get github.com/gorilla/mux
For more information run:
go help mod
Afterwards, you might also need to restart VS Code.

Endorsers Instantiate Chaincode with error "cannot find package"

I created a chaincode and I imported a package to it.
import (
"bytes"
"encoding/json"
"fmt"
"strings"
"golang.org/x/crypto/bcrypt"
"github.com/hyperledger/fabric/core/chaincode/shim"
pb "github.com/hyperledger/fabric/protos/peer")
I can install that chaincode to all endorsers. But when I instantiated it to all endorsers, it faced the error:
endorser failed with error starting container: error starting container: Failed to generate platform-specific docker build: Error returned from build: 1 "/chaincode/input/src/github.com/marbles02/marbles_chaincode.go:85:2: cannot find package "golang.org/x/crypto/bcrypt" in any of:
/usr/local/go/src/golang.org/x/crypto/bcrypt (from $GOROOT)
/chaincode/input/src/golang.org/x/crypto/bcrypt (from $GOPATH)
/go/src/golang.org/x/crypto/bcrypt
I tried to copy golang.org/x/crypto/bcrypt package to the /usr/local/go/src/ in the root directory, but it has the same error.
Try Installing the dependencies in the chaincode directory using below commands:
go mod init will create go.mod and go.sum files.
go mod vendor for creating a vendor directory.
Also if using fabric:v2.X.X then shim and peer packages moved to different libraries.
so change the peer and shim packages to below in the chaincode.go file.
peer --> github.com/hyperledger/fabric-protos-go/peer.
shim --> github.com/hyperledger/fabric-chaincode-go/shim
Make sure to add peerand shim changes before running go mod initcommand OR if you are already have a vendor directory then try go mod tidy and then go mod vendor commands to update the packages.

Cannot find package under GOPATH

I am trying to install the dependencies of my project with glidebut unfortunately it fails with the following message:
main.go:7:2: cannot find package "github.com/arschles/go-in-5-minutes/episode13/models" in any of:
/Users/theo/go-workspace/src/github.com/thitami/go-in-5-minutes/episode13/vendor/github.com/arschles/go-in-5-minutes/episode13/models (vendor tree)
/usr/local/Cellar/go/1.8.3/libexec/src/github.com/arschles/go-in-5-minutes/episode13/models (from $GOROOT)
/Users/theo/go-workspace/src/github.com/arschles/go-in-5-minutes/episode13/models (from $GOPATH)
Running a go env, this is my env variables of interest:
GOPATH="/Users/theo/go-workspace"
GOROOT="/usr/local/Cellar/go/1.8.3/libexec"
Please be advised that I am zsh and I am exporting the GOPATH inside the .zshrc file like this:
export GOPATH=HOME/go-workspace
Any ideas are appreciated
* UPDATE *
As requested this is the piece of code with the call to the models package:
import (
"database/sql"
"log"
"github.com/arschles/go-in-5-minutes/episode13/models"
_ "github.com/mxk/go-sqlite/sqlite3"
)
You can only set the gopath once and you'll have to reset it every time you change packages. Think of it as a virtualenv. One way around it is to install the packages global or by using something like gvm

Cannot find package "testing/internal/testdeps"

When I try to run go test I've got that message:
package testmain
imports testing/internal/testdeps: cannot find package "testing/internal/testdeps" in any of:
/usr/local/go/src/testing/internal/testdeps (from $GOROOT)
/Users/myname/go/src/testing/internal/testdeps (from $GOPATH)
FAIL github.com/dzyanis/olyalya/cmd [setup failed]
I think it is happened after I've installed a package manager Glide, but I'm not sure. Does anyone know how to fix that?
UPDATE: I've reinstalled Go and everything works well. That's it.
I fixed it by set:
export $GOROOT=

How to import a golang own package?

I have problems with importing a package. I want to import the "golang.org/x/tools/cmd/oracle" and the "golang.org/x/tools/oracle" package.
Which is the correct way to import these packages?
This the way I try to import the packages:
package main
import (
"fmt"
"strings"
"os"
"os/exec"
"golang.org/x/tools/oracle"
"golang.org/x/tools/cmd/oracle"
)
The both last imports leads to the following problem:
==================== Starting Go build ====================
Cleared problem markers for ProjektGO.
************ Building Go project: ProjektGO ************
with GOPATH: /home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO
>> Running: /usr/lib/go/bin/go install -v -gcflags "-N -l" ./...
file/main.go:13:2: cannot find package "golang.org/x/tools/cmd/oracle" in any of:
/usr/lib/go/src/golang.org/x/tools/cmd/oracle (from $GOROOT)
/home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/golang.org/x/tools/cmd/oracle (from $GOPATH)
file/main.go:12:2: cannot find package "golang.org/x/tools/oracle" in any of:
/usr/lib/go/src/golang.org/x/tools/oracle (from $GOROOT)
/home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/golang.org/x/tools/oracle (from $GOPATH)
^^^ Terminated, exit code: 1 ^^^
************ Build terminated. ************
Then I tried things like that:
package main
import (
"fmt"
"strings"
"os"
"os/exec"
"../../../../../golang.org/x/tools/cmd/oracle"
"../../../../../golang.org/x/tools/oracle"
)
And the result was this:
==================== Starting Go build ====================
************ Building Go project: ProjektGO ************
with GOPATH: /home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO
>> Running: /usr/lib/go/bin/go install -v -gcflags "-N -l" ./...
can't load package: /home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/file/main.go:11:2: import "../../../../../golang.org/x/tools/cmd/oracle" is a program, not an importable package
../../../../golang.org/x/tools/oracle/describe.go:20:2: cannot find package "golang.org/x/tools/go/ast/astutil" in any of:
/usr/lib/go/src/golang.org/x/tools/go/ast/astutil (from $GOROOT)
/home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/golang.org/x/tools/go/ast/astutil (from $GOPATH)
../../../../golang.org/x/tools/cmd/oracle/main.go:26:2: cannot find package "golang.org/x/tools/go/buildutil" in any of:
/usr/lib/go/src/golang.org/x/tools/go/buildutil (from $GOROOT)
/home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/golang.org/x/tools/go/buildutil (from $GOPATH)
../../../../golang.org/x/tools/oracle/callers.go:11:2: cannot find package "golang.org/x/tools/go/callgraph" in any of:
/usr/lib/go/src/golang.org/x/tools/go/callgraph (from $GOROOT)
/home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/golang.org/x/tools/go/callgraph (from $GOPATH)
../../../../golang.org/x/tools/cmd/oracle/main.go:27:2: cannot find package "golang.org/x/tools/go/loader" in any of:
/usr/lib/go/src/golang.org/x/tools/go/loader (from $GOROOT)
/home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/golang.org/x/tools/go/loader (from $GOPATH)
../../../../golang.org/x/tools/oracle/callees.go:17:2: cannot find package "golang.org/x/tools/go/pointer" in any of:
/usr/lib/go/src/golang.org/x/tools/go/pointer (from $GOROOT)
/home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/golang.org/x/tools/go/pointer (from $GOPATH)
../../../../golang.org/x/tools/oracle/callees.go:18:2: cannot find package "golang.org/x/tools/go/ssa" in any of:
/usr/lib/go/src/golang.org/x/tools/go/ssa (from $GOROOT)
/home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/golang.org/x/tools/go/ssa (from $GOPATH)
../../../../golang.org/x/tools/oracle/callees.go:19:2: cannot find package "golang.org/x/tools/go/ssa/ssautil" in any of:
/usr/lib/go/src/golang.org/x/tools/go/ssa/ssautil (from $GOROOT)
/home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/golang.org/x/tools/go/ssa/ssautil (from $GOPATH)
../../../../golang.org/x/tools/oracle/describe.go:22:2: cannot find package "golang.org/x/tools/go/types/typeutil" in any of:
/usr/lib/go/src/golang.org/x/tools/go/types/typeutil (from $GOROOT)
/home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/golang.org/x/tools/go/types/typeutil (from $GOPATH)
../../../../golang.org/x/tools/cmd/oracle/main.go:28:2: cannot find package "golang.org/x/tools/oracle" in any of:
/usr/lib/go/src/golang.org/x/tools/oracle (from $GOROOT)
/home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/golang.org/x/tools/oracle (from $GOPATH)
../../../../golang.org/x/tools/oracle/callees.go:20:2: cannot find package "golang.org/x/tools/oracle/serial" in any of:
/usr/lib/go/src/golang.org/x/tools/oracle/serial (from $GOROOT)
/home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/golang.org/x/tools/oracle/serial (from $GOPATH)
../../../../golang.org/x/tools/oracle/implements.go:21:2: cannot find package "golang.org/x/tools/refactor/importgraph" in any of:
/usr/lib/go/src/golang.org/x/tools/refactor/importgraph (from $GOROOT)
/home/haapoo/go/src/github.com/ProjektarbeitGo/ProjektGO/src/golang.org/x/tools/refactor/importgraph (from $GOPATH)
^^^ Terminated, exit code: 1 ^^^
************ Build terminated. ************
My GOROOT is /usr/lib/go and my GOPATH is /home/haapoo/go .
I know the question about gopath and goroot comes often but maybe anyone has an idea.
PS: I use goclipse
Greetings
haapoo
Have you run go get golang.org/x/tools/oracle and go get golang.org/x/tools/cmd/oracle ? This should be run after $GOPATH is properly set.
Never ever set GOROOT. (Unless you know what you are doing). Setting it is not needed.
As you cannot import golang.org/x/tools/cmd/oracle as this is a main package. At least you cannot do this the easy way and you should not anyway (except if you want to test the imported main package).
Importing is not magic, you'll have to download the package before using it. Use go get as others have mentioned.
Build on the command line to be sure what you are doing and how you are doing it (IDEs tend to blur things here).
If you need to import different packages of the same name in Golang, this is the way(just name it):
import (
"text/template"
ht "html/template"
)
but in case of "golang.org/x/tools/cmd/oracle"
it is not a package , it has just main.go and you need to build/install it. it is a command line tool:
Run 'oracle -help' for more information.
Go source code oracle.
Usage: oracle [<flag> ...] <mode> <args> ...
The -format flag controls the output format:
plain an editor-friendly format in which every line of output
is of the form "pos: text", where pos is "-" if unknown.
json structured data in JSON syntax.
xml structured data in XML syntax.
oracle is a source analysis command line tool, you can't import it. Use the following command to get it:
go get golang.org/x/tools/cmd/oracle
This will create an executable named oracle in your $GOPATH/bin directory.
Visit http://golang.org/s/oracle-user-manual for the complete oracle documentation.

Resources