Go语言基础—开发工具与环境配置
一、 VS code开发工具:
1、 配置语言选择Chinese 2、安装Go开发工具
二、项目初始化
终端输入:
go mod init 项目名称
显示go相关信息,引用的包名等信息
module GOlandProjects
go 1.18
三、新建项目文件main.go
package main
import "fmt"
func main() {
fmt.Println("Hello world!")
}
四、编译go文件
终端输入:
go build
go build -o xxx.exe
五、执行EXE文件
终端运行
hello.exe
go run main.go
六、切换编译的目标平台
cmd指定环境变量
SET CGO_ENABLED=0 // 禁用CGO
SET GOOS=linux // 目标平台是linux
SET GOARCH=amd64 // 目标处理器架构是amd64
PowerShell指定环境变量
$ENV:CGO_ENABLED=0
$ENV:GOOS="linux"
$ENV:GOARCH="amd64"
七、查找依赖包
go mod tidy
package main
import (
"fmt"
"github.com/q1mi/hello"
)
func main() {
fmt.Println("Hello world!")
hello.SayHi()
}