From 949cf3b48eb3402109f10c6212cc3dedf0bd8308 Mon Sep 17 00:00:00 2001
From: zhuyasen
Date: Sun, 15 Oct 2023 00:15:54 +0800
Subject: [PATCH] adjustment code
---
.github/RELEASE.md | 5 +++--
README.md | 4 ++--
api/serverNameExample/v1/userExample.pb.go | 5 +----
assets/readme-cn.md | 3 ++-
.../initial/registerClose.go | 6 ------
.../initial/registerClose.go | 6 ------
.../initial/registerClose.go | 6 ------
.../initial/registerClose.go | 6 ------
.../initial/registerClose.go | 6 ------
.../initial/registerClose.go | 6 ------
go.mod | 5 +++--
go.sum | 17 ++++++++---------
pkg/logger/method.go | 6 +++++-
13 files changed, 24 insertions(+), 57 deletions(-)
diff --git a/.github/RELEASE.md b/.github/RELEASE.md
index 7b2d2b72..0b55a3a1 100644
--- a/.github/RELEASE.md
+++ b/.github/RELEASE.md
@@ -1,5 +1,6 @@
## Change log
-- The make proto command supports code generation for a given proto file.
- Gorm supports master-slave configuration and custom plugins.
-- Logger library add sync function.
+- The make proto command supports code generation for a given proto file.
+- Jwt authentication support for custom fields and checksum functions.
+- Adding the rabbitmq library.
diff --git a/README.md b/README.md
index 9fd1451d..670fa403 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-## sponge [中文](assets/readme-cn.md)
+## English | [简体中文](assets/readme-cn.md)
@@ -58,7 +58,7 @@ Egg model profiling diagram for `⓷Web services created based on protobuf`:
-This is the egg model for web service code, and there are egg models for microservice (gRPC) code, and rpc gateway service code described in [sponge documentation](https://go-sponge.com/).
+This is the egg model for web service code, and there are egg models for microservice (gRPC) code, and rpc gateway service code described in [sponge documentation](https://go-sponge.com/learn-about-sponge?id=%f0%9f%8f%b7project-code-egg-model).
diff --git a/api/serverNameExample/v1/userExample.pb.go b/api/serverNameExample/v1/userExample.pb.go
index 39c352e0..b75ab249 100644
--- a/api/serverNameExample/v1/userExample.pb.go
+++ b/api/serverNameExample/v1/userExample.pb.go
@@ -10,11 +10,8 @@
package v1
import (
-
-
-
types "github.com/zhufuyi/sponge/api/types"
-
+
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
diff --git a/assets/readme-cn.md b/assets/readme-cn.md
index 63cb6789..7fc51dd0 100644
--- a/assets/readme-cn.md
+++ b/assets/readme-cn.md
@@ -42,7 +42,7 @@ sponge生成代码过程中剥离了业务逻辑与非业务逻辑两大部分
-这是web服务代码鸡蛋模型,还有微服务(gRPC)代码、rpc网关服务代码的鸡蛋模型在[sponge文档](https://go-sponge.com/zh-cn/)中有介绍。
+这是web服务代码鸡蛋模型,还有微服务(gRPC)代码、rpc网关服务代码的鸡蛋模型在[sponge文档](https://go-sponge.com/zh-cn/learn-about-sponge?id=%f0%9f%8f%b7%e9%a1%b9%e7%9b%ae%e4%bb%a3%e7%a0%81%e9%b8%a1%e8%9b%8b%e6%a8%a1%e5%9e%8b)中有介绍。
@@ -60,6 +60,7 @@ sponge包含丰富的组件(按需使用):
- 自动化api接口文档 [swagger](https://github.com/swaggo/swag), [protoc-gen-openapiv2](https://github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2)
- 鉴权 [jwt](https://github.com/golang-jwt/jwt)
- 校验 [validator](https://github.com/go-playground/validator)
+- 消息组件 [rabbitmq](github.com/rabbitmq/amqp091-go)
- 自适应限流 [ratelimit](https://github.com/zhufuyi/sponge/tree/main/pkg/shield/ratelimit)
- 自适应熔断 [circuitbreaker](https://github.com/zhufuyi/sponge/tree/main/pkg/shield/circuitbreaker)
- 链路跟踪 [opentelemetry](https://github.com/open-telemetry/opentelemetry-go)
diff --git a/cmd/serverNameExample_grpcExample/initial/registerClose.go b/cmd/serverNameExample_grpcExample/initial/registerClose.go
index 9ad28fe5..fb2e8d52 100644
--- a/cmd/serverNameExample_grpcExample/initial/registerClose.go
+++ b/cmd/serverNameExample_grpcExample/initial/registerClose.go
@@ -8,7 +8,6 @@ import (
"github.com/zhufuyi/sponge/internal/model"
"github.com/zhufuyi/sponge/pkg/app"
- "github.com/zhufuyi/sponge/pkg/logger"
"github.com/zhufuyi/sponge/pkg/tracer"
)
@@ -41,10 +40,5 @@ func RegisterClose(servers []app.IServer) []app.Close {
})
}
- // logger flushing
- closes = append(closes, func() error {
- return logger.Sync()
- })
-
return closes
}
diff --git a/cmd/serverNameExample_grpcGwPbExample/initial/registerClose.go b/cmd/serverNameExample_grpcGwPbExample/initial/registerClose.go
index 06a2ee45..57cc5734 100644
--- a/cmd/serverNameExample_grpcGwPbExample/initial/registerClose.go
+++ b/cmd/serverNameExample_grpcGwPbExample/initial/registerClose.go
@@ -8,7 +8,6 @@ import (
//"github.com/zhufuyi/sponge/internal/rpcclient"
"github.com/zhufuyi/sponge/pkg/app"
- "github.com/zhufuyi/sponge/pkg/logger"
"github.com/zhufuyi/sponge/pkg/tracer"
)
@@ -35,10 +34,5 @@ func RegisterClose(servers []app.IServer) []app.Close {
})
}
- // logger flushing
- closes = append(closes, func() error {
- return logger.Sync()
- })
-
return closes
}
diff --git a/cmd/serverNameExample_grpcPbExample/initial/registerClose.go b/cmd/serverNameExample_grpcPbExample/initial/registerClose.go
index b925549d..a7344803 100644
--- a/cmd/serverNameExample_grpcPbExample/initial/registerClose.go
+++ b/cmd/serverNameExample_grpcPbExample/initial/registerClose.go
@@ -8,7 +8,6 @@ import (
//"github.com/zhufuyi/sponge/internal/model"
"github.com/zhufuyi/sponge/pkg/app"
- "github.com/zhufuyi/sponge/pkg/logger"
"github.com/zhufuyi/sponge/pkg/tracer"
)
@@ -41,10 +40,5 @@ func RegisterClose(servers []app.IServer) []app.Close {
})
}
- // logger flushing
- closes = append(closes, func() error {
- return logger.Sync()
- })
-
return closes
}
diff --git a/cmd/serverNameExample_httpExample/initial/registerClose.go b/cmd/serverNameExample_httpExample/initial/registerClose.go
index 9ad28fe5..fb2e8d52 100644
--- a/cmd/serverNameExample_httpExample/initial/registerClose.go
+++ b/cmd/serverNameExample_httpExample/initial/registerClose.go
@@ -8,7 +8,6 @@ import (
"github.com/zhufuyi/sponge/internal/model"
"github.com/zhufuyi/sponge/pkg/app"
- "github.com/zhufuyi/sponge/pkg/logger"
"github.com/zhufuyi/sponge/pkg/tracer"
)
@@ -41,10 +40,5 @@ func RegisterClose(servers []app.IServer) []app.Close {
})
}
- // logger flushing
- closes = append(closes, func() error {
- return logger.Sync()
- })
-
return closes
}
diff --git a/cmd/serverNameExample_httpPbExample/initial/registerClose.go b/cmd/serverNameExample_httpPbExample/initial/registerClose.go
index b925549d..a7344803 100644
--- a/cmd/serverNameExample_httpPbExample/initial/registerClose.go
+++ b/cmd/serverNameExample_httpPbExample/initial/registerClose.go
@@ -8,7 +8,6 @@ import (
//"github.com/zhufuyi/sponge/internal/model"
"github.com/zhufuyi/sponge/pkg/app"
- "github.com/zhufuyi/sponge/pkg/logger"
"github.com/zhufuyi/sponge/pkg/tracer"
)
@@ -41,10 +40,5 @@ func RegisterClose(servers []app.IServer) []app.Close {
})
}
- // logger flushing
- closes = append(closes, func() error {
- return logger.Sync()
- })
-
return closes
}
diff --git a/cmd/serverNameExample_mixExample/initial/registerClose.go b/cmd/serverNameExample_mixExample/initial/registerClose.go
index 9ad28fe5..fb2e8d52 100644
--- a/cmd/serverNameExample_mixExample/initial/registerClose.go
+++ b/cmd/serverNameExample_mixExample/initial/registerClose.go
@@ -8,7 +8,6 @@ import (
"github.com/zhufuyi/sponge/internal/model"
"github.com/zhufuyi/sponge/pkg/app"
- "github.com/zhufuyi/sponge/pkg/logger"
"github.com/zhufuyi/sponge/pkg/tracer"
)
@@ -41,10 +40,5 @@ func RegisterClose(servers []app.IServer) []app.Close {
})
}
- // logger flushing
- closes = append(closes, func() error {
- return logger.Sync()
- })
-
return closes
}
diff --git a/go.mod b/go.mod
index 50e99f6e..042216b8 100644
--- a/go.mod
+++ b/go.mod
@@ -16,7 +16,7 @@ require (
github.com/go-redis/redis/extra/redisotel v0.3.0
github.com/go-redis/redis/v8 v8.11.5
github.com/go-sql-driver/mysql v1.7.0
- github.com/golang-jwt/jwt v3.2.2+incompatible
+ github.com/golang-jwt/jwt/v5 v5.0.0
github.com/golang/snappy v0.0.3
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
@@ -28,6 +28,7 @@ require (
github.com/natefinch/lumberjack v2.0.0+incompatible
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.13.0
+ github.com/rabbitmq/amqp091-go v1.9.0
github.com/shirou/gopsutil/v3 v3.23.8
github.com/spf13/cobra v1.4.0
github.com/spf13/viper v1.12.0
@@ -53,6 +54,7 @@ require (
gopkg.in/yaml.v3 v3.0.1
gorm.io/driver/mysql v1.5.1
gorm.io/gorm v1.25.4
+ gorm.io/plugin/dbresolver v1.4.7
)
require (
@@ -172,5 +174,4 @@ require (
gopkg.in/ini.v1 v1.66.4 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
- gorm.io/plugin/dbresolver v1.4.7 // indirect
)
diff --git a/go.sum b/go.sum
index 4fb2071f..9308960e 100644
--- a/go.sum
+++ b/go.sum
@@ -234,7 +234,6 @@ github.com/go-redis/redis/v8 v8.3.2/go.mod h1:jszGxBCez8QA1HWSmQxJO9Y82kNibbUmeY
github.com/go-redis/redis/v8 v8.5.0/go.mod h1:YmEcgBDttjnkbMzDAhDtQxY9yVA7jMN6PCR5HeMvqFE=
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
-github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc=
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
@@ -247,8 +246,8 @@ github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7a
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A=
-github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
-github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
+github.com/golang-jwt/jwt/v5 v5.0.0 h1:1n1XNM9hk7O9mnQoNBGolZvzebBQ7p93ULHRc28XJUE=
+github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/glog v1.0.0 h1:nfP3RFugxnNRyKgeWd4oI1nYvXpxrx8ck8ZrcizshdQ=
github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4=
@@ -570,6 +569,10 @@ github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1
github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
github.com/prometheus/procfs v0.8.0 h1:ODq8ZFEaYeCaZOJlZZdJA2AbQR98dSHSM1KW/You5mo=
github.com/prometheus/procfs v0.8.0/go.mod h1:z7EfXMXOkbkqb9IINtpCn86r/to3BnA0uaxHdg830/4=
+github.com/rabbitmq/amqp091-go v1.8.1 h1:RejT1SBUim5doqcL6s7iN6SBmsQqyTgXb1xMlH0h1hA=
+github.com/rabbitmq/amqp091-go v1.8.1/go.mod h1:+jPrT9iY2eLjRaMSRHUhc3z14E/l85kv/f+6luSD3pc=
+github.com/rabbitmq/amqp091-go v1.9.0 h1:qrQtyzB4H8BQgEuJwhmVQqVHB9O4+MNDJCCAcpc3Aoo=
+github.com/rabbitmq/amqp091-go v1.9.0/go.mod h1:+jPrT9iY2eLjRaMSRHUhc3z14E/l85kv/f+6luSD3pc=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
@@ -707,8 +710,9 @@ go.opentelemetry.io/proto/otlp v0.15.0/go.mod h1:H7XAot3MsfNsj7EXtrA2q5xSNQ10UqI
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
-go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
+go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A=
+go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
@@ -1156,16 +1160,11 @@ gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
-gorm.io/driver/mysql v1.3.5 h1:iWBTVW/8Ij5AG4e0G/zqzaJblYkBI1VIL1LG2HUGsvY=
-gorm.io/driver/mysql v1.3.5/go.mod h1:sSIebwZAVPiT+27jK9HIwvsqOGKx3YMPmrA3mBJR10c=
-gorm.io/driver/mysql v1.4.3 h1:/JhWJhO2v17d8hjApTltKNADm7K7YI2ogkR7avJUL3k=
gorm.io/driver/mysql v1.4.3/go.mod h1:sSIebwZAVPiT+27jK9HIwvsqOGKx3YMPmrA3mBJR10c=
gorm.io/driver/mysql v1.5.1 h1:WUEH5VF9obL/lTtzjmML/5e6VfFR/788coz2uaVCAZw=
gorm.io/driver/mysql v1.5.1/go.mod h1:Jo3Xu7mMhCyj8dlrb3WoCaRd1FhsVh+yMXb1jUInf5o=
-gorm.io/gorm v1.23.8 h1:h8sGJ+biDgBA1AD1Ha9gFCx7h8npU7AsLdlkX0n2TpE=
gorm.io/gorm v1.23.8/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk=
gorm.io/gorm v1.25.1/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
-gorm.io/gorm v1.25.2 h1:gs1o6Vsa+oVKG/a9ElL3XgyGfghFfkKA2SInQaCyMho=
gorm.io/gorm v1.25.2/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
gorm.io/gorm v1.25.4 h1:iyNd8fNAe8W9dvtlgeRI5zSVZPsq3OpcTu37cYcpCmw=
gorm.io/gorm v1.25.4/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
diff --git a/pkg/logger/method.go b/pkg/logger/method.go
index 9f12c61e..1fe34df7 100644
--- a/pkg/logger/method.go
+++ b/pkg/logger/method.go
@@ -2,6 +2,7 @@ package logger
import (
"fmt"
+ "strings"
"go.uber.org/zap"
)
@@ -63,7 +64,10 @@ func Errorf(format string, a ...interface{}) {
// Sync flushing any buffered log entries, applications should take care to call Sync before exiting.
func Sync() error {
- //return getLogger().Sync()
+ err := getLogger().Sync()
+ if err != nil && !strings.Contains(err.Error(), "/dev/stdout") {
+ return err
+ }
return nil
}