thm7x / thm7x

个人技术博客,博文写在 Issues 里。
12 stars 0 forks source link

vscode golang1.12.7 开发环境配置(goproxy代理墙外go包) #30

Open thm7x opened 5 years ago

thm7x commented 5 years ago

背景

环境:deepin15.10.1 ,go1.12.7,vscode1.36.1 🔔:有代理的话,配置vscode的http.proxy代理,直接vscode FQ。下面是没代理的做法。

Deprecated:注意下面解决方式废弃 2019-08-01 ,

因为官方出了新的golang module代理方式,优先推荐

1.1 由于goland到期。准备迁移到vscode。

vscode安装好go扩展,打开go项目时提醒go相关工具链缺失。 image

1.2 点击全部安装

image 可以看见有大部分没有安装上,原因就是网络不通请求超时。

1.3 怎么解决?

注意:项目需在gopath/src目录下,在vscode终端顺序执行如下操作即可。

$ export GO111MODULE=on
$ export GOPROXY=https://goproxy.io
$ go get -u github.com/mdempsky/gocode                     #gocode
$ go get -u github.com/uudashr/gopkgs/cmd/gopkgs     #gopkgs
$ go get -u github.com/ramya-rao-a/go-outline              #go-outline
$ go get -u github.com/acroca/go-symbols                    #go-symbols
$ go get -u golang.org/x/tools/cmd/guru                        #guru
$ go get -u golang.org/x/tools/cmd/gorename               #gorename
$ go get -u github.com/go-delve/delve/cmd/dlv             #dlv
$ go get -u github.com/stamblerre/gocode                    #gocode-gomod
$ go get -u github.com/rogpeppe/godef                        #godef
$ go get -u github.com/sqs/goreturns                           #goreturns
$ go get -u golang.org/x/lint/golint                                #golint
$ go get -u golang.org/x/tools/cmd/gopls                     #gopls

其中,gocode-gomod有可能装不上。 解决:gocode-gomod和golang.org开头的包,需找对应的github镜像源

$ git clone https://github.com/golang/tools.git  $GOPATH/src/golang.org/x/tools
$ git clone https://github.com/golang/net.git  $GOPATH/src/golang.org/x/net

1.4 关闭vscode重新打开项目,工具链已就绪O(∩_∩)O~~。

image

1.5 vscode,用户、工作区、debug等配置

用户配置操作

File->Preferences->Settings

{
 "http.proxy": "http://192.168.3.8:1087", //http_proxy和https_proxy代理,在此用户全局配置,vscode FQ
  "git.enableSmartCommit": true,
  "git.confirmSync": false,
  "git.autofetch": true,
  "files.autoSave":"onFocusChange",
  "editor.fontSize": 16,
  "terminal.integrated.fontSize": 16,
  "go.goroot": "/usr/local/go",
  "go.gopath": "/home/iwhile/gosrc",
  "go.formatTool": "goreturns",
  "go.useLanguageServer": true
}
工作区(Workspace)配置操作

修改settings.json文件内容如下

{
  "go.goroot": "/usr/local/go",
  "go.gopath": "/home/iwhile/gosrc:/home/iwhile/gosrc/src/materialLib",
  "go.formatTool": "goreturns",
  "go.useLanguageServer": true
}

注意:其中go.gopath为组合路径,若/home/iwhile/gosrc/src/materialLib项目path找不到,就去/home/iwhile/gosrc go路径去找。

debug配置操作

修改lauch.json里的program为程序入口文件绝对路径

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "运行本地调试",
            "type": "go",
            "request": "launch",
            "mode": "debug",
            "program": "/home/iwhile/gosrc/src/materialLib/MaterialLib_Server.go", 
            "env": {},
            "args": []
        },
    ]
}
thm7x commented 5 years ago

Deprecated上述方式

使用go module goproxy方式下载墙外包即可

go get代理官方方式(golang 1.12.7):

export GO111MODULE=on
export GOPROXY=https://goproxy.io