Create from Visual Studio Code
Overview
Once Golang is installed, we can formally enter golang for development. The two current mainstream editors are Goland VSCode, which will describe how to create a golang project using VSCode.
VScode download reference VSCode official net
:::Note taps Current document demo version is Version: 1.74.1 (Universal)
, this may be different if your VScode version is not consistent. :::
Install Go Extension
Open VScode,click on the left extension button, search Go
and install it.
Create Go Project
Open VScode and click Open...
in the workspace, select the specified directory or create a new folder as a project directory. Here I choose to create a new folder hellowd
, return to the project.
Create go module
In the top right corner of VScode, select Toggle Panel
or use shortcuts Command + J
, Strike Terminal
, enter go into the terminal and init helloowold
, go back and create a go module.
New main.go
Create a new main.go
file in the project directory HELLOWORLD
, and enter the following code:
package main
import "fmt"
func main() {
fmt.Println("Hello World!")
}
Run program
In the upper right corner of VScode, select Toggle Panel
or use shortcut Command + J
, click Terminal
, enter go run main.go
, go back, run the program.
$ go run main.go
Hello World!