IDEA integrates GO and creates module projects

Installation package

1. Go to the official website to download the corresponding installation package and go to
the official website download address

The window version I chose to download:
Insert image description here
directly follow the corresponding directory, and then click Next

Environment configuration

1. Configure go environment variables.
Add the **/bin directory of the installation package in the advanced environment variable PAHT. Refer to the picture.
My installation address: C:\Program Files\go\go1.20.4. The specific address is changed according to the directory specified by you.
Insert image description here
The installation is completed. After that, cmd to check the corresponding version

go version

The following output indicates successful installation
Insert image description here

idea configuration and create test mode

1. Idea first download the go plug-in
idea->plugins-> search for go keywords.
Insert image description here
After installing the plug-in, go to the next step.

1. Open idea->settings->languages ​​& frameworks->go.
Here you need to configure the GOROOT and GOPAHT addresses for specific reference pictures.
Insert image description here
Insert image description here
If an error is prompted when specifying the local SDK,
GoLand cannot load the local Go. The selected directory is not a valid home for Go SDK.

After configuration, you can proceed to the next step~

2. Create GO module
idea->file->new->module , click next,
Insert image description here
Insert image description here
and project
Insert image description here
notes after creation: src is a directory created by yourself, so don’t worry about this directory structure.

Run the program:

package main

import (
	"fmt"
)

func main() {
    
    
	fmt.Print("hello")
	print("e")
}

Output results

GOROOT=C:\Program Files\go\go1.20.4 #gosetup
GOPATH=C:\Program Files\go\go1.20.4\bin #gosetup
"C:\Program Files\go\go1.20.4\bin\go.exe" build -o C:\Users\zhaoyy\AppData\Local\Temp\___go_build_test_src.exe -gcflags "all=-N -l" test/src #gosetup
C:\Users\zhaoyy\AppData\Roaming\JetBrains\IntelliJIdea2020.1\plugins\intellij-go\lib\dlv\windows\dlv.exe --listen=localhost:62213 --headless=true --api-version=2 --check-go-version=false --only-same-user=false exec C:\Users\zhaoyy\AppData\Local\Temp\___go_build_test_src.exe -- #gosetup
API server listening at: 127.0.0.1:62213
helloe
Debugger finished with exit code 0

The above is an introduction to integrating IDEA with GO language and creating projects.

Supongo que te gusta

Origin blog.csdn.net/weixin_43829047/article/details/131130393
Recomendado
Clasificación