# 配置(Settings) 声明插件自己的配置项,内核会把它渲染到 WebUI 的设置页,并为每个插件维护独立的配置表。 ## `SettingsAPI` | 方法 | 说明 | |---|---| | [`DataDir`](#settingsapidatadir) | DataDir returns the plugin-specific data directory (guaranteed to exist): | | [`Defs`](#settingsapidefs) | Defs returns config definitions matching the prefix. | | [`Dump`](#settingsapidump) | Dump returns all config values. | | [`Get`](#settingsapiget) | Get reads the plugin's own config value (config_ table). | | [`GetCore`](#settingsapigetcore) | GetCore reads the core config table. | | [`GetPlugin`](#settingsapigetplugin) | GetPlugin reads another plugin's config table. | | [`List`](#settingsapilist) | List returns all keys matching the given prefix. | | [`ListCore`](#settingsapilistcore) | ListCore lists core config keys matching the prefix. | | [`ListPlugin`](#settingsapilistplugin) | ListPlugin lists another plugin's config keys matching the prefix. | | [`Plugins`](#settingsapiplugins) | Plugins returns a list of all plugin config namespaces. | | [`RegisterDef`](#settingsapiregisterdef) | RegisterDef registers a config definition for UI display. | | [`Set`](#settingsapiset) | Set writes a config value to the plugin's own config table. | | [`SetCore`](#settingsapisetcore) | SetCore writes to the core config table. | | [`SetPlugin`](#settingsapisetplugin) | SetPlugin writes to another plugin's config table. | ### `SettingsAPI.DataDir` ```go DataDir() string ``` DataDir returns the plugin-specific data directory (guaranteed to exist): /plugin_data/. Plugins should persist any runtime files (generated images, caches, downloads) here. `settings.go:25` ### `SettingsAPI.Defs` ```go Defs(prefix string) []*ConfigDef ``` Defs returns config definitions matching the prefix. `settings.go:40` ### `SettingsAPI.Dump` ```go Dump() map[string]interface{} ``` Dump returns all config values. `settings.go:43` ### `SettingsAPI.Get` ```go Get(key string) (interface{}, error) ``` Get reads the plugin's own config value (config_ table). `settings.go:5` ### `SettingsAPI.GetCore` ```go GetCore(key string) (interface{}, error) ``` GetCore reads the core config table. `settings.go:14` ### `SettingsAPI.GetPlugin` ```go GetPlugin(plugin, key string) (interface{}, error) ``` GetPlugin reads another plugin's config table. `settings.go:28` ### `SettingsAPI.List` ```go List(prefix string) ([]string, error) ``` List returns all keys matching the given prefix. `settings.go:11` ### `SettingsAPI.ListCore` ```go ListCore(prefix string) ([]string, error) ``` ListCore lists core config keys matching the prefix. `settings.go:20` ### `SettingsAPI.ListPlugin` ```go ListPlugin(plugin, prefix string) ([]string, error) ``` ListPlugin lists another plugin's config keys matching the prefix. `settings.go:34` ### `SettingsAPI.Plugins` ```go Plugins() []string ``` Plugins returns a list of all plugin config namespaces. `settings.go:46` ### `SettingsAPI.RegisterDef` ```go RegisterDef(def ConfigDef) ``` RegisterDef registers a config definition for UI display. `settings.go:37` ### `SettingsAPI.Set` ```go Set(key string, value interface{}) error ``` Set writes a config value to the plugin's own config table. `settings.go:8` ### `SettingsAPI.SetCore` ```go SetCore(key string, value interface{}) error ``` SetCore writes to the core config table. `settings.go:17` ### `SettingsAPI.SetPlugin` ```go SetPlugin(plugin, key string, value interface{}) error ``` SetPlugin writes to another plugin's config table. `settings.go:31` ### `ConfigDef` ```go 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:50` ### `PluginSDK.Settings` ```go func (s *PluginSDK) Settings() SettingsAPI ``` Settings returns the settings API for reading/writing plugin configuration. sett 在 New 时一次性写入且无 setter,故不需要加锁。 **示例插件里的真实用法** | 插件 | 位置 | 代码 | |---|---|---| | [`a2a`](../examples/index.md#a2a) | `example/a2a/plugin.go:68` | `s.Settings().RegisterDef(sdk.ConfigDef{` | | [`acp`](../examples/index.md#acp) | `example/acp/plugin.go:63` | `s.Settings().RegisterDef(sdk.ConfigDef{` | | [`ai_image`](../examples/index.md#ai_image) | `example/ai_image/plugin.go:114` | `s.Settings().RegisterDef(sdk.ConfigDef{` | | [`bili`](../examples/index.md#bili) | `example/bili/plugin.go:29` | `s.Settings().RegisterDef(sdk.ConfigDef{` | `plugin.go:401`