note/程序开发/编程语言/GoLang.md
2023-07-05 09:34:06 +08:00

52 lines
982 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# GoLang
## 安装
```python
#查看go root path
!go env
#删除目录
!rm -rf /usr/lib/golang
#下载解压
!wget https://golang.google.cn/dl/go1.20.2.linux-amd64.tar.gz
!tar xvf go1.20.2.linux-amd64.tar.gz
#移动目录
!mv go /usr/lib/go
#加载配置
%load /etc/profile
#写入配置
%%writefile /etc/profile.d/env.sh
export GO111MODULE=on
export GOROOT=/usr/local/go
export GOPATH=/home/gopath
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
#激活配置
!source /etc/profile
```
golang 官网地址: https://golang.google.cn/
## 配置
```shell
GO_HOME=C:\App\go
#新建GO_HOME 系统环境变量后找到系统环境变量Path然后编辑 Path
#新建 %GO_HOME%\bin指向 go 安装目录的 bin 目录
#设置代理
go env -w GOPROXY=https://goproxy.cn,direct
#go init 创建项目
go mod init example/hello
```
## 安装库
- protoc
```shell
go install google.golang.org/protobuf/cmd/protoc-gen-go
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc
```