go command should say exactly which versions of which packages are in a particular build.go will not use them without a special command.go command: it is simplicity, speed and clarity. Today, many programmers do not pay attention to the version, and everything works fine. If you make the right model, the programmers will still not pay attention to the version numbers, everything will just work better and become clearer. Existing workflows remain virtually unchanged. The release of new versions is very simple. In general, versioning should go into the background and not take the attention of the developer.go get . In this article, we offer how to do this, as well as demonstrate a prototype that you can try right now, and which I hope will be the basis for a possible go integration. I hope the article will be the beginning of a productive discussion about what works and what does not. Based on this discussion, I will make adjustments to both my proposal and the prototype, and then I will submit a formal proposal to add an optional function to Go 1.11.go get , but adds reproducible assemblies, supports semantic versioning, eliminates vending, removes GOPATH in favor of a project-based workflow, and provides a smooth departure from dep and its predecessors. However, this proposal is still at an early stage. If the details are not correct, we will correct them before the work gets into the main distribution Go.Makefile , goinstall and go get6g and 6l , and we included examples of makefiles in the package. A minimal gobuild shell could build one package and write the appropriate makefile (in most cases). There was no fixed way to share the code with others. We knew that this was not enough - but we released what we had, planning to develop the rest together with the community.Goinstall introduced conventions on import paths, which are now generally accepted. But while no code followed these conventions, goinstall initially only worked with packages that imported nothing but the standard library. But developers quickly moved to a single agreement that we know today, and the set of published Go packages has grown into a coherent ecosystem.go vet or auto-completion can also be quite complex. Even getting dependencies right to re-build packages if necessary and only when necessary is much more difficult with arbitrary Makefiles. Although at that time some objected that they were deprived of flexibility, but looking back, it became clear that the refusal of the Makefile was the right step: the benefits far outweigh the inconvenience.goinstall with go get .go get introduced significant changes: it allowed Go developers to share source code and use each other's work. He also isolated the parts of the assembly system within the go command, so that considerable automation was possible with the help of tools. But go get is missing the version control concept. In the very first goinstall discussions, it became clear: you need to do something with version control. Unfortunately, it was not clear what to do. At least, we in the Go team did not clearly understand this. When go get requests a package, it always gets the latest copy, delegating download and update operations to a version control system, such as Git or Mercurial. This “blind work” has led to at least two significant shortcomings.go get is that without the concept of version control, it cannot tell the user what changes to expect in this update.Packages for general use must maintain backward compatibility as they evolve. Go 1 compatibility guidelines are relevant here: do not delete exported names, encourage tagging of composite literals, and so on. If new functionality is required, add a new name, but do not change the old one. In case of a major change, create a new package with a new import path.
gopkg.in/yaml.v1 and gopkg.in/yaml.v2 for different commits (possibly in different branches) of the same Git repository. According to semantic version control, authors should release a new basic version when making critical changes. Thus, later versions of the v1 import path replace the previous ones, and v2 can render completely different APIs.The contract of your API becomes unimportant with a sufficient number of users. Someone depends on any observed behavior of the system.
go get is that without the concept of version control, the team cannot provide and even express the idea of ​​a replicable build. It’s impossible to make sure that users compile the same code dependency versions as you. In November 2013, the following advice was added to the FAQ for Go 1.2:If you use an external package and fear that it may change unexpectedly, the simplest solution is to copy it to your local repository (this is the approach used by Google). Save a copy with a new import path that identifies it as a local copy. For example, you can copyoriginal.com/pkgtoyou.com/external/original.com/pkg. One of the tools for this procedure isgovenKeith Rarik.
goven utility copies the dependency to the local repository and updates all import paths to reflect the new location. Such source code changes are necessary, but unpleasant. They make it difficult to compare and include new copies, and also require updating other copied code using this dependency.godep was what we now call vendoring, i.e., copying dependencies into a project without changing the source files, without direct support of tools, by means of a certain GOPATH setting.godep -style godep . Matt Farina published the post “Traveling by Sea Go godep Managers”, comparing godep with godep , especially glide .go command. At the same time, Daniel Theophanes began preparing specifications for a file format that describes the exact origin and version of the code in the vendor catalog. In June 2015, we accepted Keith’s offer as a vendoring experiment in Go 1.5 , which was included by default in Go 1.6. We encouraged the authors of all the tools for vendoring to work with Daniel to adopt a single metadata file format.vet more competently analyze programs, and today it is used by about a dozen or two package managers or tools of vending. On the other hand, since everyone has different metadata formats, they do not interact and cannot easily exchange information about dependencies.glide and dep implicitly add the concept of version control to Go, in a certain way setting up the vendor directory. As a result, many of the tools in the Go ecosystem are not able to get the correct version information. It is clear that Go needs direct support for package versions.Dep performs many tasks: this is an important improvement over current practices. This is an important step towards a future solution, and at the same time an experiment - we call it “official experiment” - which helps us to better understand the needs of developers. But dep not a direct prototype for the possible integration of go commands into package versioning. This is a powerful, flexible, almost universal way to explore design solution space. It is similar to the makefiles we fought at the very beginning. But as soon as we better understand the design decision space and narrow it down to several key functions that need to be supported, it will help the Go ecosystem to remove other functions, reduce expressiveness, adopt mandatory conventions that make Go code bases more uniform and easy to understand.dep : the first prototype of the final integration with the go command, the package equivalent of goinstall . The prototype is a separate command that we call vgo : a go replacement with support for version control packages. This is a new experiment, and we'll see what comes of it. As well as during the goinstall announcement, some projects and code are already compatible with vgo , while others need changes. We will remove some control and expressiveness, just as the makefiles were removed in due time, in order to simplify the system and eliminate the complexity for users. Most importantly, we are looking for pioneers who will help experiment with vgo to get as many reviews as possible.vgo does not mean the termination of support for dep : it will remain available until we achieve full and public integration with go . We will also try to make the final transition from dep to integration with go as smooth as possible, in whatever form this integration takes place. Projects that have not yet been converted to dep can still benefit from this transformation (note that the godep and glide stopped their active development and encourage migration to dep). Some projects may wish to go directly to vgo , if that suits their needs.go command consists of four steps. First, accept the import compatibility rule , which is indicated by the FAQ and gopkg.in: newer versions of the package with the specified import path must be backward compatible with older versions. Second, adopt a simple new algorithm, known as choosing the minimum version to determine which versions of the package are used in this assembly. Third, introduce the concept of a Go module : groups of packages, versioned as a whole and declaring minimum requirements that must be satisfied by their dependencies. Fourth, determine how to integrate all this into the existing go command so that the main workflows do not change significantly from today. In the rest of the article, we consider each of these steps. They are discussed in more detail in other blog articles .If the old and new packages have the same import path, the new package must be backward compatible with the old package.
import "github.com/go-yaml/yaml/v2" dep cargo , . , . -, « » - , - . , - , , , . -, , , «, X», X .go.mod , . , go.mod : // My hello, world. module "rsc.io/hello" require ( "golang.org/x/text" v0.0.0-20180208041248-4e4a3210bb54 "rsc.io/quote" v1.5.2 ) rsc.io/hello , : golang.org/x/text rsc.io/quote . , go.mod . , - .vgo , . rsc.io/quote , github.com/rsc/quote , , 1.5.2. golang.org/x/text . , v0.0.0-yyyymmddhhmmss-commit . v0.0.0 yyyymmddhhmmss-commit . , v0.0.0, . , .go.mod , , , . .Goinstall go get , git hg , , . , bzr Bazaar. , Go HTTP zip-. go get . vgo API .go.mod , , .gogo . , , go build , go install , go run go test , . golang.org/x/text Go .go.mod , , go.mod , , . git clone , cd , . . GOPATH.vgo . , vgo . . .go.mod . , go.mod , dep , glide , glock , godep , godeps , govend , govendor gvt , vgo go.mod .go get , GOPATH GOPATH. .vgo . , Go 1.11 Go, , Go 1.12 . , go get . , , .go get . , . , , .Source: https://habr.com/ru/post/442272/
All Articles