配置(Settings)¶
声明插件自己的配置项,内核会把它渲染到 WebUI 的设置页,并为每个插件维护独立的配置表。
SettingsAPI¶
| 方法 | 说明 |
|---|---|
DataDir |
DataDir returns the plugin-specific data directory (guaranteed to exist): |
Defs |
Defs returns config definitions matching the prefix. |
Dump |
Dump returns all config values. |
Get |
Get reads the plugin's own config value (config_ |
GetCore |
GetCore reads the core config table. |
GetPlugin |
GetPlugin reads another plugin's config table. |
GetSecret |
GetSecret reads a value written by SetSecret (transparently decrypted). |
List |
List returns all keys matching the given prefix. |
ListCore |
ListCore lists core config keys matching the prefix. |
ListPlugin |
ListPlugin lists another plugin's config keys matching the prefix. |
Plugins |
Plugins returns a list of all plugin config namespaces. |
RegisterDef |
RegisterDef registers a config definition for UI display. |
Set |
Set writes a config value to the plugin's own config table. |
SetCore |
SetCore writes to the core config table. |
SetPlugin |
SetPlugin writes to another plugin's config table. |
SetSecret |
SetSecret writes a value that is ALWAYS encrypted at rest, regardless of |
SettingsAPI.DataDir¶
DataDir returns the plugin-specific data directory (guaranteed to exist):
settings.go:40
SettingsAPI.Defs¶
Defs returns config definitions matching the prefix.
settings.go:55
SettingsAPI.Dump¶
Dump returns all config values.
settings.go:58
SettingsAPI.Get¶
Get reads the plugin's own config value (config_
settings.go:5
SettingsAPI.GetCore¶
GetCore reads the core config table.
settings.go:29
SettingsAPI.GetPlugin¶
GetPlugin reads another plugin's config table.
settings.go:43
SettingsAPI.GetSecret¶
GetSecret reads a value written by SetSecret (transparently decrypted).
settings.go:23
SettingsAPI.List¶
List returns all keys matching the given prefix.
settings.go:26
SettingsAPI.ListCore¶
ListCore lists core config keys matching the prefix.
settings.go:35
SettingsAPI.ListPlugin¶
ListPlugin lists another plugin's config keys matching the prefix.
settings.go:49
SettingsAPI.Plugins¶
Plugins returns a list of all plugin config namespaces.
settings.go:61
SettingsAPI.RegisterDef¶
RegisterDef registers a config definition for UI display.
settings.go:52
SettingsAPI.Set¶
Set writes a config value to the plugin's own config table.
settings.go:8
SettingsAPI.SetCore¶
SetCore writes to the core config table.
settings.go:32
SettingsAPI.SetPlugin¶
SetPlugin writes to another plugin's config table.
settings.go:46
SettingsAPI.SetSecret¶
SetSecret writes a value that is ALWAYS encrypted at rest, regardless of the key name. Use it when the key name is neutral (e.g. "blob", "conn") and so cannot be detected as sensitive automatically.
Returns an error (not a silent plaintext write) when no master key is installed — a plugin that believes it stored a secret must not end up with plaintext on disk.
The companion read is GetSecret. ConfigDef.Secret/Type=="password" and sensitive key names are encrypted automatically and do NOT need this.
settings.go:20
ConfigDef¶
type ConfigDef struct { Key string `json:"key"` Default interface{} `json:"default,omitempty"` Type string `json:"type"` DisplayName string …
ConfigDef describes a configuration field for the WebUI.
settings.go:65
PluginSDK.Settings¶
Settings returns the settings API for reading/writing plugin configuration. sett 在 New 时一次性写入且无 setter,故不需要加锁。
示例插件里的真实用法
| 插件 | 位置 | 代码 |
|---|---|---|
feiyu_voice |
example/feiyu_voice/plugin.go:65 |
s.Settings().RegisterDef(sdk.ConfigDef{Key: "base_url", Default: "http://127.0.0.1:8765", Type: "string", |
rtvoice |
example/rtvoice/plugin.go:256 |
s.Settings().RegisterDef(sdk.ConfigDef{ |
plugin.go:685