Installation bcrypt golang

Asked

Viewed 47 times

1

I have a problem that I cannot solve and would like help if possible. I am new to golang language. During a tutorial that was following regarding the language, a script was created with the bcrypt package, following the step by step was informed the package installation command:

go get -u golang.org/x/crypto/bcrypt

When performing the process as reported, I tried to execute the code and presented and presented the following error message:

024_Aplicacoes/06_bcrypt.go:9:8: no required module provides package github.com/crypto/bcrypt: go.mod file not found in current directory or any parent directory; see 'go help modules'

I’ve tried a lot of lawsuits:

  • Create the golang.org/x folder inside src
  • I changed the content of go.mod
  • I tried to instate via github with and without the github folder

I’m a little upset by catching on to something so trivial. Below follows: Tried Operating System: Windows10 and Ubunto 20 LTS golang versions tried 1.16.2(ubunutu) / 1.16.3 (windows10)

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/tarcisio/.cache/go-build"
GOENV="/home/tarcisio/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/tarcisio/.asdf/installs/golang/1.16.2/packages/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/tarcisio/.asdf/installs/golang/1.16.2/packages"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/tarcisio/.asdf/installs/golang/1.16.2/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/tarcisio/.asdf/installs/golang/1.16.2/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.2"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build770863381=/tmp/go-build -gno-record-gcc-switches"

I know I have a long way to go before I came here seeking resolution I tried, however unsuccessful.

1 answer

1

It seems to me that the problem is that you are not inside the folder that has the go.mod when compiling your code.

Assuming I have a project with the following structure:

playground
|_src
| |_main.go
|_go.mod

And try to run the project from outside the folder playground with go run playground/src/main.go, I would get the bug:

playground\main.go:6:2: no required module provides package golang.org/x/crypto/bcrypt: go.mod file not found in current directory or any parent directory; see 'go help modules'

Because the compiler couldn’t find the go.mod, and therefore does not know the meta-information of bcrypt (as the version).


Now if I go inside the folder with cd playground and then I spin go run src/main.go, the design compiles and wheel perfectly.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.