In this blog post, we’ll look at the environment where Golang is installed on A Windows system and develop Golang using IDEA to install the Go plug-in.
Golang profile
Golang, or Go, is a statically strongly typed, compiled language developed by Robert Griesemer, Rob Pike, and Ken Thompson at Google. Go language syntax is similar to C, but the function has: memory safety, GC (garbage collection), structure and cSP-style concurrent calculation.
Golang environment installation
Golang can be downloaded from studygolang.com/dl
Our first choice is to visit the official website and download the Golang installation package for the operating system. In this case, we chose the Windows version.
After downloading the installation package, you can install it directly and install it all the way to next. After the golang installation is complete, run the go version command to view the golang version. If the version number is displayed, golang is successfully installed.
Golang environment variable configuration
Three environment variables need to be configured in Golang, which are:
- GOROOT: The installation directory of Golang
- PATH: indicates the bin directory in the Golang installation directory
- GOPATH: Golang’s project directory
[Note] We configure GOROOT and PATH to the system environment variables, but GOPATH we do not directly configure a fixed configuration in the system variables, because we may create multiple Golang projects in a system, and each project will need to configure a GOPATH variable. This is obviously tedious and very difficult to manage, so when we create a project, we configure the GOPATH variable directly through the IDE at project creation time, so that each Golang project can be configured with the corresponding GOPATH path.
The environment variables for GOROOT are as follows:
The PATH environment variables are configured as follows:
If you are using an MSI installation package to install Golang, this information will be automatically configured for you during installation whenever you use Golanggo version
Being able to view the version information indicates that Golang has been configured successfully and that these variables have been configured. If you are using zip decompression, you will need to manually configure these environment variables.
IDEA Install the Go plug-in
If we want to use IDEA for Golang development, then we need to download a Go plug-in, otherwise Golang development cannot be carried out. IDEA automatically integrates the Go plug-in. We just need to download and install it on IDEA. Let’s go to the plug-in download screen: File — Settings — Plugins
IDEA development Golang
Create a Golang project
Configure the GOPATH environment variable
After creating the project, open the project and select File — Settings — Languages&Frameworks — Go — GOPATH to configure the GOPATH path for the project.
Hello World
The Golang project code is all in the SRC directory under the GOPATH path, so we create a SRC directory directly under the project to store our Golang source code.
The project directory structure is as follows:
action.go
package person
import "fmt"
func Say(a) {
fmt.Println("I'm talking.")}Copy the code
main.go
package main
import (
"com/person"
"fmt"
)
func main(a) {
fmt.Println("Hello World!")
person.Say()
}
Copy the code
The results