Go语言笔记
Go语言笔记
1 Restful Api的使用
Go语言开发RESTFul JSON API https://segmentfault.com/a/1190000014875956#articleHeader0
2. 如何使用Mysql数据库
https://github.com/go-sql-driver/mysql/wiki/Examples
3. Go语言的语法
单文件 直接 go run main.go 即可执行
多文件 go build && ./project
4. Go语言环境安装,请参考这个文章
https://www.runoob.com/go/go-environment.html
Mac环境下可以使用此命令
brew install go
或者
brew install golang
vim ~/.bash_profile
GOROOT=/usr/local/Cellar/go/1.13.4/libexec
export GOROOT
export GOPATH=/Users/zhai/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOBIN:$GOROOT/bin
source ~/.bash_profile
5. 设置好环境变量
将 /usr/local/go/bin 目录添加至PATH环境变量:
export PATH=$PATH:/usr/local/go/bin
6 Go语言学习材料整理
https://zhuanlan.zhihu.com/p/25493806
7. Go知识图谱说明
https://www.processon.com/view/link/5a9ba4c8e4b0a9d22eb3bdf0
8. GOPath和GOROOT环境变量
9 编码规范:
建议package的名称和目录名保持一致
10 命令
go install
go get
优势:
1,脚本化的语法
2,静态类型和编译型,速度快
3,原生支持并发编程
劣势:
1,语法糖不是很多,没有python和ruby那么多
2,速度不如c
3,第三方库少,但是速度快
4,
工作变量:
1,GOPATH 源码目录
使用Golang写一个简单的resful Api. 参考,主要是结构体的定义嵌套 https://blog.csdn.net/wangshubo1989/article/details/71128972
11 问题
解决golfing.org/x无法访问的问题,安装基本库
mkdir -p $GOPATH/src/golang.org/x/
cd !$git clone https://github.com/golang/net.git
git clone https://github.com/golang/sys.git
git clone https://github.com/golang/tools.gitGit clone https://github.com/golang/text.git
安装项目中的包
go get github.com/gin-gonic/gin
Go get github.com/jinzhu/gorm
Go get github.com/go-sql-driver/mysql
Go get github.com/swaggo/gin-swagger/swaggerFiles
12.保持 go 应用在后台运行,暂时使用screen指令
1. 直接运行应用
Screen -S ./api 在终端中运行
2. 查看所有 screen.
Screen -ls
3.切换到指定的终端
Screen -r 2627 数字
4 删除进程
Kil -9 23456
5 清除窗口
Screen -wipe