Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
40ec693f17 |
32
rpc/grpc.go
32
rpc/grpc.go
@@ -29,14 +29,10 @@ import (
|
|||||||
const defaultTimeout = 5 * time.Second
|
const defaultTimeout = 5 * time.Second
|
||||||
|
|
||||||
// CreateGrpcClient 创建GRPC客户端
|
// 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
|
var options []kratosGrpc.ClientOption
|
||||||
|
|
||||||
if opts != nil {
|
|
||||||
options = append(options, opts...)
|
|
||||||
}
|
|
||||||
|
|
||||||
options = append(options, kratosGrpc.WithDiscovery(r))
|
options = append(options, kratosGrpc.WithDiscovery(r))
|
||||||
|
|
||||||
var endpoint string
|
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, kratosGrpc.WithEndpoint(endpoint))
|
||||||
|
|
||||||
options = append(options, initGrpcClientConfig(cfg)...)
|
options = append(options, initGrpcClientConfig(cfg, mds...)...)
|
||||||
|
|
||||||
conn, err := kratosGrpc.DialInsecure(ctx, options...)
|
conn, err := kratosGrpc.DialInsecure(ctx, options...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -57,7 +53,7 @@ func CreateGrpcClient(ctx context.Context, r registry.Discovery, serviceName str
|
|||||||
return conn
|
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 {
|
if cfg.Client == nil || cfg.Client.Grpc == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -70,9 +66,9 @@ func initGrpcClientConfig(cfg *conf.Bootstrap) []kratosGrpc.ClientOption {
|
|||||||
}
|
}
|
||||||
options = append(options, kratosGrpc.WithTimeout(timeout))
|
options = append(options, kratosGrpc.WithTimeout(timeout))
|
||||||
|
|
||||||
|
var ms []middleware.Middleware
|
||||||
|
ms = append(ms, mds...)
|
||||||
if cfg.Client.Grpc.Middleware != nil {
|
if cfg.Client.Grpc.Middleware != nil {
|
||||||
var ms []middleware.Middleware
|
|
||||||
|
|
||||||
if cfg.Client.Grpc.Middleware.GetEnableRecovery() {
|
if cfg.Client.Grpc.Middleware.GetEnableRecovery() {
|
||||||
ms = append(ms, recovery.Recovery())
|
ms = append(ms, recovery.Recovery())
|
||||||
}
|
}
|
||||||
@@ -83,6 +79,7 @@ func initGrpcClientConfig(cfg *conf.Bootstrap) []kratosGrpc.ClientOption {
|
|||||||
ms = append(ms, validate.Validator())
|
ms = append(ms, validate.Validator())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
options = append(options, kratosGrpc.WithMiddleware(ms...))
|
||||||
|
|
||||||
if cfg.Client.Grpc.Tls != nil {
|
if cfg.Client.Grpc.Tls != nil {
|
||||||
var tlsCfg *tls.Config
|
var tlsCfg *tls.Config
|
||||||
@@ -116,30 +113,26 @@ func initGrpcClientConfig(cfg *conf.Bootstrap) []kratosGrpc.ClientOption {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CreateGrpcServer 创建GRPC服务端
|
// 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
|
var options []kratosGrpc.ServerOption
|
||||||
|
|
||||||
if opts != nil {
|
options = append(options, initGrpcServerConfig(cfg, mds...)...)
|
||||||
options = append(options, opts...)
|
|
||||||
}
|
|
||||||
|
|
||||||
options = append(options, initGrpcServerConfig(cfg)...)
|
|
||||||
|
|
||||||
srv := kratosGrpc.NewServer(options...)
|
srv := kratosGrpc.NewServer(options...)
|
||||||
|
|
||||||
return srv
|
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 {
|
if cfg.Server == nil || cfg.Server.Grpc == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var options []kratosGrpc.ServerOption
|
var options []kratosGrpc.ServerOption
|
||||||
|
|
||||||
|
var ms []middleware.Middleware
|
||||||
|
ms = append(ms, mds...)
|
||||||
if cfg.Server.Grpc.Middleware != nil {
|
if cfg.Server.Grpc.Middleware != nil {
|
||||||
var ms []middleware.Middleware
|
|
||||||
|
|
||||||
if cfg.Server.Grpc.Middleware.GetEnableRecovery() {
|
if cfg.Server.Grpc.Middleware.GetEnableRecovery() {
|
||||||
ms = append(ms, recovery.Recovery())
|
ms = append(ms, recovery.Recovery())
|
||||||
}
|
}
|
||||||
@@ -159,9 +152,8 @@ func initGrpcServerConfig(cfg *conf.Bootstrap) []kratosGrpc.ServerOption {
|
|||||||
}
|
}
|
||||||
ms = append(ms, midRateLimit.Server(midRateLimit.WithLimiter(limiter)))
|
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 {
|
if cfg.Server.Grpc.Tls != nil {
|
||||||
var tlsCfg *tls.Config
|
var tlsCfg *tls.Config
|
||||||
|
|||||||
17
rpc/rest.go
17
rpc/rest.go
@@ -22,14 +22,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// CreateRestServer 创建REST服务端
|
// 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
|
var options []kratosRest.ServerOption
|
||||||
|
|
||||||
if opts != nil {
|
options = append(options, initRestConfig(cfg, mds...)...)
|
||||||
options = append(options, opts...)
|
|
||||||
}
|
|
||||||
|
|
||||||
options = append(options, initRestConfig(cfg)...)
|
|
||||||
|
|
||||||
srv := kratosRest.NewServer(options...)
|
srv := kratosRest.NewServer(options...)
|
||||||
|
|
||||||
@@ -40,7 +36,7 @@ func CreateRestServer(cfg *conf.Bootstrap, opts ...kratosRest.ServerOption) *kra
|
|||||||
return srv
|
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 {
|
if cfg.Server == nil || cfg.Server.Rest == nil {
|
||||||
return 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 {
|
if cfg.Server.Rest.Middleware != nil {
|
||||||
var ms []middleware.Middleware
|
|
||||||
|
|
||||||
if cfg.Server.Rest.Middleware.GetEnableRecovery() {
|
if cfg.Server.Rest.Middleware.GetEnableRecovery() {
|
||||||
ms = append(ms, recovery.Recovery())
|
ms = append(ms, recovery.Recovery())
|
||||||
}
|
}
|
||||||
@@ -77,9 +73,8 @@ func initRestConfig(cfg *conf.Bootstrap) []kratosRest.ServerOption {
|
|||||||
}
|
}
|
||||||
ms = append(ms, midRateLimit.Server(midRateLimit.WithLimiter(limiter)))
|
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 != "" {
|
if cfg.Server.Rest.Network != "" {
|
||||||
options = append(options, kratosRest.Network(cfg.Server.Rest.Network))
|
options = append(options, kratosRest.Network(cfg.Server.Rest.Network))
|
||||||
|
|||||||
2
tag.bat
2
tag.bat
@@ -26,6 +26,6 @@ git tag registry/polaris/v0.0.5 --force
|
|||||||
git tag registry/servicecomb/v0.0.5 --force
|
git tag registry/servicecomb/v0.0.5 --force
|
||||||
git tag registry/zookeeper/v0.0.5 --force
|
git tag registry/zookeeper/v0.0.5 --force
|
||||||
|
|
||||||
git tag v0.3.13
|
git tag v0.3.14
|
||||||
|
|
||||||
git push origin --tags
|
git push origin --tags
|
||||||
|
|||||||
Reference in New Issue
Block a user