Go development environment settings

1. Installation

Reference go language Chinese website

test

$ go version
go version go1.14 darwin/amd64

Two, set up the environment

1. Set up domestic mirror

$ go env -w GOPROXY=https://goproxy.cn,direct

Domestic mirroring means that the user installs a third-party library,
directwhich means that when the previous proxy server cannot provide a library, go to Github to obtain it.

2. Open gomodule

$ go env -w GO111MODULE=on

3. Install goimorts

Command goimports to update your Go import lines, add missing lines and delete unreferenced lines.
In addition to repairing the import, goimport also formats the code in the same style as gofmt, so it can replace the gofmt hook of the editor.

$ go get -v golang.org/x/tools/cmd/goimports

Use the "-v" verbose flag to verify that it is working properly and see what goimports is doing.

Three, Go integrated development environment IDLE

1. idea + go plugin or Goland

idea download address-official website

IDEA

Goland

2. VSCode

https://code.visualstudio.com/
image.png

VSCode will refer to the file extension and recommend the plug-ins that should be installed.

Create project

vscode does not support creating projects directly, you can create a folder in a certain location first.
Then in this folder, execute the following command to initialize a Gomodule project.

$ mkdir  learngo  # 创建项目目录

$ cd learngo

$ go mod init learngo
go: creating new go.mod: module learngo

$ ls
go.mod

$ cat go.mod
module learngo

go 1.14

$

Then open this folder in VSCode learngo

image.png

Next, create a hello.gofile, and add the following

package main

import "fmt"

func main() {
	fmt.Println("hello world")
}

Next, open a terminal

image.png

Execute the following command to run this program

$ go run hello.go 

image.png

Recommended installation Code Runnercreated click to run code program

image.png

Guess you like

Origin blog.csdn.net/qq_22648091/article/details/109182605