Add support for database read replicas using the GORM dbresolver plugin. This allows for scaling read operations by distributing them across one or multiple replica nodes. - Update `DatabaseConfig` to support single and multiple replica configurations. - Add configuration options for replica connection pooling and selection policy. - Integrate `dbresolver` in the database initialization process for PostgreSQL. - Add helper methods to aggregate replica configurations.
315 lines
9.0 KiB
YAML
315 lines
9.0 KiB
YAML
# 服务器配置
|
||
# 环境变量: APP_SERVER_HOST, APP_SERVER_PORT, APP_SERVER_MODE
|
||
server:
|
||
host: 0.0.0.0
|
||
port: 8080
|
||
mode: debug
|
||
|
||
# 数据库配置
|
||
# 环境变量:
|
||
# SQLite: APP_DATABASE_SQLITE_PATH
|
||
# Postgres: APP_DATABASE_POSTGRES_HOST, APP_DATABASE_POSTGRES_PORT, APP_DATABASE_POSTGRES_USER,
|
||
# APP_DATABASE_POSTGRES_PASSWORD, APP_DATABASE_POSTGRES_DBNAME
|
||
database:
|
||
type: sqlite # sqlite 或 postgres
|
||
sqlite:
|
||
path: ./data/with_you.db
|
||
postgres:
|
||
host: localhost
|
||
port: 5432
|
||
user: postgres
|
||
password: postgres
|
||
dbname: with_you
|
||
sslmode: disable
|
||
# 读写分离配置(仅 postgres 模式生效,不配置则所有请求走主库)
|
||
# 单副本配置(支持环境变量):
|
||
# APP_DATABASE_REPLICA_HOST, APP_DATABASE_REPLICA_PORT, APP_DATABASE_REPLICA_USER,
|
||
# APP_DATABASE_REPLICA_PASSWORD, APP_DATABASE_REPLICA_DBNAME, APP_DATABASE_REPLICA_SSLMODE
|
||
# replica:
|
||
# host: replica1.internal
|
||
# port: 5432
|
||
# user: readonly
|
||
# password: readonly_pass
|
||
# dbname: with_you
|
||
# sslmode: disable
|
||
# 多副本配置(仅 YAML,环境变量不支持切片结构体):
|
||
# replicas:
|
||
# - host: replica1.internal
|
||
# port: 5432
|
||
# user: readonly
|
||
# password: readonly_pass
|
||
# dbname: with_you
|
||
# sslmode: disable
|
||
# replica_policy: random # random
|
||
# replica_max_idle_conns: 10
|
||
# replica_max_open_conns: 100
|
||
max_idle_conns: 10
|
||
max_open_conns: 100
|
||
log_level: warn
|
||
slow_threshold_ms: 200
|
||
ignore_record_not_found: true
|
||
parameterized_queries: true
|
||
|
||
# Redis配置
|
||
# 环境变量:
|
||
# 类型: APP_REDIS_TYPE (miniredis/redis)
|
||
# Redis: APP_REDIS_REDIS_HOST, APP_REDIS_REDIS_PORT, APP_REDIS_REDIS_PASSWORD, APP_REDIS_REDIS_DB
|
||
# Miniredis: APP_REDIS_MINIREDIS_HOST, APP_REDIS_MINIREDIS_PORT
|
||
redis:
|
||
type: miniredis # miniredis 或 redis
|
||
redis:
|
||
host: 1Panel-redis-dfmM
|
||
port: 6379
|
||
password: "redis_j8CMza"
|
||
db: 0
|
||
miniredis:
|
||
host: localhost
|
||
port: 6379
|
||
pool_size: 10
|
||
|
||
# 缓存配置
|
||
# 环境变量:
|
||
# APP_CACHE_ENABLED, APP_CACHE_KEY_PREFIX, APP_CACHE_DEFAULT_TTL, APP_CACHE_NULL_TTL
|
||
# APP_CACHE_JITTER_RATIO, APP_CACHE_DISABLE_FLUSHDB
|
||
# APP_CACHE_MODULES_POST_LIST_TTL, APP_CACHE_MODULES_CONVERSATION_TTL
|
||
# APP_CACHE_MODULES_UNREAD_COUNT_TTL, APP_CACHE_MODULES_GROUP_MEMBERS_TTL
|
||
cache:
|
||
enabled: true
|
||
key_prefix: ""
|
||
default_ttl: 30
|
||
null_ttl: 5
|
||
jitter_ratio: 0.1
|
||
disable_flushdb: true
|
||
modules:
|
||
post_list_ttl: 30
|
||
conversation_ttl: 60
|
||
unread_count_ttl: 30
|
||
group_members_ttl: 120
|
||
|
||
# 热门榜:定时在「候选池」上重算,只写入 Redis ZSET(TopN)+ top_ids(供本地缓存);不写数据库
|
||
hot_rank:
|
||
enabled: true
|
||
refresh_interval_seconds: 300
|
||
top_n: 100
|
||
recent_window_hours: 168 # 7 天内新帖进入候选
|
||
recent_fetch_limit: 500
|
||
candidate_cap: 800 # 上届 Top + 新帖 ID 合并后上限
|
||
|
||
# S3对象存储配置
|
||
# 环境变量: APP_S3_ENDPOINT, APP_S3_ACCESS_KEY, APP_S3_SECRET_KEY, APP_S3_BUCKET, APP_S3_DOMAIN
|
||
s3:
|
||
endpoint: "files.littlelan.cn"
|
||
access_key: "E6bMcYkQzCldRTrtmhvi"
|
||
secret_key: "4R9yjmwKNoHphiBkv05Oa8WGEIFbnlZeTLXfSgx3"
|
||
bucket: "test"
|
||
use_ssl: true
|
||
region: us-east-1
|
||
domain: "files.littlelan.cn"
|
||
# JWT配置
|
||
# 环境变量: APP_JWT_SECRET
|
||
jwt:
|
||
secret: your-jwt-secret-key-change-in-production
|
||
access_token_expire: 86400 # 24 hours in seconds
|
||
refresh_token_expire: 604800 # 7 days in seconds
|
||
|
||
log:
|
||
level: info
|
||
encoding: json
|
||
output_paths:
|
||
- stdout
|
||
- ./logs/app.log
|
||
retention:
|
||
access_log: 180 # HTTP访问日志 6个月
|
||
operation_log: 365 # 操作日志 1年
|
||
login_log: 1095 # 登录日志 3年
|
||
data_change: 1095 # 数据变更日志 3年
|
||
async:
|
||
buffer_size: 10000
|
||
batch_size: 100
|
||
flush_interval: 3s
|
||
worker_count: 3
|
||
enable_fallback: true
|
||
fallback_path: ./logs/fallback.log
|
||
sensitive:
|
||
enabled: true
|
||
mask_fields:
|
||
- password
|
||
- token
|
||
- secret
|
||
- phone
|
||
- id_card
|
||
- bank_card
|
||
rotation:
|
||
max_size: 100
|
||
max_age: 180
|
||
max_backups: 10
|
||
compress: true
|
||
|
||
rate_limit:
|
||
enabled: true
|
||
requests_per_minute: 60
|
||
|
||
upload:
|
||
max_file_size: 10485760 # 10MB
|
||
allowed_types:
|
||
- image/jpeg
|
||
- image/png
|
||
- image/gif
|
||
- image/webp
|
||
|
||
# 敏感词过滤配置
|
||
sensitive:
|
||
enabled: true
|
||
replace_str: "***"
|
||
min_match_len: 1
|
||
load_from_db: true
|
||
load_from_redis: false
|
||
redis_key_prefix: "sensitive_words"
|
||
|
||
# 内容审核服务配置
|
||
audit:
|
||
enabled: false # 暂时关闭第三方审核
|
||
# 审核服务提供商: local, aliyun, tencent, baidu
|
||
provider: "local"
|
||
auto_audit: true
|
||
timeout: 30
|
||
# 阿里云配置
|
||
aliyun_access_key: ""
|
||
aliyun_secret_key: ""
|
||
aliyun_region: "cn-shanghai"
|
||
# 腾讯云配置
|
||
tencent_secret_id: ""
|
||
tencent_secret_key: ""
|
||
# 百度云配置
|
||
baidu_api_key: ""
|
||
baidu_secret_key: ""
|
||
|
||
# OpenAI兼容接口配置(用于帖子审核,支持图文)
|
||
# 环境变量:
|
||
# APP_OPENAI_ENABLED, APP_OPENAI_BASE_URL, APP_OPENAI_API_KEY
|
||
# APP_OPENAI_MODERATION_MODEL, APP_OPENAI_MODERATION_MAX_IMAGES_PER_REQUEST
|
||
# APP_OPENAI_REQUEST_TIMEOUT, APP_OPENAI_STRICT_MODERATION
|
||
openai:
|
||
enabled: true
|
||
base_url: "https://api.littlelan.cn/"
|
||
api_key: "sk-y7LOeKsNfzbZWTRSFsTs79jd8WYlezbIVgdVPgMvG4Xz2AlV"
|
||
moderation_model: "qwen3.5-122b"
|
||
moderation_max_images_per_request: 1
|
||
request_timeout: 30
|
||
strict_moderation: false
|
||
|
||
# 腾讯云文本内容安全配置(作为 OpenAI 备用)
|
||
# 当 OpenAI 不可用或审核失败时,使用腾讯TMS进行文本审核
|
||
# 环境变量:
|
||
# APP_TENCENT_TMS_ENABLED, APP_TENCENT_TMS_SECRET_ID, APP_TENCENT_TMS_SECRET_KEY
|
||
# APP_TENCENT_TMS_REGION, APP_TENCENT_TMS_BIZ_TYPE, APP_TENCENT_TMS_TIMEOUT
|
||
tencent_tms:
|
||
enabled: false
|
||
secret_id: ""
|
||
secret_key: ""
|
||
region: "ap-guangzhou"
|
||
biz_type: "" # 可选,使用控制台配置的自定义策略
|
||
timeout: 30
|
||
|
||
# SMTP发信配置(gomail.v2)
|
||
# 环境变量:
|
||
# APP_EMAIL_ENABLED, APP_EMAIL_HOST, APP_EMAIL_PORT
|
||
# APP_EMAIL_USERNAME, APP_EMAIL_PASSWORD
|
||
# APP_EMAIL_FROM_ADDRESS, APP_EMAIL_FROM_NAME
|
||
# APP_EMAIL_USE_TLS, APP_EMAIL_INSECURE_SKIP_VERIFY, APP_EMAIL_TIMEOUT
|
||
email:
|
||
enabled: true
|
||
host: "smtp.exmail.qq.com"
|
||
port: 465
|
||
username: "no-reply@qczlit.cn"
|
||
password: "HbvwwVjRyiWg9gsK"
|
||
from_address: "no-reply@qczlit.cn"
|
||
from_name: "WithYou"
|
||
use_tls: true
|
||
insecure_skip_verify: false
|
||
timeout: 15
|
||
|
||
# 会话缓存配置
|
||
conversation_cache:
|
||
# TTL 配置
|
||
detail_ttl: 5m # 会话详情缓存时间
|
||
list_ttl: 60s # 会话列表缓存时间
|
||
participant_ttl: 5m # 参与者缓存时间
|
||
unread_ttl: 30s # 未读数缓存时间
|
||
|
||
# 消息缓存配置
|
||
message_detail_ttl: 30m # 单条消息详情缓存
|
||
message_list_ttl: 5m # 消息分页列表缓存
|
||
message_index_ttl: 30m # 消息索引缓存
|
||
message_count_ttl: 30m # 消息计数缓存
|
||
|
||
# 批量写入配置
|
||
batch_interval: 5s # 写入间隔
|
||
batch_threshold: 100 # 条数阈值
|
||
batch_max_size: 500 # 单次最大批量
|
||
buffer_max_size: 10000 # 写缓冲最大条数
|
||
|
||
# gRPC 服务器配置
|
||
# 环境变量:
|
||
# APP_GRPC_ENABLED, APP_GRPC_PORT
|
||
# APP_GRPC_TLS_ENABLED, APP_GRPC_TLS_CERT_FILE, APP_GRPC_TLS_KEY_FILE
|
||
grpc:
|
||
enabled: true
|
||
port: 50051
|
||
tls_enabled: false
|
||
tls_cert_file: ""
|
||
tls_key_file: ""
|
||
|
||
# Casbin RBAC权限系统配置
|
||
# 环境变量:
|
||
# APP_CASBIN_MODEL_PATH, APP_CASBIN_AUTO_SAVE, APP_CASBIN_AUTO_LOAD
|
||
# APP_CASBIN_ENABLE_CACHE, APP_CASBIN_CACHE_TTL
|
||
casbin:
|
||
model_path: "./configs/casbin/model.conf"
|
||
auto_save: true
|
||
auto_load: true
|
||
enable_cache: true
|
||
cache_ttl: 300
|
||
skip_routes:
|
||
- /health
|
||
- /api/v1/auth/login
|
||
- /api/v1/auth/register
|
||
- /api/v1/auth/check-username
|
||
- /api/v1/auth/password/send-code
|
||
- /api/v1/auth/password/reset
|
||
- /api/v1/auth/refresh
|
||
- /api/v1/admin/setup-super-admin
|
||
|
||
# 举报配置
|
||
# 环境变量: APP_REPORT_AUTO_HIDE_THRESHOLD
|
||
report:
|
||
auto_hide_threshold: 3 # 自动隐藏阈值,举报次数达到此数值时自动隐藏内容
|
||
|
||
# 极光推送配置
|
||
# 环境变量:
|
||
# APP_JPUSH_ENABLED, APP_JPUSH_APP_KEY, APP_JPUSH_MASTER_SECRET, APP_JPUSH_PRODUCTION
|
||
jpush:
|
||
enabled: false
|
||
app_key: ""
|
||
master_secret: ""
|
||
production: false # true: 生产环境, false: 开发环境
|
||
|
||
# 初始化超级管理员密钥
|
||
# 环境变量: APP_SETUP_SECRET
|
||
# 设置后可使用 POST /api/v1/admin/setup-super-admin 接口初始化第一位超级管理员
|
||
# 该接口只能使用一次,一旦系统中存在超级管理员,此接口将永久拒绝请求
|
||
setup_secret: ""
|
||
|
||
# WebSocket 配置
|
||
# 环境变量:
|
||
# APP_WEBSOCKET_MODE, APP_WEBSOCKET_CLUSTER_INSTANCE_ID
|
||
# APP_WEBSOCKET_CLUSTER_MSG_CHANNEL, APP_WEBSOCKET_CLUSTER_ONLINE_TTL
|
||
# APP_WEBSOCKET_CLUSTER_HEARTBEAT_INTERVAL
|
||
websocket:
|
||
mode: standalone # standalone 或 cluster
|
||
cluster:
|
||
instance_id: "" # 留空自动生成 UUID
|
||
msg_channel: "ws:msg" # Redis Pub/Sub 频道
|
||
online_ttl: 60 # 在线状态 TTL(秒)
|
||
heartbeat_interval: 20 # 心跳间隔(秒)
|