config: flatten WorkerConfig to value type in PoolConfig
This commit is contained in:
@@ -16,7 +16,7 @@ type PoolConfig struct {
|
|||||||
EventsBufferSize int
|
EventsBufferSize int
|
||||||
ConnectionConfig transport.ConnectionConfig
|
ConnectionConfig transport.ConnectionConfig
|
||||||
WorkerFactory WorkerFactory
|
WorkerFactory WorkerFactory
|
||||||
WorkerConfig *WorkerConfig
|
WorkerConfig WorkerConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
type PoolOption func(*PoolConfig) error
|
type PoolOption func(*PoolConfig) error
|
||||||
@@ -40,7 +40,7 @@ func GetDefaultPoolConfig() *PoolConfig {
|
|||||||
EventsBufferSize: 10,
|
EventsBufferSize: 10,
|
||||||
ConnectionConfig: *transport.GetDefaultConnectionConfig(),
|
ConnectionConfig: *transport.GetDefaultConnectionConfig(),
|
||||||
WorkerFactory: nil,
|
WorkerFactory: nil,
|
||||||
WorkerConfig: nil,
|
WorkerConfig: *GetDefaultWorkerConfig(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,12 +63,10 @@ func ValidatePoolConfig(config *PoolConfig) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.WorkerConfig != nil {
|
err = ValidateWorkerConfig(&config.WorkerConfig)
|
||||||
err = ValidateWorkerConfig(config.WorkerConfig)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -113,9 +111,9 @@ func WithConnectionConfig(cc transport.ConnectionConfig) PoolOption {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithWorkerConfig(wc *WorkerConfig) PoolOption {
|
func WithWorkerConfig(wc WorkerConfig) PoolOption {
|
||||||
return func(c *PoolConfig) error {
|
return func(c *PoolConfig) error {
|
||||||
err := ValidateWorkerConfig(wc)
|
err := ValidateWorkerConfig(&wc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -15,7 +15,7 @@ func TestNewPoolConfig(t *testing.T) {
|
|||||||
InboxBufferSize: 256,
|
InboxBufferSize: 256,
|
||||||
EventsBufferSize: 10,
|
EventsBufferSize: 10,
|
||||||
ConnectionConfig: *transport.GetDefaultConnectionConfig(),
|
ConnectionConfig: *transport.GetDefaultConnectionConfig(),
|
||||||
WorkerConfig: nil,
|
WorkerConfig: *GetDefaultWorkerConfig(),
|
||||||
WorkerFactory: nil,
|
WorkerFactory: nil,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -27,7 +27,7 @@ func TestDefaultPoolConfig(t *testing.T) {
|
|||||||
InboxBufferSize: 256,
|
InboxBufferSize: 256,
|
||||||
EventsBufferSize: 10,
|
EventsBufferSize: 10,
|
||||||
ConnectionConfig: *transport.GetDefaultConnectionConfig(),
|
ConnectionConfig: *transport.GetDefaultConnectionConfig(),
|
||||||
WorkerConfig: nil,
|
WorkerConfig: *GetDefaultWorkerConfig(),
|
||||||
WorkerFactory: nil,
|
WorkerFactory: nil,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,7 +101,8 @@ func NewPool(ctx context.Context, config *PoolConfig, handler slog.Handler,
|
|||||||
if config.WorkerFactory == nil {
|
if config.WorkerFactory == nil {
|
||||||
config.WorkerFactory = func(
|
config.WorkerFactory = func(
|
||||||
ctx context.Context, id string, handler slog.Handler) (Worker, error) {
|
ctx context.Context, id string, handler slog.Handler) (Worker, error) {
|
||||||
return NewWorker(ctx, id, config.WorkerConfig, handler)
|
wc := config.WorkerConfig
|
||||||
|
return NewWorker(ctx, id, &wc, handler)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user