This commit is contained in:
@@ -6,6 +6,8 @@ import (
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/pkg/constants"
|
||||
)
|
||||
|
||||
// globalConfig 保存当前配置,支持原子访问
|
||||
@@ -27,6 +29,7 @@ type Config struct {
|
||||
Gateway GatewayConfig `mapstructure:"gateway"`
|
||||
PollingAutoTrigger PollingAutoTriggerConfig `mapstructure:"polling_auto_trigger"`
|
||||
Polling PollingConfig `mapstructure:"polling"`
|
||||
Worker WorkerConfig `mapstructure:"worker"`
|
||||
}
|
||||
|
||||
// ServerConfig HTTP 服务器配置
|
||||
@@ -147,6 +150,12 @@ type GatewayConfig struct {
|
||||
Timeout int `mapstructure:"timeout"` // 超时时间(秒)
|
||||
}
|
||||
|
||||
// WorkerConfig Worker 进程运行配置
|
||||
type WorkerConfig struct {
|
||||
Role string `mapstructure:"role"` // Worker 运行角色:all、leader、consumer
|
||||
InstanceName string `mapstructure:"instance_name"` // Worker 实例名称,用于多实例日志区分
|
||||
}
|
||||
|
||||
// PollingConfig 轮询通用配置
|
||||
type PollingConfig struct {
|
||||
// VerboseLog 开启后,所有轮询 handler 在成功获取上游数据时以 Info 级别输出详细日志
|
||||
@@ -320,6 +329,21 @@ func (c *Config) Validate() error {
|
||||
}
|
||||
}
|
||||
|
||||
validWorkerRoles := map[string]bool{
|
||||
constants.WorkerRoleAll: true,
|
||||
constants.WorkerRoleLeader: true,
|
||||
constants.WorkerRoleConsumer: true,
|
||||
}
|
||||
if !validWorkerRoles[c.Worker.Role] {
|
||||
return fmt.Errorf(
|
||||
"invalid configuration: worker.role: invalid worker role (current value: %s, expected: %s, %s, %s)",
|
||||
c.Worker.Role,
|
||||
constants.WorkerRoleAll,
|
||||
constants.WorkerRoleLeader,
|
||||
constants.WorkerRoleConsumer,
|
||||
)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user