乘风原创程序

  • GO开发环境搭建——win平台
  • 2020/8/10 17:32:04
  • 1.go安装包下载

    • 打开下载链接:https://golang.google.cn/dl/
    • 选择windows版本下载
      在这里插入图片描述
    • 打开包进行安装,一直下一步(无注意事项)
    • 验证是否安装成功
    go version
    

    或者

    go env
    

    在这里插入图片描述

    2.开发工具VS Code 配置

    • 下载安装

    • 汉化包
      在这里插入图片描述

    • 安装go语言插件
      在这里插入图片描述
      安装完成后,重启vscode

    敲代码的时候,vs会有其他工具安装提示,全部选择安装即可(如若失败,可切换手机热点,多次进行)
    在这里插入图片描述
    安装不成功,如下图所示,这是因为
    golang.org在国内被墙了,根本无法下载golang.org的安装包和源码包,以及类库。

    Installing 14 tools at F:\Softs\GoLang\repository
      gocode
      gopkgs
      go-outline
      go-symbols
      guru
      gorename
      gomodifytags
      goplay
      impl
      godef
      goreturns
      golint
      gotests
      dlv
    
    Installing github.com/nsf/gocode FAILED
    Installing github.com/uudashr/gopkgs/cmd/gopkgs SUCCEEDED
    Installing github.com/ramya-rao-a/go-outline FAILED
    Installing github.com/acroca/go-symbols FAILED
    Installing golang.org/x/tools/cmd/guru FAILED
    Installing golang.org/x/tools/cmd/gorename FAILED
    Installing github.com/fatih/gomodifytags FAILED
    Installing github.com/haya14busa/goplay/cmd/goplay SUCCEEDED
    Installing github.com/josharian/impl FAILED
    Installing github.com/rogpeppe/godef SUCCEEDED
    Installing sourcegraph.com/sqs/goreturns FAILED
    Installing github.com/golang/lint/golint FAILED
    Installing github.com/cweill/gotests/... FAILED
    Installing github.com/derekparker/delve/cmd/dlv SUCCEEDED
    
    

    解决方法

    1、切换到 %GOPATH%/src/github.com目录下,我的%GOPATH%是 F:\Softs\GoLang\repository,如果 github.com目录下面没有golang请自行创建
    2、完成目录切换后,开始下载插件包: git clone https://github.com/golang/tools.git tools
    3、将下载的tools目录文件夹拷贝到%GOPATH%\src\golang.org\x\下,如果没有相关路径自行创建
    4、我们将上面无法安装成功的包,手动安装,由于每个人可能安装成功的不一样,可以全部执行,将目录切换到%GOPATH%下执行下面代码

    先下载

    go get -v -u github.com/nsf/gocode
    go get -v -u github.com/uudashr/gopkgs/cmd/gopkgs 
    go get -v -u github.com/ramya-rao-a/go-outline 
    go get -v -u github.com/acroca/go-symbols 
    go get -v -u golang.org/x/tools/cmd/guru 
    go get -v -u golang.org/x/tools/cmd/gorename 
    go get -v -u github.com/fatih/gomodifytags 
    go get -v -u github.com/haya14busa/goplay/cmd/goplay 
    go get -v -u github.com/josharian/impl 
    go get -v -u github.com/rogpeppe/godef 
    go get -v -u sourcegraph.com/sqs/goreturns 
    go get -v -u github.com/golang/lint/golint 
    go get -v -u github.com/cweill/gotests/... 
    go get -v -u github.com/derekparker/delve/cmd/dlv
    
    

    然后安装

    go install github.com/acroca/go-symbols
    go install github.com/cweill/gotests
    go install github.com/cweill/gotests/gotests
    go install github.com/golang/lint/golint
    go install github.com/lukehoban/go-outline
    go install github.com/newhook/go-symbols
    go install github.com/nsf/gocode
    go install github.com/ramya-rao-a/go-outline
    go install github.com/rogpeppe/godef
    go install github.com/sqs/goreturns
    go install github.com/tpng/gopkgs
    go install github.com/zmb3/gogetdoc
    go install golang.org/x/tools/cmd/gorename
    go install golang.org/x/tools/cmd/guru
    go install sourcegraph.com/sqs/goreturns
    
    • 创建go文件
      菜单栏~菜单 ~打开文件夹 ~ 选择项目根目录

      在根目录下,创建go文件

    • 运行go文件

    在这里插入图片描述- 编译go文件
    在这里插入图片描述

    本文地址:https://blog.csdn.net/qq_25212845/article/details/107890534