01 – initial golang

Time:2022-1-6

1 why learn golang

Generally, a new language appears to solve the defects of the existing language on the market. In other words, make a new balance between development efficiency, execution efficiency and resource occupation. For example, a language requires high development efficiency, high execution efficiency and less resource occupation. At present, this is an impossible problem. We can only make a balance between them, so at this timegolangIt has the characteristics of rapid development (compared with C + +), efficient execution (compared with Python) and less resource occupation (compared with Java). If you think C language and C + + are too difficult, python execution efficiency is too low, it is difficult to find a job as a first language, and Java is too heavy, then come and learn golang.

2. Establishment of golang environment (windows10)

2.1 download and install go language

reach https://studygolang.com/dl Download go installation package
image.png
The next step is to install them all. After installation, you can view the installation results through the following commands:

go version
image.png

go env
image.png

2.2 environment variable configuration

2.2.1 GOROOT

Goroot points to the installation root directory of golang

2.2.2 GOPAHT

Gopath points to our development platform, which has three directoriesbinpkgsrc

  • Bin: contains executable files
  • PKG: contains package files or library files
  • SRC: contains the source code files

We can create a new directory, create the above three subdirectories, and point gopath to it.

image.png

image.png

3 helloworld

stayGOPATHCreate a hello directory in the subdirectory SRC of, and create a hello directory in the Hello directoryhello.goThe go code in the file is:

package main

import "fmt"

func main() {
    fmt.Printf("helloworld")
}

Use the terminal to enter the Hello directory, and then build the compiler

C:\wfq\work\gojob\src\hello> go build

An executable file is then generatedhello
image.png
Execute the file
image.png

Recommended Today

Redis Client On Error: Error: write ECONNABORTED Config right

Solve the redis client on error: error: write econnaborted config rightwe Problem Description: Solution: 1. First, check whether the firewall of Linux is turned on Turn off the firewall [[email protected]]# systemctl stop firewalld.service Open 6379 port number [[email protected]]# sudo firewall-cmd –zone=public –add-port=6379/tcp –permanent success [[email protected]]# sudo firewall-cmd –reload success 2. Check whether the redis startup […]