golang.org rate limiter:
rl := rate.NewLimiter(1000000, 1)
last := time.Now()
for i := 0; i < 10; i++ {
rl.Wait(context.Background())
cur := time.Now()
fmt.Println("last", cur.Sub(last))
last = cur
golang.org rate limiter:
rl := rate.NewLimiter(1000000, 1)
last := time.Now()
for i := 0; i < 10; i++ {
rl.Wait(context.Background())
cur := time.Now()
fmt.Println("last", cur.Sub(last))
last = cur
# 思路: 使用 cloc 的匹配规则,再排除test.go 文件即可; | |
## 方式一:使用 cloc 工具 | |
1 统计 Go 源代码行数 (含测试文件) | |
cloc --match-f '\.go$' . | |
2 仅统计 Go 测试文件行数 | |
cloc --match-f '_test\.go$' . | |
3 仅统计 Go 源代码行数 (不含测试文件) |
// ==UserScript== | |
// @name Remove WOA Watermark | |
// @version 0.1 | |
// @author yelo <zhihuzeye@gmail.com> | |
// @match *://km.woa.com/** | |
// @match *://csig.lexiangla.com/** | |
// @match *://mk.woa.com/** | |
// @match *://iwiki.woa.com/** | |
// @match *://qcloud.oa.com/** | |
// @match *://ieop.oa.com/** |
Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.
// StructToMap 将 struct 对象编码为 map | |
func StructToMap(data interface{}) map[string]string { | |
reflectValue := reflect.ValueOf(data) | |
if reflectValue.Kind() == reflect.Ptr { | |
reflectValue = reflectValue.Elem() | |
} | |
reflectType := reflectValue.Type() | |
kvs := make(map[string]string) | |
for i := 0; i < reflectValue.NumField(); i++ { | |
tag := reflectType.Field(i).Tag.Get("json") |