GO language introduction and development environment configuration

I. Introduction

GO is a static language strongly typed language

Static is a compiled language

II. Installation

1. Download

Download https://golang.google.cn/dl/

2. Install

Linux installation

1, download binaries: go1.13.3.linux amd64.tar.gz-
2, the downloaded binary extracted the / usr / local directory.

tar -C /usr/local -xzf go1.13.3.linux-amd64.tar.gz

3, add / usr / local / go / bin directory to the PATH environment variable:

export PATH=$PATH:/usr/local/go/bin

Windows Installation

Under Windows you can use .msi suffix (download list can be found in the file, such as go1.13.3.windows-amd64.msi) installation package to install.
By default, the .msi files will be installed in c: \ Go directory. You can c: \ Go \ bin directory to the Path environment variable. After adding a command window you need to restart to take effect

Mac installation

Double-click the Mac under the direct go1.13.3.darwin-amd64.pkg, all the way to the next installation

3. Install a successful test

test.go

//hello world
//单行注释
/*
多行注释
多行
 */
package main   //表示main包 (每一个go文件,必须隶属于一个包)

import "fmt"  //表示导入fmt包(打印相关)

func main() {  //表示main函数
   fmt.Println("Hello, World!")  //表示在控制台输出
}

cmd run command

go run test.go        

4. Supplement

go execution

-先编译,再执行
-编译:go build s1.go    得到s1.exe
-执行:s1.exe
-编译并执行:go run s1.go

III. Some introduction to post-installation

View Configuration

go env
#显示的内容
'''
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Administrator\AppData\Local\go-build
set GOENV=C:\Users\Administrator\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\Administrator\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=c:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\ADMINI~1\AppData\Local\Temp\go-build909065030=/tmp/go-build -gno-record-gcc-switches
'''

The key configuration information

  • GOPATH: go to store the code path, go all code must be placed in the src folder gopath
  • GOROOT: go installation path built-in packages, you need to go down the path to find

Modify these configurations

set 配置的名称=配置的值

Guess you like

Origin www.cnblogs.com/pythonywy/p/11883245.html