![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
golang
文章平均质量分 50
Aurora & Code Is Law
这个作者很懒,什么都没留下…
展开
-
golang 中的协程 goroutine,深度理解 GMP 模型
包括进程、线程、协程,为什么使用协程,go中的协程goroutine,GMP模型的结构,调度器的策略等原创 2022-02-13 19:05:59 · 12596 阅读 · 0 评论 -
golang通过socket实现简单多人聊天室
聊天室包括以下功能:聊天超时检查断开连接查看用户列表改名退出server.gopackage mainimport ( "fmt" "net" "strings" "time")func main() { // 监听聊天室端口 port := "8888" listener, err := net.Listen("tcp", ":"+port) if err != nil { fmt.Println(err) return } fmt.Printf("原创 2022-02-06 23:34:53 · 12722 阅读 · 0 评论 -
golang中select实现超时处理
select会对每个case进行判断,当其中一个case可以操作时执行该case,当所有的case不能执行时会阻塞,我们根据此特性写出如下代码package mainimport ( "fmt" "time")func main() { ch := make(chan int) s := make(chan int) go func() { for { select { case num := <-ch: fmt.Println(num) case原创 2022-02-05 20:23:44 · 12724 阅读 · 0 评论 -
Golang 中直接赋值,是值传递还是地址传递?
1. 普通变量普通变量都是值传递 a := 1 b := a fmt.Printf("%p\n%p", &a, &b) // 0xc0000160a8 // 0xc0000160c0 a := 1.0 b := a fmt.Printf("%p\n%p", &a, &b) // 0xc0000160a8 // 0xc0000160c0 a := "hello" b := a fmt.Printf("%p\n%p", &a, &b原创 2022-01-29 19:15:40 · 14064 阅读 · 0 评论