Compare commits

...

2 Commits

Author SHA1 Message Date
tx7do
40ec693f17 feat: rpc. 2024-11-13 23:48:48 +08:00
tx7do
968f1b72b0 feat: upgrade go.mod. 2024-11-13 13:41:34 +08:00
5 changed files with 36 additions and 48 deletions

32
go.mod
View File

@@ -45,23 +45,23 @@ require (
github.com/olekukonko/tablewriter v0.0.5
github.com/spf13/cobra v1.8.1
github.com/tx7do/kratos-bootstrap/api v0.0.5
github.com/tx7do/kratos-bootstrap/config/apollo v0.0.4
github.com/tx7do/kratos-bootstrap/config/consul v0.0.4
github.com/tx7do/kratos-bootstrap/config/etcd v0.0.4
github.com/tx7do/kratos-bootstrap/config/kubernetes v0.0.4
github.com/tx7do/kratos-bootstrap/config/nacos v0.0.4
github.com/tx7do/kratos-bootstrap/config/apollo v0.0.5
github.com/tx7do/kratos-bootstrap/config/consul v0.0.5
github.com/tx7do/kratos-bootstrap/config/etcd v0.0.5
github.com/tx7do/kratos-bootstrap/config/kubernetes v0.0.5
github.com/tx7do/kratos-bootstrap/config/nacos v0.0.5
github.com/tx7do/kratos-bootstrap/config/polaris v0.0.1
github.com/tx7do/kratos-bootstrap/logger/fluent v0.0.4
github.com/tx7do/kratos-bootstrap/logger/logrus v0.0.4
github.com/tx7do/kratos-bootstrap/logger/tencent v0.0.4
github.com/tx7do/kratos-bootstrap/logger/zap v0.0.4
github.com/tx7do/kratos-bootstrap/registry/consul v0.0.4
github.com/tx7do/kratos-bootstrap/registry/etcd v0.0.4
github.com/tx7do/kratos-bootstrap/registry/eureka v0.0.4
github.com/tx7do/kratos-bootstrap/registry/kubernetes v0.0.4
github.com/tx7do/kratos-bootstrap/registry/nacos v0.0.4
github.com/tx7do/kratos-bootstrap/registry/servicecomb v0.0.4
github.com/tx7do/kratos-bootstrap/registry/zookeeper v0.0.4
github.com/tx7do/kratos-bootstrap/logger/fluent v0.0.5
github.com/tx7do/kratos-bootstrap/logger/logrus v0.0.5
github.com/tx7do/kratos-bootstrap/logger/tencent v0.0.5
github.com/tx7do/kratos-bootstrap/logger/zap v0.0.5
github.com/tx7do/kratos-bootstrap/registry/consul v0.0.5
github.com/tx7do/kratos-bootstrap/registry/etcd v0.0.5
github.com/tx7do/kratos-bootstrap/registry/eureka v0.0.5
github.com/tx7do/kratos-bootstrap/registry/kubernetes v0.0.5
github.com/tx7do/kratos-bootstrap/registry/nacos v0.0.5
github.com/tx7do/kratos-bootstrap/registry/servicecomb v0.0.5
github.com/tx7do/kratos-bootstrap/registry/zookeeper v0.0.5
go.opentelemetry.io/otel v1.32.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.32.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.32.0

View File

@@ -29,14 +29,10 @@ import (
const defaultTimeout = 5 * time.Second
// CreateGrpcClient 创建GRPC客户端
func CreateGrpcClient(ctx context.Context, r registry.Discovery, serviceName string, cfg *conf.Bootstrap, opts ...kratosGrpc.ClientOption) grpc.ClientConnInterface {
func CreateGrpcClient(ctx context.Context, r registry.Discovery, serviceName string, cfg *conf.Bootstrap, mds ...middleware.Middleware) grpc.ClientConnInterface {
var options []kratosGrpc.ClientOption
if opts != nil {
options = append(options, opts...)
}
options = append(options, kratosGrpc.WithDiscovery(r))
var endpoint string
@@ -47,7 +43,7 @@ func CreateGrpcClient(ctx context.Context, r registry.Discovery, serviceName str
}
options = append(options, kratosGrpc.WithEndpoint(endpoint))
options = append(options, initGrpcClientConfig(cfg)...)
options = append(options, initGrpcClientConfig(cfg, mds...)...)
conn, err := kratosGrpc.DialInsecure(ctx, options...)
if err != nil {
@@ -57,7 +53,7 @@ func CreateGrpcClient(ctx context.Context, r registry.Discovery, serviceName str
return conn
}
func initGrpcClientConfig(cfg *conf.Bootstrap) []kratosGrpc.ClientOption {
func initGrpcClientConfig(cfg *conf.Bootstrap, mds ...middleware.Middleware) []kratosGrpc.ClientOption {
if cfg.Client == nil || cfg.Client.Grpc == nil {
return nil
}
@@ -70,9 +66,9 @@ func initGrpcClientConfig(cfg *conf.Bootstrap) []kratosGrpc.ClientOption {
}
options = append(options, kratosGrpc.WithTimeout(timeout))
var ms []middleware.Middleware
ms = append(ms, mds...)
if cfg.Client.Grpc.Middleware != nil {
var ms []middleware.Middleware
if cfg.Client.Grpc.Middleware.GetEnableRecovery() {
ms = append(ms, recovery.Recovery())
}
@@ -83,6 +79,7 @@ func initGrpcClientConfig(cfg *conf.Bootstrap) []kratosGrpc.ClientOption {
ms = append(ms, validate.Validator())
}
}
options = append(options, kratosGrpc.WithMiddleware(ms...))
if cfg.Client.Grpc.Tls != nil {
var tlsCfg *tls.Config
@@ -116,30 +113,26 @@ func initGrpcClientConfig(cfg *conf.Bootstrap) []kratosGrpc.ClientOption {
}
// CreateGrpcServer 创建GRPC服务端
func CreateGrpcServer(cfg *conf.Bootstrap, opts ...kratosGrpc.ServerOption) *kratosGrpc.Server {
func CreateGrpcServer(cfg *conf.Bootstrap, mds ...middleware.Middleware) *kratosGrpc.Server {
var options []kratosGrpc.ServerOption
if opts != nil {
options = append(options, opts...)
}
options = append(options, initGrpcServerConfig(cfg)...)
options = append(options, initGrpcServerConfig(cfg, mds...)...)
srv := kratosGrpc.NewServer(options...)
return srv
}
func initGrpcServerConfig(cfg *conf.Bootstrap) []kratosGrpc.ServerOption {
func initGrpcServerConfig(cfg *conf.Bootstrap, mds ...middleware.Middleware) []kratosGrpc.ServerOption {
if cfg.Server == nil || cfg.Server.Grpc == nil {
return nil
}
var options []kratosGrpc.ServerOption
var ms []middleware.Middleware
ms = append(ms, mds...)
if cfg.Server.Grpc.Middleware != nil {
var ms []middleware.Middleware
if cfg.Server.Grpc.Middleware.GetEnableRecovery() {
ms = append(ms, recovery.Recovery())
}
@@ -159,9 +152,8 @@ func initGrpcServerConfig(cfg *conf.Bootstrap) []kratosGrpc.ServerOption {
}
ms = append(ms, midRateLimit.Server(midRateLimit.WithLimiter(limiter)))
}
options = append(options, kratosGrpc.Middleware(ms...))
}
options = append(options, kratosGrpc.Middleware(ms...))
if cfg.Server.Grpc.Tls != nil {
var tlsCfg *tls.Config

View File

@@ -22,14 +22,10 @@ import (
)
// CreateRestServer 创建REST服务端
func CreateRestServer(cfg *conf.Bootstrap, opts ...kratosRest.ServerOption) *kratosRest.Server {
func CreateRestServer(cfg *conf.Bootstrap, mds ...middleware.Middleware) *kratosRest.Server {
var options []kratosRest.ServerOption
if opts != nil {
options = append(options, opts...)
}
options = append(options, initRestConfig(cfg)...)
options = append(options, initRestConfig(cfg, mds...)...)
srv := kratosRest.NewServer(options...)
@@ -40,7 +36,7 @@ func CreateRestServer(cfg *conf.Bootstrap, opts ...kratosRest.ServerOption) *kra
return srv
}
func initRestConfig(cfg *conf.Bootstrap) []kratosRest.ServerOption {
func initRestConfig(cfg *conf.Bootstrap, mds ...middleware.Middleware) []kratosRest.ServerOption {
if cfg.Server == nil || cfg.Server.Rest == nil {
return nil
}
@@ -55,9 +51,9 @@ func initRestConfig(cfg *conf.Bootstrap) []kratosRest.ServerOption {
)))
}
var ms []middleware.Middleware
ms = append(ms, mds...)
if cfg.Server.Rest.Middleware != nil {
var ms []middleware.Middleware
if cfg.Server.Rest.Middleware.GetEnableRecovery() {
ms = append(ms, recovery.Recovery())
}
@@ -77,9 +73,8 @@ func initRestConfig(cfg *conf.Bootstrap) []kratosRest.ServerOption {
}
ms = append(ms, midRateLimit.Server(midRateLimit.WithLimiter(limiter)))
}
options = append(options, kratosRest.Middleware(ms...))
}
options = append(options, kratosRest.Middleware(ms...))
if cfg.Server.Rest.Network != "" {
options = append(options, kratosRest.Network(cfg.Server.Rest.Network))

View File

@@ -26,6 +26,6 @@ git tag registry/polaris/v0.0.5 --force
git tag registry/servicecomb/v0.0.5 --force
git tag registry/zookeeper/v0.0.5 --force
git tag v0.3.12
git tag v0.3.14
git push origin --tags

View File

@@ -86,5 +86,6 @@ cd ../zookeeper
go get all
go mod tidy
cd ../../
go get all
go mod tidy