skip to Main Content

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


    1. ls $GOPATH , if is not showing your path of golang library source, you should set path first,
    2. If point 1 is able, you should just doing :go mod tidy

    tidy argument make you doing download package with sync method, without doing go get separately.

    Login or Signup to reply.
  1. I would rather use go vendoring, it will add your dependencies to vendor/ and -mod=vendor will tell golang to search for dependencies locally.

    1. Remove go.sum
    2. Type export GOFLAGS=-mod=vendor
    3. Type 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 example GOFLAGS=-mod=vendor go run cmd/main/main.go

    Don’t forget to add vendor/ to your .gitignore

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search