darjun / go-daily-lib Goto Github PK
View Code? Open in Web Editor NEWGo 每日一库
Go 每日一库
关于cron中的以下代码:
func SkipIfStillRunning(logger Logger) JobWrapper {
return func(j Job) Job {
var ch = make(chan struct{}, 1)
ch <- struct{}{}
return FuncJob(func() {
select {
case v := <-ch:
j.Run()
ch <- v
default:
logger.Info("skip")
}
})
}
}
其中: ch <- struct{}{}
struct初始化不是应该是ch <- struct{}
吗,为什么是ch <- struct{}{}
?
你好,我在使用 gojsonq 的时候发现没有偏移量 Offset 这个方法了。
部分代码如下,没有 Offset 方法,请问你用的是那个版本的 gojsonq
r1 := gq.From("items").Select("id", "name").Limit(3).Get()
位图算法,在很多地方可以用得上,如布隆过滤器。
list = [] user{}
java list.stream().map("id").collect()
php array_column(list,"id")
获取结构体数组user的id
result: [1,2,3]
go
你好,我发现在 https://darjun.github.io/2020/03/20/godailylib/go-cmp/ 中的go get部分的链接有错误。应当是go get github.com/google/go-cmp/cmp
,而不是go get github.com/com/google/go-cmp/cmp
有哪个库能根据数据库表生成对应结构体的吗
今天碰巧看到你写的介绍 ants
的公众号文章,写的不错。
不过,文章结尾的 ants
Github 链接错写成了 github.com/valyala/ants,正确的地址应该是 github.com/panjf2000/ants,因为你的公众号没有评论功能,所以到这里来反馈一下。
大佬又是我哈哈哈!
想请教大佬一个问题,就是 golang 中使用共享内存的库有什么推荐的吗?
在网上没有找到合适的库,最好是shm+mmap都有的那种
大佬也是勤奋,博客让人受益良多。推一个常用库吧,go-cmp,google出品必属精品,项目上用,真是太强大了,完美go哲学。
地址 https://github.com/google/go-cmp
https://github.com/guonaihong/clop
package main
import (
"fmt"
"github.com/guonaihong/clop"
)
type add struct {
All bool `clop:"-A; --all" usage:"add changes from all tracked and untracked files"`
Force bool `clop:"-f; --force" usage:"allow adding otherwise ignored files"`
Pathspec []string `clop:"args=pathspec"`
}
type mv struct {
Force bool `clop:"-f; --force" usage:"allow adding otherwise ignored files"`
}
type git struct {
Add add `clop:"subcommand=add" usage:"Add file contents to the index"`
Mv mv `clop:"subcommand=mv" usage:"Move or rename a file, a directory, or a symlink"`
}
func main() {
g := git{}
clop.Bind(&g)
fmt.Printf("git:%#v\n", g)
fmt.Printf("git:set mv(%t) or set add(%t)\n", clop.IsSetSubcommand("mv"), clop.IsSetSubcommand("add"))
}
// run:
// ./git add -f
// output:
// git:main.git{Add:main.add{All:false, Force:true, Pathspec:[]string(nil)}, Mv:main.mv{Force:false}}
// git:set mv(false) or set add(true)
Golang bindings for FFmpeg
博主会不会写一下这个库,我看中文资料很少
一个高性能,多维度的 Email 地址校验库
github 地址: https://github.com/AfterShip/email-verifier
Email 邮箱校验原理: 如何校验 email 地址以提高邮件送达率
使用文件持久化
用 Go 编写 Redis 服务器: https://github.com/hdt3213/godis
支持Redis大多数功能,代码简洁规范,性能优秀。附有系列文章详细介绍设计思路和实现细节,适合学习上手
gnet 是一个基于事件驱动的高性能和轻量级网络框架
fiber是年初刚出的一个web框架,类似express.js的api接口。用起来蛮不错。
大佬,您好帮忙推荐一下小弟写的这个session库吧
https://github.com/higker/go-session
谢谢😜
go-charts简单方便的形式生成数据图表,支持svg
与png
两种方式的输出,支持主题light
, dark
, grafana
以及ant
。
Apache ECharts
在前端开发中得到众多开发者的认可,因此go-charts
提供了兼容Apache ECharts
的配置参数,简单快捷的生成相似的图表(svg
或png
),方便插入至Email或分享使用。下面为常用的图表截图(主题为light与grafana):
Apache ECharts在前端开发中得到众多开发者的认可,因此go-charts提供了兼容Apache ECharts的配置参数,简单快捷的生成相似的图表(svg或png),方便插入至Email或分享使用
从gorilla/handlers 开始就打不开网址了
[matchers]
m = g(r.sub, p.sub, r.dom) && r.dom == p.dom && r.obj == p.obj && r.act == p.obj
[matchers]
m = g(r.sub, p.sub, r.dom) && r.dom == p.dom && r.obj == p.obj && r.act == p.act
https://github.com/del-xiong/miniblink
miniblink的go语言绑定(依赖cgo),可用于创建占用资源极低的windows gui程序,相对于笨重的原生chrome或electron之类,blink占用的内存往往只有几十M,而且支持大部分H5特性
交互方式 | 方向 | 完整流程 |
---|---|---|
call | c -> s s -> c |
request and response |
notify | c -> s s -> c |
request without response |
rpc | 协议/网络 | 序列化 | 配置 | 连接数 | 每个连接并发协程数 | qps |
---|---|---|---|---|---|---|
arpc | tcp/localhost | encoding/json | os: VMWare Ubuntu 18.04 cpu: AMD 3500U 4c8t mem: 2G |
8 | 10 | 8-10万 |
grpc | http2/localhost | protobuf | os: VMWare Ubuntu 18.04 cpu: AMD 3500U 4c8t mem: 2G |
8 | 10 | 2-3万 |
我自己写 k-v 数据库项目:https://github.com/roseduan/rosedb
代码简洁,注释友好,中文文档,适合新手进阶!
你好,在根目录下的README.md中,gorilla Web 开发包之安全 cookie 库的链接貌似指向了shema,您应该指向securecookie,请你检查
https://github.com/hantmac/fuckdb
根据MySQL schema生成gorm tag 的 go struct。
相关文章介绍: https://github.com/hantmac/fuckdb/blob/master/README_zh.md
非常炫酷的终端UI库 bubbletea
https://github.com/czasg/go-queue
基于 Go 实现的 内存/磁盘 队列,支持 FIFO、LIFO、Priority。
LotusDB 是一个结合 LSM 和 B+ 树的 kv 数据库,简洁优雅,易于上手使用和学习。
Github 地址:https://github.com/flower-corp/lotusdb
看了您了解到Watermill这个包,但如果我想有多个订阅者订阅同一个topic,那么多个订阅者都会消费这个消息,有没有办法只有一个订阅者消费这个消息,不重复消费... 谢谢!
reflect\http-rpc/main.go:134 存在一个bug 。当obj 或者method不存在时,使用IsZero()判断会触发panic,reflect.value的零值是invalid,此处使用IsValid判断是否更为合理?参考:https://pkg.go.dev/reflect#Value.IsValid
Reactive Extensions for the Go Language,使用RxGo可以更轻松地编写并发调用代码
package main
import (
"context"
"errors"
"fmt"
"log"
"time"
"github.com/Pallinder/go-randomdata"
"github.com/ahmetb/go-linq"
"github.com/reactivex/rxgo/v2"
)
// ParallelCase1 并发获取不同类型字段信息
func ParallelCase1(ctx context.Context) {
type Student struct {
ID int64
Name string
Age int64
Teacher string
}
student := Student{ID: 1}
getNameByID := func() (interface{}, error) {
time.Sleep(1 * time.Second)
fmt.Println("getNameByID Success")
return func() { student.Name = "kangkang" }, nil
}
getAgeByID := func() (interface{}, error) {
time.Sleep(3 * time.Second)
fmt.Println("getAgeByID Success")
return func() { student.Age = 13 }, nil
}
getTeacherByID := func() (interface{}, error) {
time.Sleep(2 * time.Second)
fmt.Println("getTeacherByID failed")
return nil, errors.New("ERROR!")
}
for item := range rxgo.Just(getNameByID, getAgeByID, getTeacherByID)().Map(
// 执行并发任务
func(ctx context.Context, item interface{}) (interface{}, error) {
f := item.(func() (interface{}, error))
return f()
},
// 配置并发策略
rxgo.WithPool(3),
rxgo.WithErrorStrategy(rxgo.StopOnError),
rxgo.WithContext(ctx),
).Observe() {
if item.E != nil {
log.Fatal(item.E)
}
// 获取并发任务执行结果
f := item.V.(func())
f()
}
fmt.Printf("student: %+v", student)
}
// ParallelCase2 并发处理同类型字段信息
func ParallelCase2(ctx context.Context) {
idList, _ := rxgo.Range(1, 100).ToSlice(100)
var nameList []string
itemList, err := rxgo.Just(idList)().Map(
func(ctx context.Context, item interface{}) (interface{}, error) {
randNum := randomdata.Number(0, 3)
time.Sleep(time.Duration(randNum) * time.Second)
if randNum == 1 {
return nil, errors.New("[RANDOM ERROR]")
}
randName := randomdata.SillyName()
fmt.Printf("randNum: %d, randName: %s\n", randNum, randName)
return randName, nil
},
rxgo.WithPool(20), // 最大并发数
rxgo.WithBufferedChannel(20), // 带缓存接收
rxgo.WithContext(ctx), // 传递context进行链路追踪
rxgo.WithErrorStrategy(rxgo.ContinueOnError), // 错误处理策略
).ToSlice(len(idList))
if err != nil {
log.Fatalf("[RXGO ERROR]: %+v", err)
}
linq.From(itemList).SelectT(
func(item string) string { return item },
).ToSlice(&nameList)
fmt.Printf("nameList: %+v", nameList)
}
func main() {
ctx := context.Background()
ParallelCase1(ctx)
ParallelCase2(ctx)
}
https://github.com/go-ozzo/ozzo-validation
这个库主要用于数据验证,检查数据是否符合预设定的规则,一般可以用于配置的检测等
https://github.com/HDT3213/rdb
Redis RDB 文件解析和生成工具,支持转 JSON、转 AOF、寻找 Big Key、生成 RDB 文件及绘制内存火焰图等功能
这个 代码生成器库 也蛮有趣的
刚刚看了你写的有关如何使用 dig 的博客,google 推出了一个不使用反射的依赖注入库,希望博主可以也出一篇介绍,期待!
https://github.com/google/wire
在README里能不能加上每个库的简介?这样方便在一个页面里进行搜索
大佬 有沒有 zap 的讲解篇的?
Excelize 是 Go 语言编写的用于操作 Office Excel 电子表格文档的基础库
相同struct数据合并的mergo,不同struct数据的copier库考虑下呗。 要是有更好的也推荐下,目前就找到这两。
要是权限库casbin能考虑更好了
github.com/dave/dst
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.