C
C
coolstudent2019-09-29 22:52:53
go
coolstudent, 2019-09-29 22:52:53

Golang how to make project outside GOPATH?

Actually, I want to be able to get rid of placing projects in GOPATH and GOROOT and in general in any paths specified by environment variables and without creating a module from the project, because the project is a program and not a module (a module in my understanding is something like a library) and eliminate the need to load something on github. I want it to be like in PHP - I installed the composer, installed the dependencies in the project directory and everything works fine. Is there such an option? If possible, I ask for tools under Windows, but I will not refuse under Linux either. I read on the internet about golang vendoring but never smoked it. In some places it is written that vendoring allows you to do a project outside the gopas, in others, on the contrary, that everything should be inside the gopas. Who to believe?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
P
Papa, 2019-09-30
Stifflera @PapaStifflera

You have the wrong idea about modules in Go.
They are just about flexible dependency management. Allow, for example, to use several versions (possibly incompatible with each other) of the same module within the project. Well, plus, you don’t need to install anything extra like glide / dep etc. - go build itself will pull up everything you need.

A
Alexander Pavlyuk, 2019-09-30
@pav5000

Just create a project folder outside the GOPATH, do it in it.
This may not necessarily be the path to the github, just come up with a project name for yourself, this will be the name of the module. All nested modules will be imported as your/module/path/submodule/path.
In principle, everything, just then call go build your/module/path/main/module/path from the root of the project (indicating the path to the module in which we have main) and the goshka will collect everything, at the same time write versions of all your dependencies, allowing for repetitive builds.

I
index0h, 2019-09-30
@index0h

You don't have much of a choice.
1. Select GOPATH, but this is an obsolete path.
2. Rely on the "official experiment" dep.
3. Do not take the concept of "module" to heart.
vgo is just such a composer for golang, and it is developed along with the compiler

C
coolstudent, 2019-10-10
@coolstudent

Thanks everyone for the replies. Really on modules understood. I also downloaded the project from the project library on the language site which was organized as a module and it downloaded the dependencies normally and assembled outside the gopas.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question