# Packages
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# README
pkg
- golang pkg, common utils
- 集成各种常用 lib, 开箱即用
related:
- https://github.com/better-go/cookiecutter-go
go 微服务
: 项目创建脚手架.
quickstart:
快速导包:
- ✅ 导入包:
import (
// 子包
"github.com/better-go/pkg/log"
)
- ✅ install:
# use latest version:
go get -u -v github.com/better-go/pkg
# use specific tag:
go get -u -v github.com/better-go/[email protected]
- ✅ usage:
import (
"github.com/better-go/pkg/random"
)
func Example() {
// snowflake id:
userID := random.SnowFlakeID()
fmt.Printf("userID:%v\n", userID)
}
features:
-
log
: log/log.go 集成uber.log
, 开箱即用. - sync/async:
go func()
优雅异步. -
retry
: 通用重试wrap: 支持 backoff -
orm
集成:gorm
扩展- mysql 支持
- 集成
gorm v1, v2
版本
-
cache
: 集成redis
-
mq
:- kafka: 集成
kafka
- rabbitmq: 集成
rabbitmq
, 有详细使用示例代码
- kafka: 集成
-
net
:- http: 集成
gin
+auth
API 路由鉴权 - websocket: 集成
websocket
, 双向通信, 有详细使用示例代码- server: net/ws/websocket_server.go
- usage: net/ws/example/ws_server.go
- server: net/ws/websocket_server.go
- socketIO: 类似
websocket
, 双向通信, 有详细使用示例代码- server:
- graphql: 集成
- client: net/graphql/graphql_client.go
- server: net/graphql/graphql_server.go
- http: 集成
-
config
:- toml 格式配置文件读取
-
random
:-
uuid
: ID 生成器 -
snowflake
: twitter 雪花算法: 18位纯数字(有序+递增+唯一)
-
-
text
:- xss: 预防 xss 校验
-
time
: 大量时间方法扩展- 生成时间戳
- container: 扩展数据类型
- dict: 字典数据类型
- StringDict:
map[string]string
扩展, 支持生成url encode string
- Dict:
map[string]interface{}
扩展
- StringDict:
- dict: 字典数据类型
- convert: 数据格式转换工具
- crypto`: 加密/解密工具
-
com
: 第三方企业 API SDK 接入- jpush: 极光推送
- sendcloud: 搜狐短信服务
- cronjob: 集成
cron job
库, 开箱即用, -
x
: 扩展一些框架-
gin
: 扩展代码- 路由 wrap: x/gin/router.go 自动处理 request args binding 和 response
-
go-micro
: -
go-zero
:- 微服务启动器: x/go-zero/cmd/cmd.go
-
wiki:
development:
- setup:
# required tool:
brew install go-task/tap/go-task
# this project root folder:
cd pkg/
# init:
task init
# get go pkg:
task tidy
reference:
- uber.log
- 目录结构参考: https://github.com/micro/go-plugins
- 目录风格, 参考 go 标准库, 以及
x
库 - https://github.com/golang/text
go get golang.org/x/text
go get golang.org/x/oauth2
go get golang.org/x/net
go get golang.org/x/crypto
research:
- https://go.libhunt.com/
- go pkg diff