# go-study **Repository Path**: myh1222/go-study ## Basic Information - **Project Name**: go-study - **Description**: Go语言基础学习 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2021-12-02 - **Last Updated**: 2021-12-02 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Go Study ## 代理设置 ```shell script GOPROXY=https://goproxy.cn,direct ``` ### air安装 ``` go get -u github.com/cosmtrek/air ``` 已经在go.mod文件中配置了依赖 ``` github.com/cosmtrek/air v1.12.4 // indirect ``` 新建一个文件 ``` touch .air.toml ``` ## 编码规范 https://golang.google.cn/doc/effective_go.html ## 基础学习 1. 21世纪互联网时代多核环境的通用编程语言 1. Go语言采用大小写表示是否可以导出,大写字母开头表示导出的公共符号。小写字母开头表示包内部的私有符号。 1. Go语言后面不需要分号 1. Go语言的数据结构 1. 数组 1. 字符串 1. 切片:可以理解成简化版的动态数组 1. := 表示声明和初始化赋值 1. [Go语言interface详解](https://www.jb51.net/article/56812.htm) 1. make返回的是引用类型,new返回的是指针类型。 1. map,slice,chan三种类型的创建最好使用make方法,因为可以让go去创建好,然后可以直接使用了。 1. [golang获取当前时间、时间戳和时间字符串及它们之间的相互转换](https://blog.csdn.net/skh2015java/article/details/70051512) #### 判空 ##### struct判空 ```go if defaultCmdArgs == (CmdArgsModel{}) {} ``` #### 异常处理 go语言一般会返回err,直接对err进行判断就可以绕过错误或者异常了。 https://blog.csdn.net/johnWcheung/article/details/95452508 ### 字符串学习 1. [go字符串的遍历输出](https://blog.csdn.net/benben_2015/article/details/78904860) 1. 字符创拼接,%d拼接整数,%s拼接字符串 ```shell sprintf := fmt.Sprintf("https://headline.sankuai.com/ajax/rule/dispatch/fact/fuzzySearchFacts?page=%d&pageSize=10&name=", i) ``` ### 动态数组学习 ### 键值对结构学习 ## 框架学习 ### 手动处理依赖关系 ```shell script go mod tidy ``` 如果项目中存在go.mod ```shell script go mod download ``` ```shell script go get ``` ### iris github:https://github.com/kataras/iris Install with a go.mod file ![](https://camo.githubusercontent.com/726147400a062cfbb94f336e0c35d0e664486db03c24062584a70c34ec1ac6b7/68747470733a2f2f7777772e697269732d676f2e636f6d2f696d616765732f676966732f696e7374616c6c2d6372656174652d697269732e676966) ### beego ##### 运行 ```shell go run beego.go ``` ![](./img/gorun.png) ##### 编译打包运行 ```shell go build -o beego beego.go ./beego ``` ##### 各种环境打包 1、Mac下编译Linux, Windows平台的64位可执行程序: ``` $ CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build test.go $ CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build test.go ``` 2、Linux下编译Mac, Windows平台的64位可执行程序: ``` $ CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build test.go $ CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build test.go ``` 3、Windows下编译Mac, Linux平台的64位可执行程序: ``` $ SET CGO_ENABLED=0SET GOOS=darwin3 SET GOARCH=amd64 go build test.go $ SET CGO_ENABLED=0 SET GOOS=linux SET GOARCH=amd64 go build test.go ``` 注:如果编译web等工程项目,直接cd到工程目录下直接执行以上命令 GOOS:目标可执行程序运行操作系统,支持 darwin,freebsd,linux,windows GOARCH:目标可执行程序操作系统构架,包括 386,amd64,arm 参考: https://blog.csdn.net/daily886/article/details/97527117 ### go frame https://goframe.org/ ### 测试 ```shell script go build -o misas projectCreateTest159.go ``` ```shell script scp misas misas@172.31.102.159:/home/misas/platform/ ``` 服务器后台运行 ```shell script nohup /home/misas/platform/misas >>./api-test.log 2>&1 & ``` ### 封装的collection https://pkg.go.dev/github.com/chenhg5/collection ### 封装的Stream https://gitee.com/softbar/gostream ## ORM ### GORM https://gorm.io/ 类型转换 https://github.com/spf13/cast