Go. Installing modules

Viewed 60

I want to install a parsing library but "go get" doesn't work.

go get -u github.com/geziyor/geziyor

Outputs the following:

go: go.mod file not found in current directory or any parent directory.
        'go get' is no longer supported outside a module.
        To build and install a command, use 'go install' with a version,
        like 'go install example.com/cmd@latest'
        For more information, see https://golang.org/doc/go-get-install-de
prediction
        or run 'go help get' or 'go help install'.
1 Answers

For starters, the documentation is a bit misleading. So how do you install a module into your project?

Well, you don't really install it in the first place, you first depend on it in your project. Use

go mod edit -require github.com/geziyor/geziyor@latest

It will be installed during build or when running go mod tidy.

Installing the module right into your project (thus bundling it) is called "vendoring".

Related