# Go ## 安装 [Download and install](https://go.dev/doc/install) [How To Install Go on Ubuntu 20.04](https://www.digitalocean.com/community/tutorials/how-to-install-go-on-ubuntu-20-04#conclusion) ```shell= curl -OL https://golang.org/dl/go1.16.7.linux-amd64.tar.gz sudo tar -C /usr/local -xvf go1.16.7.linux-amd64.tar.gz # 环境变量 export GOROOT=/usr/local/go export GOPATH=/opt/go export GOBIN=$GOPATH/bin export PATH=$PATH:$GOROOT/bin export PATH=$PATH:$GOPATH/bin ``` ## 开发环境 [为 Go 开发配置Visual Studio Code](https://learn.microsoft.com/zh-cn/azure/developer/go/configure-visual-studio-code) ```shell= # go proxy go env -w GOPROXY=https://goproxy.io,direct # Set environment variable allow bypassing the proxy for selected modules go env -w GOPRIVATE=*.corp.example.com go env -w GO111MODULE=on # go path go env -w GOPATH=/Users/zhangxinhao/code/test/demo/go go env -w GOPATH=/Users/zhangxinhao/go # go bin go env -w GOBIN=/home/zxh/code/go/demo/go/bin ``` ### GoLand ```shell= # 依赖外网三方库的,可设置Proxy,配置环境变量 GO111MODULE=on;GOBIN=D:\Program Files\Go\bin;GOPRIVATE=szv-open.codehub.huawei.com;GOPROXY=http://mirrors.tools.huawei.com/goproxy,direct;GOSUMDB=off ``` ### VSCode ```shell= # 如果您使用的 Go 版本是 1.13 及以上 (推荐) # go proxy go env -w GO111MODULE=on go env -w GOPROXY=https://mirrors.tools.huawei.com/goproxy/ go env -w GONOSUMDB=* go env -w GOSUMDB=off go env -w GOBIN=D:\code\go\path\bin go env -w GOBIN=/opt/go/bin go env -w GOPROXY=http://mirrors.tools.huawei.com/goproxy,direct go env -w GOPROXY=https://repo.huaweicloud.com/repository/goproxy/,direct go env -w GOPRIVATE=*.huawei.com go env -w CGO_ENABLED=1 # 设置不走 proxy 的私有仓库,多个用逗号相隔(可选) go env -w GOPRIVATE=*.corp.example.com # 设置不走 proxy 的私有组织(可选) go env -w GOPRIVATE=example.com/org_name ``` ## 下载私有仓库 ```shell= # 以coastguard为例 # 仓库地址 https://open.codehub.huawei.com/innersource/it-edge-native/edge-native-core/coastguard/files?ref=master # ssh下载地址 ssh://git@szv-open.codehub.huawei.com:2222/innersource/it-edge-native/edge-native-core/coastguard.git # http下载地址 https://szv-open.codehub.huawei.com/innersource/it-edge-native/edge-native-core/coastguard.git@v1.0.6 # 设置http转成ssh下载 git config --global --add url."ssh://git@szv-open.codehub.huawei.com:2222/".insteadOf "https://szv-open.codehub.huawei.com/" git config --global --add url."ssh://git@lfg-y.codehub.huawei.com:2222/".insteadOf "https://codehub-y.huawei.com/" git config --global --add url."ssh://git@codehub-dg-y.huawei.com:2222/".insteadOf "https://codehub-dg-y.huawei.com/" # 下载代码 go get szv-open.codehub.huawei.com/innersource/it-edge-native/edge-native-core/coastguard.git@v1.0.6 # 如果没有权限,可以使用 用户名+token的方式 git config --global --add url."https://{username}:{token}@szv-open.codehub.huawei.com".insteadOf "https://szv-open.codehub.huawei.com" # 因为coastguard库的module命名是huawei.com/kmc和代码库路径不一致,不能直接go get, 需要go mod replace的方式下载 go mod edit -replace huawei.com/kmc=szv-open.codehub.huawei.com/innersource/it-edge-native/edge-native-core/coastguard.git@v1.0.6 ``` ```shell= require huawei.com/kmc v1.0.6 replace huawei.com/kmc => szv-open.codehub.huawei.com/innersource/it-edge-native/edge-native-core/coastguard.git v1.0.6 # 重新下载 go get huawei.com/kmc@v1.0.6 # git配置 # 避免证书校验 git config --global http.sslVerify false # 保存凭证 git config --global credential.helper store ``` # 学习项目 ## 版本 | 主要版本 | 发布日期 | | -------- | ---------- | | 1.0 | 2012-03-28 | | 1.1 | 2013-05-13 | | 1.2 | 2013-12-01 | | 1.3 | 2014-06-18 | | 1.4 | 2014-12-10 | | 1.5 | 2015-08-19 | | 1.6 | 2016-02-17 | | 1.7 | 2016-08-15 | | 1.8 | 2017-02-16 | | 1.9 | 2017-08-24 | | 1.10 | 2018-02-16 | | 1.11 | 2018-08-24 | | 1.12 | 2019-02-25 | | 1.13 | 2019-09-03 | | 1.14 | 2020-02-25 | | 1.15 | 2020-08-11 | | 1.16 | 2021-02-16 | | 1.17 | 2021-08-16 | | 1.18 | 2022-03-15 | | 1.19 | 2022-08-02 | | 1.20 | 2023-02-01 | ## 项目 ### gin-vue-admin [flipped-aurora/gin-vue-admin](https://github.com/flipped-aurora/gin-vue-admin) [项目介绍](https://www.gin-vue-admin.com/guide/introduce/project.html) ```shell= git clone https://github.com/flipped-aurora/gin-vue-admin.git # 生成swagger文档 cd server swag init ``` ### go-admin [go-admin-team/go-admin](https://github.com/go-admin-team/go-admin) [介绍](https://www.go-admin.pro/guide) ## 文章 [一文读懂 Golang init 函数执行顺序](https://cloud.tencent.com/developer/beta/article/2138066) [Go (Golang) GOOS and GOARCH](https://gist.github.com/asukakenji/f15ba7e588ac42795f421b48b8aede63) Golang 支持交叉编译,在一个平台上生成另一个平台的可执行程序。 GOOS : 目标平台的操作系统 (darwin、freebsd、linux、windows) GOARCH: 目标平台的体系架构 (386、amd64、arm) 交叉编译不支持CGO 所以要禁用它 ## 开源库 ### Viper [spf13/viper](https://github.com/spf13/viper) ### go-logging [op/go-logging](https://github.com/op/go-logging) ### GORM [go-gorm/gorm](https://github.com/go-gorm/gorm)
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up