Golang Awesome
常用库
- mux
- chi - ⭐️
- gin, mux
- ORM
- 命令行/Command
- urfave/cli - ⭐️
- 简单易用
- spf13/cobra - ⭐️
- 目前使用最多
- 更适合命令行非常复杂的情况,默认 split 处理逻辑
- flag 由 pflag 处理,配置由 viper 处理
- 比 urfave/cli 更 unopinioned
- urfave/cli 更加 declarative
- muesli/coral
- cobra fork with only 4 dependencies
- go-cmd/cmd
- MIT, Golang
- urfave/cli - ⭐️
- IoC/DI
- JWX
- golang-jwt/jwt
- lestrrat-go/jwx
- jwt,jwk,jwa,jws,jwe
- OIDC
- caos/oidc
- op,rs
- golang.org/x/oauth2
- caos/oidc
- 配置
- viper - 重量级
- 会 lowercase YAML key
- break space
- caarlos0/env
- knadh/koanf
- 轻量 - 功能按需引入 - binary 小
- viper - 重量级
- 日志
- zerolog
- zap
- logrus
- HTTP Client
- Observerable
- Prometheus Metrics
- Jaeger
- Testing
- 参考
学习
- https://go-proverbs.github.io/
- https://golang.org/doc/effective_go
- https://github.com/golang/go/wiki/CodeReviewComments
- https://github.com/golang/go/wiki/Modules
- https://github.com/golang/go/wiki
- https://golang.org/ref/spec
- project layout
- Simple Pojrect Layout
- golang-standards/project-layout
- rsc: this is not a standard Go project layout - #117
- Network Programming with Go
- Gotchas in the Go Network Packages Defaults
- Playground
日志
- rs/zerolog - ⭐️
- Zero Allocation JSON Logger
- 接口更友好
- ⚠️ 重复名字字段不会覆盖
- uber-go/zap - ⭐️
- 适用于生产、核心链路
- 需要更多的配置
- Suger 模式接口友好 - 些微影响性能
- sirupsen/logrus
- 目前处于 维护模式 🚧 - 完成使命
- 适用于简单快速使用
- 默认即可使用
- benchmark
数据库驱动
- polarsignals/frostdb
- Apache-2.0, Go
- embeddable columnar database
- 类似于 duckdb
- mattn/go-sqlite3
- 依赖 CGO
- DSN - https://www.sqlite.org/uri.html
file:test.db?cache=shared&mode=memory
- mode ro, rw, rwc, memory
- rwc - Read, Write, Create
- cache shared, private - https://www.sqlite.org/sharedcache.html
_foreign_keys/_fk
-PRAGMA foreign_keys
- 外键约束
- cznic/sqlite
- pure go SQLite
- github.com/jackc/pgx/v5
- 推荐 - 纯 Go
- jackc/pgtype
- 接口没有 pq 提供的类型方便操作
- vs pq
- go-redis/redis
- go-redis/redis#607
- 不支持 Prefix
- go-redis/redis#607
- lib/pq
- 已不推荐使用
数据库相关
- ent
- ariga/sqlcomment
- 添加注释 - 用于 trace
- ariga/sqlcomment
- gorm
- guregu/null
- 包装 sql.Null 支持 序列化
- qustavo/sqlhooks
- 添加 hook
- kyleconroy/sqlc
- sql 生成 go 代码进行调用
- sosedoff/pgweb
- Golang Web 管理工具 - MIT, 只读
- go-pg/pg
- ORM focus on PostgreSQL features and performance
- volatiletech/sqlboiler
- database-first ORM
- xo/xo
- DB 生成 Go
- jmoiron/sqlx
- 辅助 sql 操作
- xo/dburl
- Connect String
- SQL Builder
- 迁移
- atlas
- DSL based
- golang-migrate/migrate
- rubenv/sql-migrate
- atlas
Web
tip
- Go 本身的 HTTP 处理已经比较完备,选择框架和库尽量以增强为主,避免选择全新实现
- 兼容 Go HTTP 处理逻辑的库能够相互组合使用
路由/Router
- chi
- 标准接口
- 开发比 mux 活跃
- radix trie - 类似 httprouter - 性能优于 mux
- 自带较多 middleware
- gorilla/mux
- 不推荐使用
- 非常便于使用路由,增强 go http 功能
- 变量匹配路由 -
O(n)
- julienschmidt/httprouter
- 牺牲功能换取性能
- 不适用于 RESTful 接口 - 不能区分路由
/users/like
,/users/:userId
- 参考
框架/Framework
- kataras/iris
- BSD-3
- gin-gonic/gin
- 默认处理逻辑将请求和响应封装为了 Context
- 能 Wrap http 的 Handler
- 基于 httprouter 路由 - 不能区分路由
/users/like
,/users/:userId
- 不适用于 RESTful 接口
- gin#2016
- gofiber/fiber
- 非 net/http 体系
- 基于 fasthttp
- cloudwego/hertz
- 微服务
- 网络层基于 Netpoll
- 文档 https://www.cloudwego.io/zh/docs/hertz/
- by 字节跳动
- emicklei/go-restful
- 辅助构建 RESTful 类型接口
- 抽象 Resource 概念
- 抽象 Entity 编码处理
- 支持 JSON 和 XML
- 支持定义 OpenAPI
- ogen-go/ogen
- 生成 OpenAPIv3
- beego
- 用于快速开发的完整框架 - All in one
- 不推崇,尽量避免使用
- 除非所有理念刚好匹配
- echo
- revel
- danielgtaylor/huma
- Huma REST/GraphQL API Framework for Golang with OpenAPI 3
- swaggo/swag
- swaggo/http-swagger
- goadesign/goa
增强处理
- go-chi/render
- 辅助处理请求响应内容
- unrolled/render
- yuriizinets/kyoto
- SSR :)
Websocket
- gorilla/websocket
- 实现 ws 的首选库
- 功能比
golang.org/x/net/websocket
丰富完善
- olahol/melody
- 基于 gorilla/websocket 封装的简单消息处理库
- 不再维护,如需修改可以拷贝出来使用
- gobwas/ws Tiny WebSocket library for Go
Misc
- go-vgo/robotgo
- RobotGo, Go Native cross-platform GUI automation
- valyala/fasthttp
- 重写的 net/http 处理
- 注重性能
- Zero memory allocations in hot paths. Up to 10x faster than net/http
- golobby/container
- IoC Container
- zhenghaoz/gorse recommender system service
- davidschlachter/embedded-struct-visualizer
- struct 关系可视化
- orijtech/structslop
- struct 字段顺序调整优化
- tmc/reactssr
- React SSR
- razorpay/go-financial
- numpy-financial
- Go Financial — A pkg for elementary financial functions
- loov/goda
- Go Dependency Analysis toolkit
GraphQL
- 99designs/gqlgen
- GraphQL Schema 生成 Model/Resolver
- 静态类型,无法动态 Schema
- 参照 graphql-js 实现
- graph-gophers/graphql-go
- BSD-2
- 类型自动绑定 Schema - 静态 Schema
- graphql-go/graphql
- 代码动态生成 Schema - 动态 Schema
- Yamashou/gqlgenc
- gqlgen 客户端
- Khan/genqlient
- type-safe Go GraphQL client
网关
- ysugimoto/grpc-graphql-gateway
- 基于 pb 生成 graphql 网关
- 实现使用 graphql-go/graphql
- movio/bramble
- MIT, Golang
- 比 apollo 简单但功能更弱
- 基于 service 合成 - 支持部分简单 directive
- 不支持 subscriptions
- Introducing Bramble: A Federated GraphQL Gateway Implemented In Go
- nautilus/gateway
- MIT, Golang
- Introspect schema,自动合并 - 不需要 directive
- 不支持 subscriptions
- A Guide to GraphQL Schema Federation, Part 1
代码生成/Generator
- cmd/stringer/stringer.go
- 为 int 枚举生成 String 方法
//go:generate stringer -type=Pill
-type
-output
-trimprefix
-tags
-linecomment
- String 返回 Comment 内容
- google/addlicense
- 添加 License
//go:generate go run github.com/google/addlicense -c Wener -y 2019-present ./
- fatih/gomodifytags
- 添加 json tag
gomodifytags -file demo.go -struct Server -add-tags json -add-options json=omitempty -transform camelcase --skip-unexported
- transform
- snakecase - base_domain
- camelcase - baseDomain
- lispcase - base-domain
- pascalcase - BaseDomain
- titlecase - Base Domain
- keep
- hexdigest/gowrap
- 生成 interface 实现,辅助实现修饰模式
- awalterschulze/goderive
- 为 Struct 生成 Equal、Compare、DeepCopy、GoString、Hash
- 为类型生成 Set 操作
- 生成函数式编程方法
- 生成并发操作
- miku/zek
- XML -> Go Struct
- 在线生成
- mholt/json-to-go
- JSON -> Go Struct
- 在线生成
- gzuidhof/tygo
- Go -> Typescript
- 功能性
- ent/ent - Schema -> CRUD, MySQL, PostgreSQL, SQLite
- uber-go/gopatch
- 根据规则转换代码
- ogen-go/ogen
- OpenAPI, Golang
JSON
- sclevine/yj
- Convert between YAML, TOML, JSON, HCL
- json-iterator/go
- 替代
encoding/json
- 更好性能,更多功能
- 自定义类型解码
- 宽松名字处理
- 替代
- go-faster/jx
- 高性能 JSON encode,decode
- 不兼容 encoding/json - 因此才能提供性能优势
- 不支持反射
- 适用于代码生成场景
- tidwall/gjson
- Get Json Path
- tidwall/sjson
- Set Json Path
- qri-io/jsonschema
- xeipuuv/gojsonschema
- ugorji/go diomatic codec and rpc lib for msgpack, cbor, json, etc.
数据处理/Data
- go-playground/validator
- struct 标签注解校验 - 类似于 Java 的 Bean Validate
- 功能完善
- go-validator/validator
- 实现简单 - 基础类型基础功能
- go-ozzo/ozzo-validation
- 校验库
- mapstructure
- bytedance/go-tagexpr
- 使用表达式 validate
- BWbwchen/MapReduce
网络/Network
- cloudwego/netpoll
- non-blocking I/O networking framework, focused on RPC
- https://github.com/inetaf
- tidwall/evio
- event-loop networking for Go
- panjf2000/gnet
- 高性能、轻量级、非阻塞的事件驱动 Go 网络框架。
- magma/magma
- Platform for building access networks and modular network services
- koding/websocketproxy WebSocket reverse proxy
- soheilhy/cmux
Connection multiplexer - serve different services on the same port
- grpc,ssh,http,https 同端口
- songgao/water TUN/TAP library written in native Go
- name5566/leaf game server framework in Go
- xtaci/gonet Game Server Skeleton in golang.
- nadoo/glider
- forward proxy with multiple protocols support
- cilium/ebpf
- kevwan/tproxy
- https://gvisor.dev/docs/user_guide/networking/
- gvisor networking stack
- topfreegames/pitaya
- MIT, Game server
协议/Protocol
- hacdias/webdav
- Simple Go WebDAV server
事件驱动/Event
- temporal
- uber/cadence
- distributed, scalable, durable, and highly available orchestration engine
- execute asynchronous long-running business logic
- tibcosoftware/flogo
- 包含 Web UI
- 用于实现事件驱动编程
- 场景
- 集成 Flow 处理
- 流处理
- 上下文决策
- Microgateway
- ThreeDotsLabs/watermill
- trustmaster/goflow
- flowbase/flowbase
服务框架/Service Framework
- dapr/dapr
portable, event-driven, runtime for building distributed applications
- Sidecar 模式
- 微软 项目
- AsynkronIT/protoactor-go
- Proto Actor - Ultra fast distributed actors for Go, C# and Java/Kotlin
- wasmCloud/wasmCloud
- wasm actor 平台 - 支持 tinygo
- RichardKnop/machinery asynchronous task queue/job queue based on distributed message passing
- hibiken/asynq
- MIT, Golang
- Redis
- Simple, reliable, and efficient distributed task queue in Go
- twitchtv/twirp
simple RPC framework with protobuf service definitions
- protobuf+net/http
- gogf/gf
微服务框架/Microservices Framework
大多微服务框架着重于 RPC、服务发现、配置,并提供基础的中间件 监控、Trace。
- stefanprodan/podinfo
- go-kit/kit
standard library for microservices
- 简单灵活自由拼装 - 因此定位是 kit 和 库
- 很多抽象接口值得学习
- go-micro - asim/go-micro standalone framework for distributed systems development
- google/go-cloud
- Go Cloud Development Kit
- nytimes/gizmo
- ergo-services/ergo
- design patterns of Erlang/OTP
国产
- kratos - go-kratos/kratos
- grpc,wire
- kratos 命令行工具
- 哔哩哔哩 RPC 框架
- go-zero - zeromicro/go-zero
- 好未来技术
- 自定义 DSL + goctl 生成
- cloudwego/kitex
- Apache-2.0, Go
- 字节跳动 RPC 框架
- rpcx - smallnest/rpcx
- go-chassis/go-chassis
- unionj-cloud/go-doudou
国内环境
Markdown
- yuin/goldmark
- 易于扩展 - 内建较多扩展
- 实现扩展需要阅读源码添加
- gomarkdown/markdown
- 自带部分扩展功能
- russross/blackfriday
- 不兼容 CommonMark
- 无法扩展
- microcosm-cc/bluemonday
- html sanitizer
认证授权/Auth
- dexidp/dex - OIDC, IdP
- ory
- hydra - OIDC, IdP
- kratos - 用户注册管理
- oathkeeper - 访问代理 - 注入授权信息
- keto - 访问控制服务
- fosite - Golang OAuth2 框架
- Permify/permify-gorm
Plugin
- 扩展/插件/Extension/Plugin - 动态库
- plugin - Linux, FreeBSD, macOS
-buildmode=plugin
- 只支持 Linux, FreeBSD, macOS - dlopen
- 需要 cgo - #19569
- Lookup symbol 强转类型进行使用 - 类似 dlopen - 底层使用 dlopen
- main 下 exported 的符号都可以使用
- 加载时所有包的 init 都会触发
- plugin 不支持 close - go 涉及到 gc 和全局状态
- 交互不需要序列化 - 相同内存空间
- hashicorp/go-plugin
- 基于 RPC 的插件系统
- 交互信息需要序列化
- 用于专门的场景 - 例如不能用于 Hook HTTP 请求
- 多进程
- 隔离 cgo
- 避免 crash
- 支持热升级
- 多语言
- 基于 RPC 的插件系统
语言/Language
- rogchap/v8go
- 内含预编译的静态 libv8
- alpine 需要额外构建 v8go#170
- augustoroman/v8
- V8 Binding
- 🚧 不再维护
- mvdan/sh
Shell parser, formatter, interpreter
- source APKBUILD https://gitlab.alpinelinux.org/kdaudt/atools-go
- mvdan/gofumpt stricter gofmt
- burrowers/garble
- BSD-3
- 混淆 Go 代码 - 替代现有 go 工具
- mjibson/sqlfmt
- d5/tengo
- MIT
- 自定义的语言
- dop251/goja
- Javascript
- +6MB
- Shopify/go-lua
- MIT
- Lua 5.2 VM
- 兼容 luac 编译结果
- yuin/gopher-lua
- MIT
- Lua 5.1
- google/starlark-go
- Python
- used by Caddy, Bazel
- traefik/yaegi
- by Traefik
- Apache-2.0
- +14MB
- 自定义类型需要源码 - 配置 GOPATH - 对依赖的模块进行 vendor
- 支持解释模式和编译模式
- Yaegi is Another Elegant Go Interpreter
- google/cel-go
- Apache-2.0, Go
- Fast, portable, non-Turing complete expression evaluation with gradual typing
Template
- Masterminds/sprig - 提供大量模板函数
- gliderlabs/sigil
- hairyhenderson/gomplate - 支持数据源的命令行模板
有趣
- Zxilly/go-size-analyzer
- fogleman/primitive
- 将图像转换为原子图形
- esimov/triangle
- 转换为三角形
- alecthomas/chroma
- 代码高亮
- mugo
- rhu1/fgg
- basic prototype of Featherweight Go and Featherweight Generic Go
- joewalnes/websocketd
- Turn any program that uses STDIN/STDOUT into a WebSocket server
- jeromer/mumbojumbo 字符串混淆
- esimov/caire 内容感知的图像缩放
- Go in a scratch VM
- 游戏
- 算法
- smarty-archives/mafsa
- Minimal Acyclic Finite State Automata
- blevesearch/vellum
- FST
- smarty-archives/mafsa
控制理论 / Control theory
Library
- cron
- adhocore/gronx cron parser
- vfs
- cache
- goroutine
- error
- compress/archive
- magic/mime
- charset
- golang.org/x/text/encoding/charmap
- golang.org/x/text/encoding/simplifiedchinese
- golang.org/x/net/html/charset
- https://github.com/saintfish/chardet
- https://github.com/djimenez/iconv-go
- iconv cgo binding
- nlp
- lang
- dsl
- distributed/分布式
- hash
- media
- http
- support content negotiation #19307
- saas/paas
- tsuru/tsuru
- BSD-3
- PaaS
- Goxiaoy/go-saas
- geeks-accelerator/oss/saas-starter-kit
- 2019
- tsuru/tsuru
- semver
- 数据结构/算法
- kv/storage
- goroutine/concurrency
- oklog/run
- sourcegraph/conc
- Better structured concurrency for go
- cloudflare/tableflip
- Graceful process restarts in Go
- SimonWaldherr/golang-benchmarks
Tool
- arl/statsviz
- visualization of your Go application runtime statistics (GC, MemStats, etc.) in the browser
- mgechev/revive
- golint
- jondot/goweight
- 分析 go 模块大小
- google/bloaty
- 二进大小分析
- xo/usql
- SQL 命令行工具
- google/gops
- Go 进程诊断
- google/ko Build and deploy Go applications on Kubernetes
- go-task/task
- charmbracelet/wish
- Make SSH apps
- elves/elvish
- ssh
- golang.org/x/crypto/ssh
- x/crypto/ssh: rsa-sha2-256/rsa-sha2-512 #49952
- 服务端 /etc/ssh/sshd_config 添加
PubkeyAcceptedAlgorithms +ssh-rsa
可临时解决 - AlpineLinux 3.15 新版本 openssh server 默认不允许 ssh-rsa
- openssh 8.8 废弃 ssh-rsa
- k0sproject/rig
- appleboy/easyssh-proxy
- owenthereal/upterm
- gliderlabs/ssh
- SSH Server
- golang.org/x/crypto/ssh
- shell
go install github.com/jondot/goweight@latest
cd cmd/server
goweight
Debug
- profiling
- log
- metrics
- felixge/httpsnoop
- github.com/slok/go-http-metrics -prometheus 内置 handler 拦截
- GODEBUG=http1debug
- GODEBUG=http2debug=2
Service
- umputun/remark42 comment egnine
- ortuman/jackal
- XMPP
- google/martian
- building custom HTTP/S proxies
Performance
- bspaans/jit-compiler
- Writing a JIT compiler in Golang
- Go Performance Tools Cheat Sheet
- CPU Utilization is Wrong
OS/操作系统
- rainycape/governator
- process manager for UNIX systems
- ochinchina/supervisord
- immortal/immortal
- willscott/go-nfs
- kahing/goofys
- progrium/macdriver
- Native Mac APIs for Go
- gokrazy/gokrazy
- Go+Linux Kernel+RPi firmware on Board
- lmorg/murex
- Bash-like
Lower Level
- mmcloughlin/avo
- Generate x86 Assembly with Go
- twitchyliquid64/golang-asm
ML/机器学习
- sjwhitworth/golearn is a 'batteries included' machine learning library for Go. Simplicity, paired with customisability, is the goal.
- cdipaolo/goml is a machine learning library written entirely in Golang which lets the average developer include machine learning into their applications.
- chewxy/gorgonia is a library that helps facilitate machine learning in Go. Write and evaluate mathematical equations involving multidimensional arrays easily.
- nlpodyssey/spago
SIP/WebRTC
- rtctunnel/rtctunnel network tunnels over WebRTC
- ghettovoice/gosip SIP in GO
- jaroszan/sip SIP simulator in Go
- xiaochengtech/sip Go 实现的 RFC3261-SIP 协议
- KalbiProject/Kalbi Golang SIP framework
- sip client.go
- 简单处理 Register
Command Line
- charmbracelet/bubbletea TUI framework
Office
Internal
- https://github.com/emluque/golang-internals-resources
- https://github.com/teh-cmc/go-internals
- https://www.altoros.com/blog/golang-internals-part-1-main-concepts-and-project-structure/
- https://github.com/golang/go/tree/master/src/cmd/compile
Tools
- https://github.com/natesales/q
- GPL-3.0
- command line DNS client with support for UDP, TCP, DoT, DoH, DoQ and ODoH
- ogham/dog
参考
TBD
Utils
- jinzhu/now Now is a time toolkit for golang
- benmanns/goworker Go-based background worker
- dustin/go-humanize
- 格式化数据大小, 时间和数字等
- dropbox/godropbox Common libraries for writing Go services/applications.
- asciimoo/wuzz Interactive cli tool for HTTP inspection
- goreleaser/goreleaser Deliver Go binaries as fast and easily as possible
Console
- jroimartin/gocui Minimalist Go package aimed at creating Console User Interfaces.
- nsf/termbox-go Pure Go termbox implementation
Data
Web
- Auth
- https://github.com/markbates/goth
- Package goth provides a simple, clean, and idiomatic way to write authentication packages for Go web applications.
- https://github.com/markbates/goth
- https://gitea.com/lunny/tango
Misc
- https://github.com/geziyor/geziyor
- https://github.com/alexflint/go-restructure
- https://github.com/pointlander/peg Peg, Parsing Expression Grammar
- https://github.com/hanwen/go-fuse
Hardware
- https://github.com/ycoroneos/golang_embedded
- ycoroneos/G.E.R.T
- Golang Embedded Run-Time
- https://news.ycombinator.com/item?id=15591847
- https://news.ycombinator.com/item?id=14590847
- https://bugs.alpinelinux.org/issues/4276
- gcc-arm-none-eabi
Scripts
- https://github.com/peterh/liner line editor with history
- https://github.com/dop251/goja ECMAScript/JavaScript engine
- https://github.com/elves/elvish