I downloaded go-redis client using
go mod init github.com/my/repo
go get github.com/go-redis/redis/v8
But it showed cannot find package "go.opentelemetry.io/otel/api/trace". So I deleted go-redis from ${GOPATH}/src/github.com and then tried running it again
go get github.com/go-redis/redis/v8
But it does nothing. Doesn’t show any error or any message. But when I try to import package it says
cannot find package "github.com/go-redis/redis/v8" in any of:
/usr/lib/go/src/github.com/go-redis/redis/v8 (from $GOROOT)
/home/username/go/src/github.com/go-redis/redis/v8 (from $GOPATH)
I tried go mod tidy
go mod clean
but none worked. What should I do?
2
Answers
$GOPATH
, if is not showing your path of golang library source, you should set path first,go mod tidy
tidy argument make you doing download package with sync method, without doing go get separately.
I would rather use go vendoring, it will add your dependencies to vendor/ and -mod=vendor will tell golang to search for dependencies locally.
export GOFLAGS=-mod=vendor
go mod tidy && go mod vendor
If you can’t export variables, use go run and go build with the prefix
GOFLAGS=-mod=vendor
, for exampleGOFLAGS=-mod=vendor go run cmd/main/main.go
Don’t forget to add vendor/ to your .gitignore