Set up a Go lang development environment under Win10 system to replace domestic sources and experience the fastest framework Iris in the universe

Set up a Go lang development environment under Win10 system to replace domestic sources and experience the fastest framework Iris in the universe

The original text is reproduced from "Liu Yue's Technology Blog" v3u.cn/a_id_156

Recently, some students have begun to try to get in touch with Go lang. It is always a good habit to embrace new technologies. The previous article introduced how to configure the Go lang development environment under Mac os . This time we will configure it under Win10 and replace it. Domestic installation sources, and finally get in touch with "the fastest web framework in the universe"-Iris. Many of my friends may not be familiar with Iris. Generally, Go lang has a reputation for relatively well-known frameworks in the web development field, such as Beego or Gin. In addition, the reason why Iris is recommended here is not because it is derived from the cool name of the ancient Greek goddess (Rainbow Goddess), but because of its powerful Go http server performance under the blessing of goroutine.

First go to the website to download the win10 installation package: studygolang.com/dl

Compared with last year, go lang has advanced two more versions. The current stable version is 1.14.4. The development momentum can be described as rapid. However, it is recommended to choose go1.12.12 version, because many frameworks do not support 1.14.4, so I recommend it here. The general stable version number is: go1.12.12.windows-amd64.msi

The installation directory is recommended to be installed in c:/go.

After the installation is successful, in the environment variables of Win10, the system should automatically configure GOROOT, GOPATH, GOBIN. Please make sure that these three variables are configured in your system. GOPATH can be understood as the development directory, GOROOT is the installation directory, and GOBIN is Executable command directory

At this time if you enter the command on the win10 command line

go version  
  
go version go1.12.12 windows/amd64
 

If the version number can be printed out, the installation is successful.

Then comes the recommendation of the editor. For beginners, I still strongly recommend vscode, because it is simple and flexible, and does not require various complicated interpreter configurations. Only two plug-ins, CodeRunner and Go, are sufficient to support your agile writing. go lang

Restart vscode

New test.go

package main  
import "fmt"  
  
func main() {  
    fmt.Println("hello go!")  
}
 

Right click "Run Code"

After the editor is configured, now we try to install some third-party libraries based on Go lang. Under normal circumstances, we use go get to install. It is somewhat similar to python's pip in use, but unfortunately, domestic users cannot Use it directly, because it is blocked, so before installing Iris, we need to replace the domestic source for go get, here we use the source of Alibaba Cloud, enter the following two commands on the command line

set GO111MODULE=on  
  
set GOPROXY=https://mirrors.aliyun.com/goproxy
 

Open the GO111MODULE module and specify the proxy address https://mirrors.aliyun.com/goproxy. It should be noted that if the computer is restarted, the source you specify will be reset, so it is best to add these two variables to the environment variable. In the setting, you can ensure permanent effect.

After that, you can use go get to install Iris, the rainbow goddess.

go get -v -u github.com/kataras/iris
 

The speed of Alibaba Cloud CDN mirroring is still very impressive

After installation, you can create a new project folder in the go installation directory and write the main.go file

package main  
   
import (  
	"github.com/kataras/iris"  
	"github.com/kataras/iris/middleware/logger"  
	"github.com/kataras/iris/middleware/recover"  
)  
   
func main() {  
	app := iris.New()  
	app.Logger().SetLevel("debug")  
	app.Use(recover.New())  
	app.Use(logger.New())  
	app.Get("/", func (ctx iris.Context){  
		ctx.HTML(" ")  
	})  
   
	app.Run(iris.Addr(":8081"), iris.WithoutServerError(iris.ErrServerClosed))  
}
 

Here we let Iris run on port 8081, enter the directory where main.go is located, and type the command

go run main.go
 

During the compilation process, an error may be reported that some dependent libraries are not found. Don t worry at this time. Repeat the go run main.go command to download the dependent libraries. After all the dependencies are installed, you can compile successfully, and finally run

Open the browser and visit http://localhost:8081/

So the installation and configuration of Iris is here, and I will share some more development experience about Iris in the future.

The original text is reproduced from "Liu Yue's Technology Blog" v3u.cn/a_id_156