goredisgo-get

Why cannot import library from go get?


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?


Solution

    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.