Go Lang 1.13
MacOS Mojave 10.14.6
环境变量
GOROOT
Go Lang 安装目录
GOPATH
Go 命令环境依赖,其中主要目录:
- bin 可执行相关
- pkg 编译包相关
- src 源码包相关
GO111MODULE
GO111MODULE=auto
$GOPATH/src
步骤1:初始化环境
1.创建项目
package main
import (
"fmt"
)
func main() {
fmt.Println("Hello, world!")
}
2.初始化模块
# go mod init hello
hellogo.modgo.sum
go.modgo.sum
➜ # go mod tidy
hello2 imports
hello/utils: malformed module path "hello/utils": missing dot in first path element
模块名路径
import (
"hello/utils"
"github.com/astaxie/beego"
)
helloutilsgithub.comastaxie/beego
注意:相同路径下仅能声明一个包
步骤2:配置VSCode
4.安装 VSCode-Go 插件, 添加一下配置:
"go.useLanguageServer": true,
"[go]": {
"editor.snippetSuggestions": "none",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true,
}
},
"gopls": {
"usePlaceholders": true, // add parameter placeholders when completing a function
// Experimental settings
"completeUnimported": true, // autocomplete unimported packages
"deepCompletion": true, // enable deep completion
}