go test foo - cannot find package foo - go

I have this directory structure:
https://github.com/netjet-chrome-extension/netjet-mono/tree/master/examples/projects/golang
I try to run test.sh, which consists of:
#!/usr/bin/env bash
cd "$(dirname "$BASH_SOURCE")"
export GOPATH="$PWD"
go test sourcegraph_go_selenium
but I get this error:
can't load package: package sourcegraph_go_selenium: cannot find
package "sourcegraph_go_selenium" in any of:
/usr/lib/go-1.10/src/sourcegraph_go_selenium (from $GOROOT)
/home/oleg/codes/netjet/netjet-mono/examples/projects/golang/src/sourcegraph_go_selenium
(from $GOPATH)
GOPATH is set correctly, so why can't it find the sourcegraph_go_selenium package? this package is right there, in src/sourcegraph_go_selenium...?

Try this:
go test sourcegraph_go_selenium/...

Related

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

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"
)

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

go install command with glide on windows

I'm having trouble running the go install $(glide nv) command.
I run this command from within my project's folder within the src folder of the go workspace directoy
so basically I do :
%GOPATH%/src/my/project/ go install $(glide nv)
The error message I get is as follow :
can't load package: package $(glide: cannot find package "$(glide" in any of:
C:\Go\src\$(glide (from $GOROOT)
W:\GO_WORKSPACE\src\$(glide (from $GOPATH)
can't load package: package nv): cannot find package "nv)" in any of:
C:\Go\src\nv) (from $GOROOT)
W:\GO_WORKSPACE\src\nv) (from $GOPATH)
I had previously run glide install without a problem on that project.
What am I missing?
It works on powershell. At the project directory run command:
go install $(glide nv)

Resolving 'cannot find package' error with vendor in go 1.7

I have a project structure which looks like below:-
session-service
_libs //Contains all the external dependencies
api
constants
exceptions
idgen
jsonDecoder
log
model
monitor
persistence
redis
routes
src/bddtest/servicetest
util
Content of _libs looks like below:-
github.com
golang.org
x
net
gopkg.in
My Makefile looks like below:-
.PHONY: deploy
LOGLEVEL ?= 1
CONFIGFILE ?= 2
GOFLAGS ?= $(GOFLAGS:)
PWD = $(shell pwd)
export GOPATH = $(shell echo $$GOPATH):$(PWD)/_libs:$(PWD)
export GOBIN = $(PWD)/bin
export GOROOT = $(shell echo $$GOROOT)
deploy: clean build install
build:
#rm -rf pkg/ 2>/dev/null
#rm -rf _libs/pkg/ 2>/dev/null
#go build $(GOFLAGS) ./...
install:
#go install ./...
clean:
#go clean $(GOFLAGS) -i ./...
## EOF
Everything is working fine. Now I am thinking of moving to vendor. So I renamed my _libs to vendor and modified my Makefile like below:-
export GOPATH = $(shell echo $$GOPATH):$(PWD)
But after this I started getting the following error:-
vendor/golang.org/x/net/html/charset/charset.go:20:2: cannot find package "golang.org/x/text/encoding" in any of:
/Users/debraj/golang/src/b/m/session-service/vendor/golang.org/x/text/encoding (vendor tree)
/usr/local/go/src/golang.org/x/text/encoding (from $GOROOT)
/Users/debraj/golang/src/golang.org/x/text/encoding (from $GOPATH)
/Users/debraj/golang/src/b/m/session-service/src/golang.org/x/text/encoding
vendor/golang.org/x/net/html/charset/charset.go:21:2: cannot find package "golang.org/x/text/encoding/charmap" in any of:
/Users/debraj/golang/src/b/m/session-service/vendor/golang.org/x/text/encoding/charmap (vendor tree)
/usr/local/go/src/golang.org/x/text/encoding/charmap (from $GOROOT)
/Users/debraj/golang/src/golang.org/x/text/encoding/charmap (from $GOPATH)
/Users/debraj/golang/src/b/m/session-service/src/golang.org/x/text/encoding/charmap
vendor/golang.org/x/net/html/charset/charset.go:22:2: cannot find package "golang.org/x/text/encoding/htmlindex" in any of:
/Users/debraj/golang/src/b/m/session-service/vendor/golang.org/x/text/encoding/htmlindex (vendor tree)
/usr/local/go/src/golang.org/x/text/encoding/htmlindex (from $GOROOT)
/Users/debraj/golang/src/golang.org/x/text/encoding/htmlindex (from $GOPATH)
/Users/debraj/golang/src/b/m/session-service/src/golang.org/x/text/encoding/htmlindex
vendor/golang.org/x/net/html/charset/charset.go:23:2: cannot find package "golang.org/x/text/transform" in any of:
/Users/debraj/golang/src/b/m/session-service/vendor/golang.org/x/text/transform (vendor tree)
/usr/local/go/src/golang.org/x/text/transform (from $GOROOT)
/Users/debraj/golang/src/golang.org/x/text/transform (from $GOPATH)
/Users/debraj/golang/src/b/m/session-service/src/golang.org/x/text/transform
vendor/golang.org/x/net/http2/h2i/h2i.go:38:2: cannot find package "golang.org/x/crypto/ssh/terminal" in any of:
/Users/debraj/golang/src/b/m/session-service/vendor/golang.org/x/crypto/ssh/terminal (vendor tree)
/usr/local/go/src/golang.org/x/crypto/ssh/terminal (from $GOROOT)
/Users/debraj/golang/src/golang.org/x/crypto/ssh/terminal (from $GOPATH)
/Users/debraj/golang/src/b/m/session-service/src/golang.org/x/crypto/ssh/terminal
Environment:-
go version go1.7.3 darwin/amd64
Mac OS X 10.11.6
Can someone let me know why I am getting the above errors with vendor but everything works fine with _libs?
UPDATE
In my local the newlines in the output of $(go list ./... | grep -v /vendor/) was causing some problem. So to resolve this I had to modify the jimb 's solution a bit. I introduced a variable in Makefile PKG = $(shell go list ./... | grep -v /vendor/ | tr "\n" " ") and then used that variable in go install & go build like #go build $(GOFLAGS) $(PKG)
The _libs directory starts with _, and is ignored by the go tool. When you move the packages to vendor/, the ./... wildcard now includes all packages in the vendor directory.
You should explicitly list the package you want to install, rather than rely on the ./... wildcard. If you still want the wildcard behavior, you can use go list ./... and filter any package containing a vendor/ directory in their path. Depending on your specific needs, this could be as simple as:
go install $(go list ./... | grep -v vendor/)

Go install: “Can't load package” (even though GOPATH is set)

I'm just getting started with the Go programming language and installed Go using the Windows installer from the website. I tested installation by using go run hello.go and that works. The problem comes when I try to build my first program:
$ echo $GOROOT
C:\Go\
$ echo $GOPATH
/cygdrive/c/Users/Paul/Documents/Home/go
mkdir -p $GOPATH/src/hello
Inside that directory I have a simple hello.go program:
package main
import "fmt"
func main() {
fmt.Printf("Hello, world.\n")
}
The problem comes when I try to build and install:
$ go install hello
can't load package: package hello: cannot find package "hello" in any of:
C:\Go\src\hello (from $GOROOT)
\cygdrive\c\Users\Paul\Documents\Home\go\src\hello (from $GOPATH)
GOPATH environment variable must contain valid path.
\cygdrive\c\Users\Paul\Documents\Home\go\src\hello is not a valid path on Windows.
Try setting GOPATH=c:\Users\Paul\Documents\Home\go instead.

Resources