中文论坛
c.biancheng.net/golang/intro/
Go语言实战笔记(二十三)| Go 调试 https://www.flysnow.org/2017/06/07/go-in-action-go-debug.html
函数function
https://www.cnblogs.com/skymyyang/p/7659775.html
golang 函数以及函数和方法的区别
https://blog.csdn.net/d_guco/article/details/53575067
Golang中new和make的区别
https://studygolang.com/articles/4997
Golang 学习之“”、nil 和 len(s)的对比
https://blog.csdn.net/phantom_111/article/details/54670598
Go学习笔记之:for循环
https://studygolang.com/articles/1937
Golang从入门到精通(六):Golang控制语句之for
https://blog.csdn.net/xiangxianghehe/article/details/78782135
golang笔记——容器
https://studygolang.com/articles/6236
https://blog.csdn.net/u011304970/article/details/72782412
golang之math/rand随机数
https://studygolang.com/articles/11984?fr=sidebar
Golang struct、interface 组合嵌入类型详解
https://www.jianshu.com/p/d87c69ac6ce7
golang中struct和interface的基础使用教程
https://www.jb51.net/article/137067.htm
golang interface to struct and string to struct
https://blog.csdn.net/rocky0503/article/details/81482689
Go语言基础:make,new, len, cap, append, delete方法
https://blog.csdn.net/uudou/article/details/52241534
golang中省略返回值造成内存泄漏
https://studygolang.com/articles/591
golang手动管理内存
https://blog.csdn.net/bolun365/article/details/65683615
打印
fmt.Println("hello world")
fmt.Printf("The variable i is now: %d\n", i)
GO int64和int32相互转换必须强转
int64 roomIdTemp
int32 roomId = int32(roomIdTemp)
go的指针也是用.调用
go的枚举不可以用直接写整形赋值
go之Marshal
https://blog.csdn.net/stpeace/article/details/82901943
常用
打印
fmt.Println("hello world")
fmt.Printf("The variable i is now: %d\n", i)
GO int64转int32
roomId = int32(roomIdTemp)
go的指针也是用.调用
go的枚举不可以用直接写整形赋值
goint64,和int32必须手动强转
:= 声明并赋值
格式化
accountName := core.Sprintf("机器人%d", i)
if语句
if role == nil { //不能if(), {不能换行
return errutil.ErrRoleNotFound
}else{ //else不能换行
}
if role := rolemanager.RoleManager.Find(player.RoleId); role != nil {
}
for循环
for i := 0; i < 1000; i++ { //不能for()
}
for true {
for _, session := range PlayerList { //和lua的 for k, v 差不多, PlayerList是数组或者map
}
}
map
https://www.jianshu.com/p/664163be0b54
GoLang基础数据类型--->字典(map)详解
https://www.cnblogs.com/yinzhengjie/p/7689996.html
Go语言interface底层实现
https://blog.csdn.net/i6448038/article/details/82916330
go语言底层数据结构之map解析
https://baijiahao.baidu.com/s?id=1609310227824363709&wfr=spider&for=pc
go语言常见坑
https://blog.csdn.net/ahaotata/article/details/84307952
Golang 学习笔记(06)—— 多线程
https://www.jianshu.com/p/c3d65105fa46
var PlayerList = make(map[string]*core.Session)
数组
arr := [...]int{6, 7, 8}
类的概念
go语言没有.h的概念
package roles //类似于lua的模块,外部调用的时候需要用到
import "soccer/message" //类似于c++的include
type Robot struct { //和c++的class差不多,用于声明对象的属性
Id int32
Camp message.ECamp
}
func NewRobot(id int32, camp message.ECamp) *Robot { //构造函数
return &Robot{Id: id, Camp: camp}
}
//第一个括号c++的类的作用域::,第二个括号是参数,参数后面是返回值,如果返回多个值用括号,返回单个值不用括号
func (r *Robot) RobotInfo() *message.Group_RobotInfo {
return &message.Group_RobotInfo{
RobotId: r.Id,
Camp: r.Camp,
}
}
//外部调用
robot := roles.NewRobot(group.robotId, camp)
go没有public 和 privite
函数首字母大小是punblic,首字母小写是privite
runtime.GOMAXPROCS(1) //设置cpu的核的数量,从而实现高并发
编译linux版本
下载babun,windows安装
到代码所在目录 go build
如果没东西就cd ..返回上一层
默认编译出来是exe
编译linux版本
#!/usr/bin/env bash
export GOARCH=amd64
export GOOS=linux
go build