zoukankan      html  css  js  c++  java
  • vscode 配置 golang开发环境

     

    如果你使用golang,那么强烈建议你采用vscode作为IDE。


    image

    1. 首先在vscode 当中安装go插件,如上图

    2. 配置 %AppData%CodeUsersettings.json 当中的参数

       go.goroot; go.toolsGopath 这两个参数一定要配置上

       vscode配置有两种user,workspace

       user是全局生效,针对所有项目

       workspace仅针对当前项目,如果与user当中的配置不一样,在当前项目中使用workspace的配置   

    "go.formatTool": "goformat",
    "go.goroot": "D:\sdk\go",
    "go.toolsGopath": "D:\sdk\gotools",
    "go.inferGopath": true,
    "go.gotoSymbol.includeGoroot": true,
    "go.gotoSymbol.includeImports": true, 
    "go.useLanguageServer": true,
    "go.autocompleteUnimportedPackages": true,
    "go.coverOnTestPackage": false,

       将上面的配置增加到 settings.json 当中,然后重启vscode

    3. ctrl+shift+p 调出go的命令窗口,然后选择 Go: Install/Update tools

       为什么一定要安装这些工具呢?

       没有这些工具,代码导航、格式化等这些常用功能都不能用,开发的效率和体验会非常不好

    image

    4. 选中所有的工具后,点击OK按钮

    image

    5. 等待下载安装完成即可

     


    错误处理:

    Installing github.com/mdempsky/gocode FAILED

    Installing github.com/uudashr/gopkgs/cmd/gopkgs FAILED

    Installing github.com/ramya-rao-a/go-outline FAILED

    Installing github.com/acroca/go-symbols FAILED

    Installing golang.org/x/tools/cmd/guru FAILED

    国内特殊环境引起的,需要自行解决!
    不过,在golang的最新版本中支持使用代理,使用方法如下

    go env -w GOPROXY=https://goproxy.io,direct

     

    如果全部成功将显示下面的提示:

    Installing github.com/mdempsky/gocode SUCCEEDED

    Installing github.com/uudashr/gopkgs/cmd/gopkgs SUCCEEDED

    Installing github.com/ramya-rao-a/go-outline SUCCEEDED

    Installing github.com/acroca/go-symbols SUCCEEDED

    Installing golang.org/x/tools/cmd/guru SUCCEEDED

    Installing golang.org/x/tools/cmd/gorename SUCCEEDED

    Installing github.com/cweill/gotests/... SUCCEEDED

    Installing github.com/fatih/gomodifytags SUCCEEDED

    Installing github.com/josharian/impl SUCCEEDED

    Installing github.com/davidrjenni/reftools/cmd/fillstruct SUCCEEDED

    Installing github.com/haya14busa/goplay/cmd/goplay SUCCEEDED

    Installing github.com/godoctor/godoctor SUCCEEDED

    Installing github.com/go-delve/delve/cmd/dlv SUCCEEDED

    Installing github.com/stamblerre/gocode SUCCEEDED

    Installing github.com/rogpeppe/godef SUCCEEDED

    Installing winterdrache.de/goformat/goformat SUCCEEDED

    Installing golang.org/x/lint/golint SUCCEEDED

    Installing golang.org/x/tools/gopls SUCCEEDED

     

    Reload VS Code window to use the Go language server

    All tools successfully installed. You're ready to Go :).

  • 相关阅读:
    两栏自适应布局
    说说bfc 和 HasLayout
    春联式弹动广告
    Centos7安装完毕后重启提示Initial setup of CentOS Linux 7 (core)的解决方法
    2016年新剧《欢乐颂》里面的经典台词
    硬盘怎么保养
    如何保养与维护笔记本硬盘
    仔细看完,你会成为微信高手
    电脑之间用网线直接连接起来快速传送大文件技巧
    阿里云9折优惠码 GQH4IT 使用方法如下:
  • 原文地址:https://www.cnblogs.com/russinovich/p/11820098.html
Copyright © 2011-2022 走看看