Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/go_modules/github.com/gin-contr…
Browse files Browse the repository at this point in the history
…ib/cors-1.6.0
  • Loading branch information
qloog authored Oct 29, 2024
2 parents 686bca6 + fd50eb5 commit 30e27c4
Show file tree
Hide file tree
Showing 24 changed files with 445 additions and 149 deletions.
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
## Changelog
# Changelog

## v1.10.0

- feat: support async flush log to disk
- feat: add re-entry and automatic renewal for redis lock
- feat: add gorm logger
- chore: using gorm offical plguin for tracing and metrics

## v1.9.0

- feat: support clickhouse
- chore: upgrade go to v1.22.3
- chore: optimize log and orm

## v1.8.2
- feat: support PostgreSQL
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ Eagle utilizes a classic layered structure and employs the Wire dependency injec
## Installtion CLI

```bash
GOPROXY="https://goproxy.cn,direct"

# go >= 1.16
go install github.com/go-eagle/eagle/cmd/eagle@latest

Expand All @@ -86,15 +88,15 @@ eagle new eagle-demo
eagle new github.com/foo/eagle-demo

# gen a server with http and gRPC
eagle new -b=all eagle-demo
eagle new -b=main eagle-demo
# or
eagle new github.com/foo/eagle-demo

# build
make build
# install dependence
go mod tidy

# run
eagle run
make run
```

## Documentation
Expand Down
4 changes: 3 additions & 1 deletion cmd/eagle/internal/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ func Run(cmd *cobra.Command, args []string) {
return
} else if len(cmdPath) == 1 {
for k, v := range cmdPath {
dir = path.Join(v, k)
selectedDir = k
dir = v
}
} else {
var cmdPaths []string
Expand All @@ -71,6 +72,7 @@ func Run(cmd *cobra.Command, args []string) {

// go run /path/cmd/server
fd := exec.Command("go", []string{"run", path.Join(dir, selectedDir)}...)
fd.Env = os.Environ()
fd.Stdout = os.Stdout
fd.Stderr = os.Stderr
fd.Dir = dir
Expand Down
2 changes: 1 addition & 1 deletion cmd/eagle/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

var (
// Version is the version of the compiled software.
Version = "v0.18.0"
Version = "v0.18.1"

rootCmd = &cobra.Command{
Use: "eagle",
Expand Down
23 changes: 12 additions & 11 deletions config/docker/database.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
default:
Driver: mysql # 驱动名称,目前支持 mysql,postgres,默认: mysql
Name: eagle # 数据库名称
Addr: db:3306 # 如果是 docker,可以替换为 对应的服务名称,eg: db:3306
Driver: mysql # 驱动名称,目前支持 mysql,postgres,默认: mysql
Name: eagle # 数据库名称
Addr: db:3306 # 如果是 docker,可以替换为 对应的服务名称,eg: db:3306
UserName: root
Password: root
ShowLog: true # 是否打印所有SQL日志
MaxIdleConn: 10 # 最大闲置的连接数,0意味着使用默认的大小2, 小于0表示不使用连接池
MaxOpenConn: 60 # 最大打开的连接数, 需要小于数据库配置中的max_connections数
Timeout: 3s # 数据库连接超时时间
ReadTimeout: 3s # 数据库去读超时时间, 0代表不限制
WriteTimeout: 3s # 数据库写入超时时间, 0代表不限制
ConnMaxLifeTime: 4h # 单个连接最大存活时间,建议设置比数据库超时时长(wait_timeout)稍小一些
SlowThreshold: 500ms # 慢查询阈值,设置后只打印慢查询日志,默认为200ms
ShowLog: true # 是否打印所有SQL日志
MaxIdleConn: 10 # 最大闲置的连接数,0意味着使用默认的大小2, 小于0表示不使用连接池
MaxOpenConn: 60 # 最大打开的连接数, 需要小于数据库配置中的max_connections数
Timeout: 3s # 数据库连接超时时间
ReadTimeout: 3s # 数据库去读超时时间, 0代表不限制
WriteTimeout: 3s # 数据库写入超时时间, 0代表不限制
ConnMaxLifeTime: 4h # 单个连接最大存活时间,建议设置比数据库超时时长(wait_timeout)稍小一些
SlowThreshold: 500ms # 慢查询阈值,设置后只打印慢查询日志,默认为200ms
EnableTrace: false
10 changes: 6 additions & 4 deletions config/docker/logger.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
Development: false
DisableCaller: false
DisableStacktrace: false
Encoding: json # json or console
Level: info # 日志级别,INFO, WARN, ERROR
Name: eagle
Writers: console # 有2个可选项:file,console 选择file会将日志记录到logger_file指定的日志文件中,选择console会将日志输出到标准输出,当然也可以两者同时选择
Encoding: json # json or console
Level: info # 日志级别,INFO, WARN, ERROR
ServiceName: user-service
Filename: eagle
Writers: console # 有2个可选项:file,console 选择file会将日志记录到logger_file指定的日志文件中,选择console会将日志输出到标准输出,当然也可以两者同时选择
LoggerDir: /data/logs
LogRollingPolicy: daily
LogRotateDate: 1
LogRotateSize: 1
LogBackupCount: 7
FlushInterval: 1s
46 changes: 24 additions & 22 deletions config/local/database.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
default:
Driver: mysql # 驱动名称,目前支持: mysql,postgres,默认: mysql
Name: eagle # 数据库名称
Addr: localhost:3306 # 如果是 docker,可以替换为 对应的服务名称,eg: db:3306, pg:5432
Driver: mysql # 驱动名称,目前支持: mysql,postgres,默认: mysql
Name: eagle # 数据库名称
Addr: localhost:3306 # 如果是 docker,可以替换为 对应的服务名称,eg: db:3306, pg:5432
UserName: root
Password: 123456
ShowLog: true # 是否打印所有SQL日志
MaxIdleConn: 10 # 最大闲置的连接数,0意味着使用默认的大小2, 小于0表示不使用连接池
MaxOpenConn: 60 # 最大打开的连接数, 需要小于数据库配置中的max_connections数
Timeout: 3s # 数据库连接超时时间, 如果是 PostgreSQL 不需要加入单位
ReadTimeout: 3s # 数据库去读超时时间, 0代表不限制,如果是PostgreSQL, 3000代表3s
WriteTimeout: 3s # 数据库写入超时时间, 0代表不限制,如果是PostgreSQL, 不会使用该字段的值
ConnMaxLifeTime: 4h # 单个连接最大存活时间,建议设置比数据库超时时长(wait_timeout)稍小一些
SlowThreshold: 500ms # 慢查询阈值,设置后只打印慢查询日志,默认为200ms
ShowLog: true # 是否打印所有SQL日志
MaxIdleConn: 10 # 最大闲置的连接数,0意味着使用默认的大小2, 小于0表示不使用连接池
MaxOpenConn: 60 # 最大打开的连接数, 需要小于数据库配置中的max_connections数
Timeout: 3s # 数据库连接超时时间, 如果是 PostgreSQL 不需要加入单位
ReadTimeout: 3s # 数据库去读超时时间, 0代表不限制,如果是PostgreSQL, 3000代表3s
WriteTimeout: 3s # 数据库写入超时时间, 0代表不限制,如果是PostgreSQL, 不会使用该字段的值
ConnMaxLifeTime: 4h # 单个连接最大存活时间,建议设置比数据库超时时长(wait_timeout)稍小一些
SlowThreshold: 500ms # 慢查询阈值,设置后只打印慢查询日志,默认为200ms
EnableTrace: false
user:
Driver: mysql # 驱动名称,目前支持: mysql,postgres,默认: mysql
Name: eagle # 数据库名称
Addr: localhost:3306 # 如果是 docker,可以替换为 对应的服务名称,eg: db:3306, pg:5432
Driver: mysql # 驱动名称,目前支持: mysql,postgres,默认: mysql
Name: eagle # 数据库名称
Addr: localhost:3306 # 如果是 docker,可以替换为 对应的服务名称,eg: db:3306, pg:5432
UserName: root
Password: 123456
ShowLog: true # 是否打印所有SQL日志
MaxIdleConn: 10 # 最大闲置的连接数,0意味着使用默认的大小2, 小于0表示不使用连接池
MaxOpenConn: 60 # 最大打开的连接数, 需要小于数据库配置中的max_connections数
Timeout: 3s # 数据库连接超时时间
ReadTimeout: 3s # 数据库去读超时时间, 0代表不限制
WriteTimeout: 3s # 数据库写入超时时间, 0代表不限制
ConnMaxLifeTime: 4h # 单个连接最大存活时间,建议设置比数据库超时时长(wait_timeout)稍小一些
SlowThreshold: 500ms # 慢查询阈值,设置后只打印慢查询日志,默认为200ms
ShowLog: true # 是否打印所有SQL日志
MaxIdleConn: 10 # 最大闲置的连接数,0意味着使用默认的大小2, 小于0表示不使用连接池
MaxOpenConn: 60 # 最大打开的连接数, 需要小于数据库配置中的max_connections数
Timeout: 3s # 数据库连接超时时间
ReadTimeout: 3s # 数据库去读超时时间, 0代表不限制
WriteTimeout: 3s # 数据库写入超时时间, 0代表不限制
ConnMaxLifeTime: 4h # 单个连接最大存活时间,建议设置比数据库超时时长(wait_timeout)稍小一些
SlowThreshold: 500ms # 慢查询阈值,设置后只打印慢查询日志,默认为200ms
EnableTrace: false
10 changes: 6 additions & 4 deletions config/local/logger.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
Development: false
DisableCaller: false
DisableStacktrace: false
Encoding: json # json or console
Level: info # 日志级别,INFO, WARN, ERROR
Name: eagle
Writers: console # 有2个可选项:file,console 选择file会将日志记录到logger_file指定的日志文件中,选择console会将日志输出到标准输出,当然也可以两者同时选择
Encoding: json # json or console
Level: info # 日志级别,INFO, WARN, ERROR
ServiceName: user-service
Filename: eagle
Writers: console # 有2个可选项:file,console 选择file会将日志记录到logger_file指定的日志文件中,选择console会将日志输出到标准输出,当然也可以两者同时选择
LoggerDir: /data/logs
LogRollingPolicy: daily
LogRotateDate: 1
LogRotateSize: 1
LogBackupCount: 7
FlushInterval: 1s
9 changes: 5 additions & 4 deletions examples/log/logger.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
Development: false
DisableCaller: false
DisableStacktrace: false
Encoding: json # json or console
Level: info # 日志级别,INFO, WARN, ERROR
Name: eagle
Writers: file # 有2个可选项:file,console 选择file会将日志记录到logger_file指定的日志文件中,选择console会将日志输出到标准输出,当然也可以两者同时选择
Encoding: json # json or console
Level: info # 日志级别,INFO, WARN, ERROR
ServiceName: demo-service
Filename: demo-file
Writers: file # 有2个可选项:file,console 选择file会将日志记录到logger_file指定的日志文件中,选择console会将日志输出到标准输出,当然也可以两者同时选择
LoggerDir: /tmp/logs
LogRollingPolicy: daily
LogRotateDate: 1
Expand Down
2 changes: 1 addition & 1 deletion examples/log/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func main() {
log.Info("test log")

// print log using custom filename
log.Init(log.WithFilename("custom"))
log.Init(log.WithFilename("custom-filename"))
log.Info("test log with filename")

// print log using custom dir and filename
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
module github.com/go-eagle/eagle

go 1.21
go 1.22.3

require (
github.com/1024casts/gorm-opentelemetry v1.0.1-0.20210805144709-183269b54068
github.com/Shopify/sarama v1.19.0
github.com/alicebob/miniredis/v2 v2.15.1
github.com/cenkalti/backoff/v4 v4.2.1
Expand Down Expand Up @@ -74,6 +73,7 @@ require (
gorm.io/driver/mysql v1.5.2
gorm.io/driver/postgres v1.5.4
gorm.io/gorm v1.25.10
gorm.io/plugin/opentelemetry v0.1.4
)

require (
Expand Down Expand Up @@ -172,6 +172,7 @@ require (
github.com/shopspring/decimal v1.4.0 // indirect
github.com/spf13/afero v1.9.2 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/swaggo/swag v1.7.0 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
Expand Down
11 changes: 4 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RX
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/1024casts/gorm-opentelemetry v1.0.1-0.20210805144709-183269b54068 h1:XWMHFSEROBGd33gZNMsTb6zxECMN8xOJkO0ucOJdz58=
github.com/1024casts/gorm-opentelemetry v1.0.1-0.20210805144709-183269b54068/go.mod h1:nEAgMK5Iab8nqYy8zn1tYjEjkeDA2PmszXOwZhlDrMs=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
Expand Down Expand Up @@ -428,7 +426,6 @@ github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk
github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
Expand Down Expand Up @@ -1266,13 +1263,13 @@ gorm.io/driver/mysql v1.5.2 h1:QC2HRskSE75wBuOxe0+iCkyJZ+RqpudsQtqkp+IMuXs=
gorm.io/driver/mysql v1.5.2/go.mod h1:pQLhh1Ut/WUAySdTHwBpBv6+JKcj+ua4ZFx1QQTBzb8=
gorm.io/driver/postgres v1.5.4 h1:Iyrp9Meh3GmbSuyIAGyjkN+n9K+GHX9b9MqsTL4EJCo=
gorm.io/driver/postgres v1.5.4/go.mod h1:Bgo89+h0CRcdA33Y6frlaHHVuTdOf87pmyzwW9C/BH0=
gorm.io/driver/sqlite v1.1.4 h1:PDzwYE+sI6De2+mxAneV9Xs11+ZyKV6oxD3wDGkaNvM=
gorm.io/driver/sqlite v1.1.4/go.mod h1:mJCeTFr7+crvS+TRnWc5Z3UvwxUN1BGBLMrf5LA9DYw=
gorm.io/gorm v1.20.7/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
gorm.io/gorm v1.20.12/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
gorm.io/driver/sqlite v1.5.0 h1:zKYbzRCpBrT1bNijRnxLDJWPjVfImGEn0lSnUY5gZ+c=
gorm.io/driver/sqlite v1.5.0/go.mod h1:kDMDfntV9u/vuMmz8APHtHF0b4nyBB7sfCieC6G8k8I=
gorm.io/gorm v1.25.2-0.20230530020048-26663ab9bf55/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
gorm.io/gorm v1.25.10 h1:dQpO+33KalOA+aFYGlK+EfxcI5MbO7EP2yYygwh9h+s=
gorm.io/gorm v1.25.10/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
gorm.io/plugin/opentelemetry v0.1.4 h1:7p0ocWELjSSRI7NCKPW2mVe6h43YPini99sNJcbsTuc=
gorm.io/plugin/opentelemetry v0.1.4/go.mod h1:tndJHOdvPT0pyGhOb8E2209eXJCUxhC5UpKw7bGVWeI=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
Expand Down
16 changes: 8 additions & 8 deletions pkg/errcode/grpc_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,21 @@ func ToRPCCode(code int) codes.Code {
var statusCode codes.Code

switch code {
case ErrInternalServer.code:
case ErrInternalServer.Code():
statusCode = codes.Internal
case ErrInvalidParam.code:
case ErrInvalidParam.Code():
statusCode = codes.InvalidArgument
case ErrUnauthorized.code:
case ErrUnauthorized.Code():
statusCode = codes.Unauthenticated
case ErrNotFound.code:
case ErrNotFound.Code():
statusCode = codes.NotFound
case ErrDeadlineExceeded.code:
case ErrDeadlineExceeded.Code():
statusCode = codes.DeadlineExceeded
case ErrAccessDenied.code:
case ErrAccessDenied.Code():
statusCode = codes.PermissionDenied
case ErrLimitExceed.code:
case ErrLimitExceed.Code():
statusCode = codes.ResourceExhausted
case ErrMethodNotAllowed.code:
case ErrMethodNotAllowed.Code():
statusCode = codes.Unimplemented
default:
statusCode = codes.Unknown
Expand Down
22 changes: 22 additions & 0 deletions pkg/lock/luascript.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package lock

var (
// lockscript lua script for acrequire a lock
lockLuaScript = `
if redis.call("GET", KEYS[1]) == ARGV[1] then
redis.call("SET", KEYS[1], ARGV[1], "PX", ARGV[2])
return "OK"
else
return redis.call("SET", KEYS[1], ARGV[1], "NX", "PX", ARGV[2])
end
`

// unlockscript lua script for release a lock
unlockLuaScript = `
if redis.call("GET", KEYS[1]) == ARGV[1] then
return redis.call("DEL", KEYS[1])
else
return 0
end
`
)
Loading

0 comments on commit 30e27c4

Please sign in to comment.