zoukankan      html  css  js  c++  java
  • Go语言环境安装篇

    回家想重新学习下go的源码,然后在win上安装问题多多,遂整理一下

    一、Go安装包下载地址:

    国情原因 https://golang.org/ 偶尔会访问不了,新手要下载 Go 官方的提供的安装包经常会受阻。解决方法是使用可信任的其他镜像进行下载,推荐这两个:

    https://golang.google.cn/dl/
    https://gomirrors.org/

     二、路径配置:

    win下:

        下载后直接双击msi文件安装,默认安装在C:Program FilesGo
        安装完成后默认会在环境变量 Path 后添加 Go 安装目录下的 bin 目录 C:Program FilesGoin,并添加环境变量 GOROOT,值为 Go 安装根目录 C:Program FilesGo
        验证是否安装成功,在运行中输入 cmd 打开命令行工具,在提示符下输入 go

        

    添加国内代理,否则很多包无法下载:

       将Go默认的代理替换为以下代理:

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

     三、IDE的选择和设置:

    目前可选的IDE有很多,如VsCode,goland,subline等,强烈推荐用Vscode,然后使用glide做包管理。

    vs插件安装

          

       vscode-go 配置

        settins.json 基本上不需要配置,用默认值就可以了。如需调整 文件 -->首选项 -->设置 输入go即可查看go相关配置

    {
        "git.ignoreLimitWarning": true,
        //开启自动保存
        "files.autoSave": "onFocusChange",
        "go.buildFlags": [],
        "go.lintFlags": [],
        "go.useCodeSnippetsOnFunctionSuggest": false,
        "[go]": {
            "editor.insertSpaces": false,
            "editor.formatOnSave": true
        },
        "go.formatTool": "goreturns",
        "go.goroot": "C:\Go",
        "go.gopath": "D:\GoPath"
    }
    

      

    安装GO相关组件:

          官方文档说明 https://github.com/Microsoft/vscode-go/wiki/Go-tools-that-the-Go-extension-depends-on
          vscode也可以通过ctrl+shift+p 运行命令一次性安装所有这些工具

           Go: Install/Update Tools

    然后呢,在下载go的相关包的过程中遇到问题:

      由于各种原因下载不下来,于是重新手动下载下载

    解决方案:

              

    // 进入该目录下的src目录
    cd $GOPATH/src
    
    //创建github.com插件目录及下载插件
    cd $GOPATH/src
    mkdir github.com
    cd $GOPATH/src/github.com
    mkdir acroca cweill derekparker go-delve josharian karrick mdempsky pkg ramya-rao-a rogpeppe sqs uudashr
    cd $GOPATH/src/github.com/acroca
    git clone https://github.com/acroca/go-symbols.git
    cd $GOPATH/src/github.com/cweill
    git clone https://github.com/cweill/gotests.git
    cd $GOPATH/src/github.com/derekparker
    git clone https://github.com/derekparker/delve.git
    cd $GOPATH/src/github.com/go-delve
    git clone https://github.com/go-delvedelve.git
    cd $GOPATH/src/github.com/josharian
    git clone https://github.com/josharian/impl.git
    cd $GOPATH/src/github.com/karrick
    git clone https://github.com/karrick/godirwalk.git
    cd $GOPATH/src/github.com/mdempsky
    git clone https://github.com/mdempsky/gocode.git
    cd $GOPATH/src/github.com/pkg
    git clone https://github.com/pkg/errors.git
    cd $GOPATH/src/github.com/ramya-rao-a
    git clone https://github.com/ramya-rao-a/go-outline.git
    cd $GOPATH/src/github.com/rogpeppe
    git clone https://github.com/rogpeppe/godef.git
    cd $GOPATH/src/github.com/sqs
    git clone https://github.com/sqs/goreturns.git
    cd $GOPATH/src/github.com/uudashr
    git clone https://github.com/uudashr/gopkgs.git
    
    // 创建golang.org插件目录及下载插件
    cd $GOPATH/src
    mkdir -p golang.org/x
    cd golang.org/x
    git clone https://github.com/golang/tools.git
    git clone https://github.com/golang/lint.git
    
    // 手动安装插件
    cd $GOPATH/src
    go install github.com/mdempsky/gocode
    go install github.com/uudashr/gopkgs/cmd/gopkgs
    go install github.com/ramya-rao-a/go-outline
    go install github.com/acroca/go-symbols
    go install github.com/rogpeppe/godef
    go install github.com/sqs/goreturns
    go install github.com/derekparker/delve/cmd/dlv
    go install github.com/cweill/gotests
    go install github.com/josharian/impl
    go install golang.org/x/tools/cmd/guru
    go install golang.org/x/tools/cmd/gorename
    go install golang.org/x/lint/golint 

    检查插件是否安装成功

            打开(最好重启一下vs code) Visual Studio Code,在go文件中引入一个包,并写出“包名.”会有方法提示,例如:我这里引入的是“math/rand”包,当我写“rand”的时候会有下图的提示,那就说明插件安装成功了。

  • 相关阅读:
    [运维-安全]CentOS7.0环境下安装kangle和easypanel
    (转)FastDFS文件存储
    使用mybatis-generator-core自动生成代码
    SSM框架中常用的配置文件
    Spring MVC文件上传和下载
    Spring MVC-拦截器
    Spring MVC之JSON数据交互和RESTful的支持
    Spring MVC数据绑定(二)
    Spring MVC数据绑定(一)
    Spring MVC简介
  • 原文地址:https://www.cnblogs.com/lvpengbo/p/14406222.html
Copyright © 2011-2022 走看看