Loading

随笔分类 -  Golang

摘要:安装go 1.19.3 1.下载源码包、解压 tar zxvf go1.19.3.linux-amd64.tar.gz cp -r ./go /home/chq/soft 2.设置工作目录 mkdir /home/chq/go mkdir /home/chq/projects 3.配置变量 expo 阅读全文
posted @ 2024-07-15 11:41 集君
摘要:主要思路: 1.创建channel,通过定时器定时往channel中写入令牌,返回令牌桶本身(channel); 2.判断请求是否可以拿到令牌; package main import ( "context" "fmt" "time" ) func getBucket(capacityPs, max 阅读全文
posted @ 2021-12-09 16:08 集君
摘要:参考: https://www.freeaihub.com/post/105431.html http://hustcat.github.io/rate-limit-example-in-go/ 令牌桶模型 官方实现:golang.org/x/time/rate 主要方法为: type Limite 阅读全文
posted @ 2021-12-09 14:32 集君
摘要:golang中,通过关键字go可以创建goroutine,一个函数可以被创建多个goroutine,一个goroutine必定对应一个函数 go创建goroutine与channel返回数据 为一个普通函数创建goroutine的写法: go 函数名(参数列表) 使用go函数是,被调用函数的返回值会 阅读全文
posted @ 2021-10-10 21:25 集君
摘要:在golang中,channel是一个比较核心的功能,作为goroutine之间通信的一种方式,channel和linux系统中管道/消息队列比较类似。但不同之处在于,channel在golang中,提倡基于通信实现内存共享(linux是基于内存实现通信),重点是如何利用channel节省内存,共享 阅读全文
posted @ 2021-10-10 20:05 集君
摘要:查看go环境 chq@chqs-iMac  ~  go env GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/Users/chq/Library/Caches/go-build" GOENV="/Users/chq/Library/Applic 阅读全文
posted @ 2020-03-03 15:37 集君 阅读(151) 评论(0) 推荐(0)