zoukankan      html  css  js  c++  java
  • go_install_02_golang插件安装

    go_install_02_golang插件安装

    1.配置 golang 加速代理

    • go 全球加速代理站点: https://goproxy.io
    • 需要预先安装好 go 开发环境并配置 GOPATH GOBBIN 等环境变量
    • 在终端中执行以下命令配置代理
    # 查看 go 的环境配置
    go env
    
    # 开启代理设置,Go-1.13 以上默认启用
    go env -w GO111MODULE=on
    
    # 设置代理
    go env -w GOPROXY=https://goproxy.io,direct
    
    • 实例演示: linux 下的 go env
    GOARCH="amd64"
    GOBIN=""
    GOCACHE="/root/.cache/go-build"
    GOEXE=""
    GOHOSTARCH="amd64"
    GOHOSTOS="linux"
    GOOS="linux"
    GOPATH="/root/go"
    GORACE=""
    GOROOT="/usr/lib/go-1.10"
    GOTMPDIR=""
    GOTOOLDIR="/usr/lib/go-1.10/pkg/tool/linux_amd64"
    GCCGO="gccgo"
    CC="gcc"
    CXX="g++"
    CGO_ENABLED="1"
    CGO_CFLAGS="-g -O2"
    CGO_CPPFLAGS=""
    CGO_CXXFLAGS="-g -O2"
    CGO_FFLAGS="-g -O2"
    CGO_LDFLAGS="-g -O2"
    PKG_CONFIG="pkg-config"
    GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build086417840=/tmp/go-build -gno-record-gcc-switches"
    
    • 实例演示:Windows 下的 go env
    -------------------------------
    C:UsersAdministrator>go env
    set GO111MODULE=on
    set GOARCH=amd64
    set GOBIN=
    set GOCACHE=C:UsersAdministratorAppDataLocalgo-build
    set GOENV=C:UsersAdministratorAppDataRoaminggoenv
    set GOEXE=.exe
    set GOFLAGS=
    set GOHOSTARCH=amd64
    set GOHOSTOS=windows
    set GOINSECURE=
    set GOMODCACHE=D:go_workpkgmod
    set GONOPROXY=
    set GONOSUMDB=
    set GOOS=windows
    set GOPATH=D:go_work
    set GOPRIVATE=
    set GOPROXY=https://goproxy.io,direct
    set GOROOT=D:ToolsGo
    set GOSUMDB=sum.golang.org
    set GOTMPDIR=
    set GOTOOLDIR=D:ToolsGopkg	oolwindows_amd64
    set GOVCS=
    set GOVERSION=go1.16.4
    set GCCGO=gccgo
    set AR=ar
    set CC=gcc
    set CXX=g++
    set CGO_ENABLED=1
    set GOMOD=NUL
    set CGO_CFLAGS=-g -O2
    set CGO_CPPFLAGS=
    set CGO_CXXFLAGS=-g -O2
    set CGO_FFLAGS=-g -O2
    set CGO_LDFLAGS=-g -O2
    set PKG_CONFIG=pkg-config
    set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:UsersADMINI~1AppDataLocalTempgo-build2372728255=/tmp/go-build -gno-record-gcc-switches
    -------------------------------
    

    2.使用 vscode 在线安装 go 插件

    • 如果不配置加速代理无法连接服务器下载插件
    • 快捷键 ctrl+shift+P 打开命令控制器,
    • 输入 go: install ,
    • 选择 update tools,然后选择所有插件进行安装

    3.命令行在线安装 go 插件

    • 也可以命令行终端执行以下命令安装 go 的插件
    • 与在线安装时实际执行的命令相同
    cd ~/go/
    go get -u -v golang.org/x/tools/cmd/godoc
    go get -u -v golang.org/x/tools/cmd/goformat
    go get -u -v golang.org/x/tools/cmd/goimports
    go get -u -v golang.org/x/tools/cmd/goreturns
    go get -u -v golang.org/x/tools/cmd/guru
    go get -u -v golang.org/x/tools/cmd/gorename
    go get -u -v golang.org/x/tools/gopls
    go get -u -v golang.org/x/lint/golint
    #go get -u -v github.com/mdempsky/gocode
    go get -u -v github.com/stamblerre/gocode
    go get -u -v github.com/uudashr/gopkgs/v2/cmd/gopkgs
    go get -u -v github.com/ramya-rao-a/go-outline
    go get -u -v github.com/acroca/go-symbols
    go get -u -v github.com/cweill/gotests
    go get -u -v github.com/fatih/gomodifytags
    go get -u -v github.com/josharian/impl
    go get -u -v github.com/davidrjenni/reftools/cmd/fillstruct
    go get -u -v github.com/haya14busa/goplay/cmd/goplay
    go get -u -v github.com/godoctor/godoctor
    go get -u -v github.com/go-delve/delve/cmd/dlv
    go get -u -v github.com/rogpeppe/godef
    go get -u -v github.com/sqs/goreturns
    
    • 实例演示:安装完成,查看插件列表
    ll ~/go/bin/
    -------------------------------
    -rwxr-xr-x 1 zhaoshuai zhaoshuai  14M  4月 30 19:08 dlv
    -rwxr-xr-x 1 zhaoshuai zhaoshuai 5.3M  4月 30 19:07 fillstruct
    -rwxr-xr-x 1 zhaoshuai zhaoshuai 4.1M  4月 30 15:47 goaddimport
    -rwxr-xr-x 1 zhaoshuai zhaoshuai 8.1M  4月 30 19:08 gocode
    -rwxr-xr-x 1 zhaoshuai zhaoshuai 8.1M  4月 28 17:44 gocode-gomod
    -rwxr-xr-x 1 zhaoshuai zhaoshuai 7.0M  4月 30 19:08 godef
    -rwxr-xr-x 1 zhaoshuai zhaoshuai 7.1M  4月 30 19:07 godoctor
    -rwxr-xr-x 1 zhaoshuai zhaoshuai 6.9M  4月 30 15:47 gogetdoc
    -rwxr-xr-x 1 zhaoshuai zhaoshuai 5.0M  4月 30 19:03 golint
    -rwxr-xr-x 1 zhaoshuai zhaoshuai 3.3M  4月 30 19:05 gomodifytags
    -rwxr-xr-x 1 zhaoshuai zhaoshuai 3.2M  4月 30 19:04 go-outline
    -rwxr-xr-x 1 zhaoshuai zhaoshuai 4.3M  4月 30 19:04 gopkgs
    -rwxr-xr-x 1 zhaoshuai zhaoshuai 6.5M  4月 30 19:07 goplay
    -rwxr-xr-x 1 zhaoshuai zhaoshuai  22M  4月 28 17:37 gopls
    -rwxr-xr-x 1 zhaoshuai zhaoshuai 5.0M  4月 30 19:00 gorename
    -rwxr-xr-x 1 zhaoshuai zhaoshuai 6.3M  4月 30 19:09 goreturns
    -rwxr-xr-x 1 zhaoshuai zhaoshuai 3.1M  4月 30 19:04 go-symbols
    -rwxr-xr-x 1 zhaoshuai zhaoshuai 8.4M  4月 30 18:59 guru
    -rwxr-xr-x 1 zhaoshuai zhaoshuai 5.5M  4月 30 19:07 impl
    -rwxr-xr-x 1 zhaoshuai zhaoshuai  12M  4月 30 15:15 staticcheck
    

    4.离线安装 go 插件

    • 网络质量不行也可以先从 github 上将安装包下载到本地在进行安装
    # 创建指定的目录结构
    cd ~/go/
    mkdir -p bin
    mkdir -p src/github.com/golang
    mkdir -p src/golang.org/x
    cd ~/go/src
    
    # 下载 tools 包,安装 guru,gorename,下载比较慢,注意下载路径
    git clone https://github.com/golang/xerrors.git golang.org/x/xerrors
    git clone https://github.com/golang/mod.git golang.org/x/mod
    git clone https://github.com/golang/tools.git golang.org/x/tools
    go install golang.org/x/tools/cmd/guru@latest
    go install golang.org/x/tools/cmd/gorename@latest
    
    # lint,注意下载路径
    git clone https://github.com/golang/lint.git golang.org/x/lint
    go install golang.org/x/lint/golint@latest
    
    # gopkgs,注意下载路径
    git clone https://github.com/pkg/errors github.com/pkg/errors
    git clone https://github.com/karrick/godirwalk.git github.com/karrick/godirwalk
    git clone https://github.com/uudashr/gopkgs.git github.com/uudashr/gopkgs
    go install github.com/uudashr/gopkgs/v2/cmd/gopkgs@latest
    
    # go-outline
    git clone https://github.com/ramya-rao-a/go-outline.git github.com/ramya-rao-a/go-outline
    go install github.com/ramya-rao-a/go-outline@latest
    
    # go-symbols
    git clone https://github.com/acroca/go-symbols.git github.com/acroca/go-symbols
    go install github.com/acroca/go-symbols@latest
    
    # gotests
    git clone https://github.com/cweill/gotests.git github.com/cweill/gotests
    go install github.com/cweill/gotests@latest
    
    # gomodifytags
    git clone https://github.com/fatih/structtag.git github.com/fatih/structtag
    git clone https://github.com/fatih/camelcase.git github.com/fatih/camelcase
    git clone https://github.com/fatih/gomodifytags.git github.com/fatih/gomodifytags
    go install github.com/fatih/gomodifytags@latest
    
    # impl
    git clone https://github.com/josharian/impl.git github.com/josharian/impl
    go install github.com/josharian/impl@latest
    
    # fillstruct
    git clone https://github.com/davidrjenni/reftools.git github.com/davidrjenni/reftools
    go install github.com/davidrjenni/reftools/cmd/fillstruct@latest
    
    # goplay
    git clone https://github.com/skratchdot/open-golang.git github.com/skratchdot/open-golang
    git clone https://github.com/haya14busa/goplay github.com/haya14busa/goplay
    go install github.com/haya14busa/goplay/cmd/goplay@latest
    
    # godoctor
    git clone https://github.com/godoctor/godoctor.git github.com/godoctor/godoctor
    go install github.com/godoctor/godoctor@latest
    
    # dlv
    git clone https://github.com/go-delve/delve.git github.com/go-delve/delve
    go install github.com/go-delve/delve/cmd/dlv@latest
    
    # gocode-gomod
    git clone https://github.com/stamblerre/gocode.git github.com/stamblerre/gocode
    go install github.com/stamblerre/gocode@latest
    
    # godef
    git clone https://github.com/rogpeppe/godef.git github.com/rogpeppe/godef
    go install github.com/rogpeppe/godef@latest
    
    # goreturns
    git clone https://github.com/sqs/goreturns.git github.com/sqs/goreturns
    go install github.com/sqs/goreturns@latest
    

    5.参考地址

    https://blog.netimed.cn/archives/go/20201111/319.html
    https://blog.csdn.net/xiazhipeng1000/article/details/109584712
    https://www.liwenzhou.com/posts/Go/00_go_in_vscode/
    
    本文版权归作者和博客园共有,如需转载请在文章页面给出原文链接,否则保留追究法律责任的权利。
  • 相关阅读:
    mysql数据库引擎myisam与innodb
    Java观察者模式的理解
    线程安全的单例模式
    线程相关
    java 线程读写锁
    原子变量AtomicInteger
    接口文档管理,版本管理工具,阿里RAP的windows下部署
    谷歌浏览器报错:跨域问题处理( Access-Control-Allow-Origin)_ 用于本地测试的快捷解决方法
    mysql bin-log日志记录
    阿里RDS中插入emoji 表情插入失败的解决方案
  • 原文地址:https://www.cnblogs.com/tssc/p/14715447.html
Copyright © 2011-2022 走看看