validator: cannot find package "github.com/go-playground/validator/v10" in any of

Package version eg. v8, v9:

v10

Issue, Question or Enhancement:

go get github.com/go-playground/validator/v10

give following error

package github.com/go-playground/validator/v10: cannot find package "github.com/go-playground/validator/v10" in any of:
        /usr/local/go/src/github.com/go-playground/validator/v10 (from $GOROOT)
        /go/src/github.com/go-playground/validator/v10 (from $GOPATH)

Code sample, to showcase or reproduce:

using golang docker latest

$ docker run -it --rm golang sh
$ go get github.com/go-playground/validator/v10
package github.com/go-playground/validator/v10: cannot find package "github.com/go-playground/validator/v10" in any of:
        /usr/local/go/src/github.com/go-playground/validator/v10 (from $GOROOT)
        /go/src/github.com/go-playground/validator/v10 (from $GOPATH)

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 17
  • Comments: 20 (2 by maintainers)

Most upvoted comments

Hi folks, I stumbled with this issue. In my case this is used by another library(gin) but I noticed there is no v10 directory, and since I read this v10 was used for a transition but not longer exists, maybe symlinking to the same project work, and in fact it worked.

And yes, I know it’s too hacky and I don’t really know the side effects.

I did:

$cd $GOPATH/src/github.com/go-playground/validator/
$ln -s . v10

I just initialised my project with go mod init command. Your go get command working after that.

Had the same problem with golang:1.14.2-alpine3.11, added

RUN go mod init

to the dockerfile fixed the issue.

@Higan as mentioned in the EDIT for me updating my golang version did the trick … it’s really a pity that this module topic broke older golang projects (due to the fact that earlier versions of the language simply didn’t allow to explicitly specify certain versions as dependencies).

these are the steps i’m using in my dockerfile:

FROM debian:stretch AS install

# some more steps here but won't list all of them

ENV GOLANG_VERSION 1.11

RUN wget -O go.tgz "https://golang.org/dl/go$GOLANG_VERSION.linux-amd64.tar.gz" && \
    tar -C /usr/local -xzf go.tgz && \
    rm go.tgz && \
    mkdir /go

ENV GOROOT /usr/local/go
ENV GOPATH /go
ENV PATH $GOPATH/bin:$GOROOT/bin:$PATH

RUN go version

RUN go get -v github.com/gin-gonic/gin

The reason that’s this isn’t working is really that go modules is a breaking change to the ecosystem and isn’t compatible with previous tooling.

unfortunately there’s not much I can do about that from this package. If gin changed the import path back to github.com/go-playground/validator and then changed the go mod file to import by tag instead eg. Go get github.com/go-playground/validator@v10.x.x that may be an option but for non go modules projects you’d lose versioning of this package and always be pulling the latest master.

The unfortunate reality is if you want to use a package like gin that has converted to using go modules one should really update their program to use go modules. The alternative is to keep using and older version of gin using some other dependency management.

To solve this I recommend:

  • updating to a version of go that supports go modules.
  • convert your program to use go modules.
  • move your package out of the GOPATH

Please let me know that this helps.

having the same problem when trying to run go get -v github.com/gin-gonic/gin since this is the default validator … running it in docker > fetching for debian:stretch

EDIT: was trying to update packages for an older project where i fixed the golang version to 1.10. updating to 1.11 seems to resolve this issue in my case (but lets see what else breaks)