RRuna

配置参考

按能力分节的配置键

Runa 默认从 config/*.toml 读取配置。文件名会作为配置域,例如 config/cache.toml 会写入 cache 域,config/cache.production.toml 只在 production 环境加载。

本页是速查表,只列常见键。更完整的解释和示例看对应能力页。

覆盖顺序

配置合并顺序:

  1. 默认值
  2. 基础配置文件
  3. 当前环境配置文件
  4. 环境变量
  5. 代码 Set 或 Provider 选项

基础规则

  • 文件名决定配置域,比如 cache.toml 对应 runa.Config("cache")
  • 环境文件用 名称.环境.toml,比如 cache.production.toml
  • duration 字段可以写 10s5m1h
  • 密钥、密码、token 不建议提交到 Git,生产环境优先用环境变量或密钥系统

App

# config/app.toml
timezone = "Asia/Shanghai"

键:timezone

Cache

[cache.pools.default]
driver = "memory"
prefix = "app:"
ttl = "10m"

键:driverprefixttlmeta

Redis

完整配置路径:

[redis.default]
addr = "127.0.0.1:6379"
username = ""
password = ""
db = 0
pool_size = 10
min_idle = 1

写在 config/redis.toml 里:

addr = "127.0.0.1:6379"
username = ""
password = ""
db = 0
pool_size = 10
min_idle = 1

[cache]
addr = "127.0.0.1:6379"
db = 1

键:addrusernamepassworddbloggerdial_timeoutread_timeoutwrite_timeoutpool_sizemin_idle

按完整路径表示时是 redis.<name>;写在 config/redis.toml 里时,根键表示 default 运行时,[name] 表表示命名运行时。

Redis 驱动子包也会读取功能配置段,例如 [cache.redis][lock.redis][rate.redis][queue.redis][message.redis][cluster.redis][ws.redis]。功能段不存在时,会回退到 [redis] 或由 Use(name) 选择的 [redis.<name>]

共享 [redis] / [redis.<name>] 段只表示连接参数。prefixttl、websocket 的 channelpresence_prefix 等能力专属配置应写在功能段或 driver option。

AMQP / NATS / MQTT

[amqp]
url = "amqp://guest:guest@127.0.0.1:5672/"

[nats]
url = "nats://127.0.0.1:4222"

[mqtt]
broker = "tcp://127.0.0.1:1883"
client_id = "runa"

消息和队列驱动子包会先读取功能段,例如 [message.amqp][queue.amqp][message.nats][message.mqtt],再回退到共享 [amqp][nats][mqtt]

Queue

[queue.queues.default]
driver = "memory"
workers = ["default"]
retry = 3
retry_delay = "5s"
timeout = "30s"
retention = "24h"

[queue.workers.default]
concurrency = 4
poll_interval = "100ms"
lease = "30s"
stop_timeout = "30s"

Session

[session.sessions.web]
driver = "memory"
cookie_name = "sid"
cookie_domain = ""
cookie_path = "/"
ttl = "24h"
idle_timeout = "30m"
shared = false

Storage

[storage.disks.public]
driver = "local"
prefix = "public"
public = true
url_prefix = "/files"
domain = "https://cdn.example.com"

Lock

[lock.lockers.default]
driver = "memory"
prefix = "lock:"
ttl = "30s"
wait = "5s"
retry_interval = "100ms"
auto_renew = true

Rate

[rate.limiters.api]
driver = "memory"
algorithm = "token_bucket"
limit = 60
window = "1m"
burst = 10
key = ["ip", "route"]

Message

[message.brokers.default]
driver = "memory"

Audit

[audit]
methods = ["POST", "PUT", "PATCH", "DELETE"]
mode = "async"
strict = false
capture_input = true
mask_fields = ["password", "token", "secret"]
mask_value = "***"
max_input_size = 16384
buffer = 100
write_timeout = "3s"

Observe

[observe]
service = "api"
env = "production"
version = "1.0.0"
timeout = "2s"
mount = "/-"
debug = false

Cluster

[cluster]
driver = "memory"
id = "api-1"
service = "api"
env = "production"
version = "1.0.0"
addr = "http://127.0.0.1:8080"
heartbeat_interval = "5s"
ttl = "15s"

Console

[console]
title = "Runa Console"
mount = "/_console"
auth = ["web"]
interval = "5s"
slow_threshold = "300ms"
collect_http = true
sample_interval = "1s"

JSON-RPC

[jsonrpc]
path = "/rpc"
ws_path = "/rpc/ws"

Devtools

[devtools]
embed_root = "views"
embed_patterns = ["**/*.html"]
embed_package = "embed"
embed_name = "ViewFS"
embed_out = "internal/embed/view.go"
编辑此页