Documentation
¶
Overview ¶
本文件定义独立于服务发现的稳定身份与编号权威配置。
本文件定义 Core Manage 控制面的进程级存储配置。
Index ¶
- Constants
- Variables
- func AdminView(con *ServerConfig) (map[string]interface{}, error)
- func BeginServerInitialization()
- func EndServerInitialization()
- func IsServerInitializing() bool
- type AuthRevocationConfig
- type AuthRevocationRedisConfig
- type AuthSecret
- type CasDoorConfig
- type CasDoorConfigData
- type CasDoorServer
- type ClusterClaimConfig
- type ClusterConfig
- type ClusterDiscoveryConfig
- type ClusterInstanceShardConfig
- type ClusterProviderConfig
- type ClusterServiceConfig
- type ClusterShardConfig
- type ClusterShardKeyConfig
- type ConsulProviderConfig
- type EtcdProviderConfig
- type GRPCSecurityConfig
- type GRPCTransportConfig
- type HMACAuthConfig
- type HTTPTransportConfig
- type IDGeneratorConfig
- type KafkaMQConfig
- type MQConfig
- type MQDeadLetterConfig
- type MQRequestReplyConfig
- type MQRetryConfig
- type MQSwitchConfig
- type ManageStoreConfig
- type MelodyConfig
- type MelodyConfigOption
- type NATSJetStreamMQConfig
- type QUICTransportConfig
- type RabbitMQConfig
- type RedisProviderConfig
- type RedisStreamMQConfig
- type RocketMQConfig
- type RouteCacheConfig
- type RouteCacheL1Config
- type RouteCacheL2Config
- type RouteCacheRedisConfig
- type RuntimeObservabilityConfig
- type ServerConfig
- type TransportConfig
Constants ¶
const ( AuthRevocationModeLocal = "local" )
const ( DefaultClusterHeartbeatInterval = 3 * time.Second DefaultClusterHeartbeatTimeout = 10 * time.Second DefaultClusterSuspectTimeout = 15 * time.Second DefaultClusterInstanceReuseCooldown = 30 * time.Second DefaultClusterProviderTTL = 10 * time.Second DefaultClusterEtcdPrefix = "/core/cluster" DefaultClusterConsulPrefix = "digitalway-core" DefaultClusterRedisPrefix = "core:discovery" )
const ( // ManageStoreDriverSQLite 使用 Core 默认的本地 SQLite 控制面库。 ManageStoreDriverSQLite = "sqlite" // ManageStoreDriverMySQL 使用多进程共享的 MySQL 控制面库。 ManageStoreDriverMySQL = "mysql" // ManageStoreDriverPostgres 使用 PostgreSQL 控制面存储。 ManageStoreDriverPostgres = "postgres" )
const ( DefaultRedisStreamCommandPoolSize = 8 DefaultRedisStreamBlockingReadPoolSize = 16 )
const ( DefaultAccessExpireSeconds int64 = 7200 DefaultRefreshExpireSeconds int64 = 2592000 )
const CONFIGDIR = "/etc/"
const GRPCServerNameTargetService = "{service}"
GRPCServerNameTargetService makes the gRPC client verify the server certificate against PayLoad.TargetService for service-discovered calls.
Variables ¶
var CONFIGDIRPATH = utils.Getpath() + CONFIGDIR
var ( // INITSERVER 仅为保持源码兼容而保留。 // Deprecated: 请使用 IsServerInitializing;外部并发直接写入 INITSERVER 不受锁保护。 INITSERVER = false )
Functions ¶
func AdminView ¶
func AdminView(con *ServerConfig) (map[string]interface{}, error)
AdminView returns a JSON-compatible configuration view with credentials and private material removed. The regular QueryConfig response remains the full internal contract used by service-to-service calls.
func BeginServerInitialization ¶
func BeginServerInitialization()
BeginServerInitialization 登记一个进入初始化阶段的服务器实例。
func EndServerInitialization ¶
func EndServerInitialization()
EndServerInitialization 结束一个服务器实例的初始化阶段。
func IsServerInitializing ¶
func IsServerInitializing() bool
IsServerInitializing 返回当前进程是否仍有服务器实例处于初始化阶段。
Types ¶
type AuthRevocationConfig ¶
type AuthRevocationConfig struct {
Mode string
BadgerPath string
Redis AuthRevocationRedisConfig
}
AuthRevocationConfig 配置 Casdoor 身份撤销状态的持久化模式。 local 使用 Badger;shared 使用 Redis 作为权威,Badger 仅保存本地确认快照。
func (*AuthRevocationConfig) ApplyDefaults ¶
func (c *AuthRevocationConfig) ApplyDefaults(service string)
func (AuthRevocationConfig) Validate ¶
func (c AuthRevocationConfig) Validate(casdoorEnabled bool) error
type AuthRevocationRedisConfig ¶
AuthRevocationRedisConfig 配置共享认证撤销状态使用的 Redis 权威存储。
type AuthSecret ¶
type AuthSecret struct {
AccessSecret string
AccessExpire int64
RefreshSecret string
RefreshExpire int64
CasDoor CasDoorConfig
}
type CasDoorConfig ¶
type CasDoorConfig struct {
Enable bool
YamlFilePath string
WebhookSecret string
// contains filtered or unexported fields
}
func (*CasDoorConfig) GetConfigData ¶
func (con *CasDoorConfig) GetConfigData() (*CasDoorConfigData, error)
func (*CasDoorConfig) ReloadConfig ¶
func (con *CasDoorConfig) ReloadConfig() error
type CasDoorConfigData ¶
type CasDoorConfigData struct {
Certificate string `yaml:"certificate"`
Server CasDoorServer `yaml:"server"`
}
type CasDoorServer ¶
type ClusterClaimConfig ¶
type ClusterClaimConfig struct {
AutoMachineID bool `json:",optional"`
AutoDataCenterID bool `json:",optional"`
MachineIDMax uint `json:",optional"`
DataCenterIDMax uint `json:",optional"`
ConflictPolicy string `json:",optional"` // expand-machine-id | expand-data-center-id | fail
}
ClusterClaimConfig 实例身份认领配置。
type ClusterConfig ¶
type ClusterConfig struct {
IdentityMode string `json:",optional"`
InstanceID string `json:",optional"`
IdentityFile string `json:",optional"`
Mode string `json:",optional"` // off | auto | on
Provider string `json:",optional"` // local | etcd | consul
NodeName string `json:",optional"`
AdvertiseAddress string `json:",optional"`
HeartbeatInterval time.Duration `json:",optional"`
HeartbeatTimeout time.Duration `json:",optional"`
SuspectTimeout time.Duration `json:",optional"`
InstanceReuseCooldown time.Duration `json:",optional"`
Claim ClusterClaimConfig `json:",optional"`
Discovery ClusterDiscoveryConfig `json:",optional"`
Shard ClusterShardConfig `json:",optional"`
Services map[string]ClusterServiceConfig `json:",optional"`
Providers ClusterProviderConfig `json:",optional"`
}
ClusterConfig 集群配置。Mode=off 时单机运行,Mode=auto 时自动检测,Mode=on 时强制进入集群流程。
func (*ClusterConfig) ApplyDefaults ¶
func (c *ClusterConfig) ApplyDefaults()
ApplyDefaults 为 ClusterConfig 补充缺失的默认值。
func (*ClusterConfig) Validate ¶
func (c *ClusterConfig) Validate() error
Validate 校验 ClusterConfig 中的字段合法性。
type ClusterDiscoveryConfig ¶
type ClusterDiscoveryConfig struct {
Seeds []string `json:",optional"`
Multicast bool `json:",optional"`
MDNS bool `json:",optional"`
}
ClusterDiscoveryConfig 服务发现配置。
type ClusterInstanceShardConfig ¶
type ClusterInstanceShardConfig struct {
MachineID uint `json:",optional"`
Shards map[string][]string `json:",optional"`
}
ClusterInstanceShardConfig 单个实例的分片标记。
type ClusterProviderConfig ¶
type ClusterProviderConfig struct {
Etcd EtcdProviderConfig `json:",optional"`
Consul ConsulProviderConfig `json:",optional"`
Redis RedisProviderConfig `json:",optional"`
}
ClusterProviderConfig 外部 provider 连接参数。
type ClusterServiceConfig ¶
type ClusterServiceConfig struct {
ShardKeys map[string]ClusterShardKeyConfig `json:",optional"`
Instances []ClusterInstanceShardConfig `json:",optional"`
}
ClusterServiceConfig 单个服务的分片配置。
type ClusterShardConfig ¶
type ClusterShardConfig struct {
MissingKeyPolicy string `json:",optional"` // error | average
EmptyCandidatePolicy string `json:",optional"` // error | average | readonly-fallback
KeyPriority []string `json:",optional"`
}
ClusterShardConfig 服务分片全局策略配置。
type ClusterShardKeyConfig ¶
type ClusterShardKeyConfig struct {
Mode string `json:",optional"` // exact | group | hash | optional
Required bool `json:",optional"`
}
ClusterShardKeyConfig 单个 shard key 的规则。
type ConsulProviderConfig ¶
type ConsulProviderConfig struct {
Address string `json:",optional"`
Prefix string `json:",optional"`
TTL time.Duration `json:",optional"`
}
ConsulProviderConfig Consul 连接配置。
type EtcdProviderConfig ¶
type EtcdProviderConfig struct {
Endpoints []string `json:",optional"`
Prefix string `json:",optional"`
TTL time.Duration `json:",optional"`
}
EtcdProviderConfig etcd 连接配置。
type GRPCSecurityConfig ¶
type GRPCSecurityConfig struct {
Mode string `json:",optional"` // insecure | tls | mtls | mesh
CAFile string `json:",optional"`
CertFile string `json:",optional"`
KeyFile string `json:",optional"`
ServerName string `json:",optional"`
}
GRPCSecurityConfig gRPC 传输安全配置。
type GRPCTransportConfig ¶
type GRPCTransportConfig struct {
Port int `json:",optional"`
MaxRecvMsgSize int `json:",optional"`
MaxSendMsgSize int `json:",optional"`
Security GRPCSecurityConfig `json:",optional"`
}
GRPCTransportConfig gRPC 传输配置。
type HMACAuthConfig ¶
type HMACAuthConfig struct {
AccessKeyHeader string `json:",default=X-Access-Key"`
TimestampHeader string `json:",default=X-Timestamp"`
NonceHeader string `json:",default=X-Nonce"`
SignatureHeader string `json:",default=X-Signature"`
RecvWindowHeader string `json:",default=X-Recv-Window"`
MaxInFlight int `json:",default=64"`
}
HMACAuthConfig 配置 Auth 用户域 REST 凭证头和未认证 Hook 的进程内并发上限。 是否启用由服务是否实现 IHMACAuthProvider 决定;Manage 与 ServerManage 不读取本配置。
func (*HMACAuthConfig) ApplyDefaults ¶
func (c *HMACAuthConfig) ApplyDefaults()
ApplyDefaults 补充中性 HMAC Header 名和安全的进程内并发上限。
func (HMACAuthConfig) Validate ¶
func (c HMACAuthConfig) Validate() error
Validate 拒绝非法、重复 Header 名和无效并发上限。
type HTTPTransportConfig ¶
type HTTPTransportConfig struct {
Enable bool `json:",optional"`
}
HTTPTransportConfig HTTP 传输配置。
type IDGeneratorConfig ¶ added in v1.4.0
type IDGeneratorConfig struct {
LocalPath string `json:",optional"`
Provider string `json:",optional"`
Namespace string `json:",optional"`
Epoch string `json:",optional"`
Providers ClusterProviderConfig `json:",optional"`
LocalDevelopment bool `json:",optional"`
ReservationWindow time.Duration `json:",optional"`
StartupTimeout time.Duration `json:",optional"`
}
IDGeneratorConfig 显式配置编号权威,不能继承服务发现的自动降级。
func (*IDGeneratorConfig) ApplyDefaults ¶ added in v1.4.0
func (g *IDGeneratorConfig) ApplyDefaults()
ApplyDefaults 只补编号时间预算,不导入发现 Provider 的 TTL 或降级配置。
func (*IDGeneratorConfig) Validate ¶ added in v1.4.0
func (g *IDGeneratorConfig) Validate() error
Validate 校验独立编号配置,也供离线工具和构造器直接调用。
type KafkaMQConfig ¶
KafkaMQConfig Kafka 连接配置。
type MQConfig ¶
type MQConfig struct {
Mode string `json:",optional"` // off | auto | on
Provider string `json:",optional"` // redis-stream | nats-jetstream | kafka | rabbitmq | rocketmq
Usage []string `json:",optional"` // event-stream | transport | websocket | delayed-task
RequestReply MQRequestReplyConfig `json:",optional"`
Retry MQRetryConfig `json:",optional"`
DeadLetter MQDeadLetterConfig `json:",optional"`
Switch MQSwitchConfig `json:",optional"`
RedisStream RedisStreamMQConfig `json:",optional"`
NATSJetStream NATSJetStreamMQConfig `json:",optional"`
Kafka KafkaMQConfig `json:",optional"`
RabbitMQ RabbitMQConfig `json:",optional"`
RocketMQ RocketMQConfig `json:",optional"`
}
MQConfig 消息队列配置。默认 Mode=off 不初始化,显式 Mode=auto 自动检测,Mode=on 强制启用。
func (*MQConfig) ApplyDefaults ¶
func (m *MQConfig) ApplyDefaults()
ApplyDefaults 为 MQConfig 补充缺失的默认值。
type MQDeadLetterConfig ¶
MQDeadLetterConfig 死信队列配置。
type MQRequestReplyConfig ¶
type MQRequestReplyConfig struct {
Enable bool `json:",optional"`
Timeout time.Duration `json:",optional"`
}
MQRequestReplyConfig MQ 同步 request/reply 配置。
type MQRetryConfig ¶
type MQRetryConfig struct {
Enable bool `json:",optional"`
RetryCount int `json:",optional"`
InitialDelay time.Duration `json:",optional"`
MaxDelay time.Duration `json:",optional"`
}
MQRetryConfig MQ 消息重试配置。
type MQSwitchConfig ¶
type MQSwitchConfig struct {
AllowDynamicSwitch bool `json:",optional"`
Strategy string `json:",optional"` // drain | dual-write | maintenance
TargetProvider string `json:",optional"`
DualWriteDuration time.Duration `json:",optional"`
// RollbackOnFailure 开启动态切换时默认 true。使用指针以区分"未设置"和"显式 false"。
RollbackOnFailure *bool `json:",optional"`
}
MQSwitchConfig MQ 动态切换配置。
type ManageStoreConfig ¶ added in v1.3.0
type ManageStoreConfig struct {
Driver string
Database string
Host string
Port int
Username string
Password string
MaxIdleConns int
MaxOpenConns int
SSLMode string
SSLRootCert string
SSLCert string
SSLKey string
TimeZone string
}
ManageStoreConfig 配置目录、菜单、按钮、角色、权限、管理员主体和主体角色关系的唯一存储。 该配置只能出现在内置 server 服务的 server.json 中。
func DefaultManageStoreConfig ¶ added in v1.3.0
func DefaultManageStoreConfig() *ManageStoreConfig
DefaultManageStoreConfig 返回新安装使用的 SQLite 默认配置。
func (*ManageStoreConfig) ApplyDefaults ¶ added in v1.3.0
func (c *ManageStoreConfig) ApplyDefaults()
ApplyDefaults 补齐不改变存储选择的连接默认值。
func (ManageStoreConfig) StorageConfig ¶ added in v1.7.0
func (c ManageStoreConfig) StorageConfig() types.StorageConfig
StorageConfig 转换为通用存储配置,控制面不维护驱动选择分支。
func (ManageStoreConfig) Validate ¶ added in v1.3.0
func (c ManageStoreConfig) Validate() error
Validate 拒绝未支持驱动、不完整 MySQL 配置和无效连接池。
type MelodyConfig ¶
type MelodyConfig struct {
WriteWait time.Duration // Duration until write times out.
PongWait time.Duration // Timeout for waiting on pong.
PingPeriod time.Duration // Duration between pings.
ReadTimeout time.Duration `json:"read_timeout"` // 新增
MaxMessageSize int64 // Maximum size in bytes of a message.
MessageBufferSize int // The max amount of messages that can be in a sessions buffer before it starts dropping them.
ConcurrentMessageHandling bool // Handle messages from sessions concurrently.
MaxConnections int64 // 最大连接数
}
func GetMelodyConfig ¶
func GetMelodyConfig() *MelodyConfig
func NewMelodyConfig ¶
func NewMelodyConfig() *MelodyConfig
type MelodyConfigOption ¶
type MelodyConfigOption func(con *MelodyConfig)
type NATSJetStreamMQConfig ¶
type NATSJetStreamMQConfig struct {
URL string `json:",optional"`
StreamPrefix string `json:",optional"`
DurablePrefix string `json:",optional"`
}
NATSJetStreamMQConfig NATS JetStream 连接配置。
type QUICTransportConfig ¶
type QUICTransportConfig struct {
Enable bool `json:",optional"`
CertFile string `json:",optional"`
KeyFile string `json:",optional"`
}
QUICTransportConfig QUIC 传输配置。
type RabbitMQConfig ¶
RabbitMQConfig RabbitMQ 连接配置。
type RedisProviderConfig ¶
type RedisProviderConfig struct {
Addr string `json:",optional"`
DB int `json:",optional"`
Prefix string `json:",optional"`
TTL time.Duration `json:",optional"`
}
RedisProviderConfig 配置使用 Redis 键租约和 Stream 事件的服务发现 Provider。
type RedisStreamMQConfig ¶
type RedisStreamMQConfig struct {
Addr string `json:",optional"`
DB int `json:",optional"`
Prefix string `json:",optional"`
CommandPoolSize int `json:",optional"`
BlockingReadPoolSize int `json:",optional"`
}
RedisStreamMQConfig Redis Streams 连接配置。
func (RedisStreamMQConfig) Validate ¶ added in v1.4.5
func (r RedisStreamMQConfig) Validate() error
Validate 校验显式池预算;零值由构造器默认化,拒绝客户端不能表达的范围。
type RocketMQConfig ¶
type RocketMQConfig struct {
NameServers []string `json:",optional"`
Group string `json:",optional"`
}
RocketMQConfig RocketMQ 连接配置。
type RouteCacheConfig ¶
type RouteCacheConfig struct {
Mode string `json:",optional"` // local | shared; 旧 off 会兼容为 local
TTL time.Duration `json:",optional"`
L1 RouteCacheL1Config `json:",optional"`
L2 RouteCacheL2Config `json:",optional"`
Redis RouteCacheRedisConfig `json:",optional"`
}
func (*RouteCacheConfig) ApplyDefaults ¶
func (c *RouteCacheConfig) ApplyDefaults()
func (*RouteCacheConfig) Validate ¶
func (c *RouteCacheConfig) Validate() error
type RouteCacheL1Config ¶
type RouteCacheL2Config ¶
type RouteCacheRedisConfig ¶
type RuntimeObservabilityConfig ¶
type RuntimeObservabilityConfig struct {
// Mode: off | prometheus。默认值由 ApplyDefaults 写入,避免 go-zero conf 嵌套 default 干扰迁移加载。
Mode string `json:",optional"`
QueryURL string `json:",optional"`
QueryTimeout time.Duration `json:",optional"`
MaxConcurrentQueries int `json:",optional"`
CacheTTL time.Duration `json:",optional"`
}
RuntimeObservabilityConfig 控制 ServerManage 侧 Runtime Aggregator 的指标查询。 业务实例只需暴露 Prometheus scrape;QueryURL 仅查询端需要。
func (*RuntimeObservabilityConfig) ApplyDefaults ¶
func (c *RuntimeObservabilityConfig) ApplyDefaults()
ApplyDefaults 补充 RuntimeObservability 默认值,并规范化 Mode。
func (RuntimeObservabilityConfig) RedactedQueryURLHost ¶
func (c RuntimeObservabilityConfig) RedactedQueryURLHost() string
RedactedQueryURLHost 返回仅 host 的安全摘要(日志用,不含 userinfo/path)。
func (RuntimeObservabilityConfig) Validate ¶
func (c RuntimeObservabilityConfig) Validate() error
Validate 校验 RuntimeObservability 合法性。 注意:go-zero conf.MustLoad 会在 ApplyDefaults 之前调用 Validate, 因此空 Mode / 零超时视为“尚未补默认值”,按 off 语义放行。
type ServerConfig ¶
type ServerConfig struct {
IDGenerator *IDGeneratorConfig `json:",optional,omitempty"`
rest.RestConf
DataCenterID uint
MachineID uint
Auth AuthSecret
ManageAuth AuthSecret
ServerManageAuth AuthSecret
IsWhiteList bool
WhiteList []string
TrustedProxies []string
HMACAuth HMACAuthConfig `json:",optional"`
IsLoaclVisit bool
RemoteAccessManageAPI bool
MelodyConfigPath string `json:",optional"`
Cluster ClusterConfig `json:",optional"`
Transport TransportConfig `json:",optional"`
MQ MQConfig `json:",optional"`
RouteCache RouteCacheConfig `json:",optional"`
AuthRevocation AuthRevocationConfig `json:",optional"`
RuntimeObservability RuntimeObservabilityConfig `json:",optional"`
ManageStore *ManageStoreConfig `json:",optional,omitempty"`
}
func MergeProtectedFields ¶
func MergeProtectedFields(existing, incoming *ServerConfig) (*ServerConfig, error)
MergeProtectedFields keeps credentials from the current runtime config. Configuration editing intentionally cannot rotate authentication material.
func NewServiceDefaultConfig ¶
func NewServiceDefaultConfig(servicename string, port int) *ServerConfig
func ReadConfig ¶
func ReadConfig(servicename string) *ServerConfig
func (*ServerConfig) ApplyDefaults ¶
func (con *ServerConfig) ApplyDefaults()
ApplyDefaults 为 ServerConfig 及其子配置补充缺失的默认值。 ReadConfig、NewServiceDefaultConfig、Save 均必须调用此方法。
func (*ServerConfig) ReloadExternalConfigs ¶
func (con *ServerConfig) ReloadExternalConfigs()
ReloadExternalConfigs 加载外部配置文件(Casdoor、Melody)。
func (*ServerConfig) Save ¶
func (own *ServerConfig) Save() error
func (*ServerConfig) Validate ¶
func (con *ServerConfig) Validate() error
Validate 校验 ServerConfig 中各子配置的合法性。
type TransportConfig ¶
type TransportConfig struct {
Internal string `json:",optional"` // grpc | http | quic | mq
Fallback []string `json:",optional"`
MaxRetries int `json:",optional"` // 网络错误重试次数,0=不重试
RetryDelay time.Duration `json:",optional"` // 重试基础延迟,默认 100ms
HTTP HTTPTransportConfig `json:",optional"`
QUIC QUICTransportConfig `json:",optional"`
GRPC GRPCTransportConfig `json:",optional"`
}
TransportConfig 内部传输配置。Internal 指定首选协议,Fallback 为降级顺序。
func (*TransportConfig) ApplyDefaults ¶
func (t *TransportConfig) ApplyDefaults()
ApplyDefaults 为 TransportConfig 补充缺失的默认值。
func (*TransportConfig) ApplyServerDefaults ¶
func (t *TransportConfig) ApplyServerDefaults(cluster ClusterConfig, httpPort int)
ApplyServerDefaults 根据服务端口和集群拓扑补充 gRPC 默认值。
func (*TransportConfig) Validate ¶
func (t *TransportConfig) Validate() error
Validate 校验 TransportConfig 中的字段合法性。
func (*TransportConfig) ValidateForServer ¶
func (t *TransportConfig) ValidateForServer(cluster ClusterConfig, runIP string) error
ValidateForServer 校验需要服务端集群上下文的 gRPC 约束。