In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > IT Information >
Share
Shulou(Shulou.com)11/24 Report--
A programming language full of vitality must be constantly evolving. As the Go project continues to evolve, there will be a number of small iterations within each major version. For the version update of Go, how do we do a lot of version management.
The importance of multi-version management here are a few reasons why we need Go multi-version management.
Stability considerations: although Go1 has been well adhering to the backward compatibility guidelines, we usually do not upgrade directly to the latest version for stability reasons.
Multi-project development: the version of Go that each project depends on is inconsistent.
Version compatibility: testing code compatibility before and after, or ensuring that bug fixes are correct in different Go versions, is important for open source projects to ensure version compatibility.
We need two prerequisites for how to manage multiple versions.
A certain version of Go has been installed
Git is installed.
Installation
Running the go install golang.org/ dl / go command downloads the wrapper for a specific version of Go.
Go install golang.org/dl/go@latest downloads a specific Go version and its corresponding tool chain through a wrapper.
$go download, for example, installs version 1.14.12, which can be done like this.
$go install golang.org/dl/go1.14.12@latest$ go1.14.12 download use
Using the wrapper go1.14.12, we can build and test based on Go v1.14.12.
$go1.14.12 mod init hellogo: creating new go.mod: module hello$ echo 'package main; import "fmt"; func main () {fmt.Println ("Hello, World")}' hello.go$ go1.14.12 build$. / helloHello, World, of course, if you want Go v1.14.12 to be the face of the go command, you can do so.
The go1.14.12 env GOROOT path of $go versiongo version go1.17 darwin/64$ export GOROOT=$ (go1.14.12 env GOROOT) $export PATH=$ {GOROOT} / bin:$PATH$ go versiongo version go1.14.12 darwin/64 is the content of Go v1.14.12. So, if we want to uninstall this version, just delete the path folder; if you want to read the source code of this version, just look at the src / content under the path.
Get the latest development version
There is a special version tag: gotip, which is used to install the latest development version.
As you can see from go install golang.org/dl/gotip@latest$ gotip download, the latest development version currently pulled is go1.18-1afa432.
The secret of implementing multi-version download and installation lies in https://go.googlesource.com/ dl, whose mirror library is https://github.com/ golang / dl.
Looking at the warehouse code, we can see a series of version directories
If you choose a version to enter at random, you will find that there is a main.go file.
The contents of the main.go file are as follows
The go1.14.12 wrapper we downloaded through go install golang.org/ dl / go1.14.12@latest is compiled from this main.go.
Therefore, the logic we later download and run through the go1.14.12 wrapper lies in the Run method in the internal / version package.
/ / Run runs the "go" tool of the provided Go version.func Run (version string) {log.SetFlags (0) / / get the Go installation directory root, err: = goroot (version) if err! = nil {log.Fatalf ("% s:% v", version, err)} / / logical if len (os.Args) = = 2 & & os.Args [1] = "download" {if err: = install (root, version) Err! = nil {log.Fatalf ("% s: download failed:% v", version, err)} os.Exit (0)} / / determine the installation status of this version of Go if _, err: = os.Stat (filepath.Join (root, unpackedOkay)); err! = nil {log.Fatalf ("% s: not downloaded. Run'% s download' to install to% v ", version, version, root)} / / run this version of Go runGo (root)} due to the space, the downloaded install and the running runGo functional logic article will no longer be expanded, students who want to know more can explore on their own.
In addition, in order to have a Go wrapper main program for each version (to avoid repetitive manual operations), a help command genv is used here: you can quickly generate the corresponding version of the wrapper code / main.go. For the implementation here, see the internal / genv / main.go code.
Summary this paper introduces the multi-version management solution provided by Go officially, including use, installation, uninstallation, etc., you can feel its simplicity and efficiency. At the same time, we briefly looked at this set of implementation code logic.
Finally, I hope this article will help you make good use of Go multi-version management.
This article comes from the official account of Wechat: Golang Technology sharing (ID:GolangShare), author: machine bell chopping kitchen knife
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.