Documentation
¶
Index ¶
- Constants
- func ConfigFilePath() (string, error)
- func ResolveAppsPathPrefix(cfg *Config) string
- func ResolveContainerRuntime(cfg *Config) string
- func ResolveContainerRuntimes(cfg *Config) []string
- func ResolveDatabaseLogLevel(cfg *Config) string
- func ResolveGitIdentity(cfg *Config) (string, string)
- func SaveConfigSection(key string, value any) (string, error)
- func SetCLIFlags(f *CLIFlags)
- type AgentConfig
- type CLIFlags
- type Config
- type ConfigFile
- type ContainerConfig
- type DatabaseConfig
- type DebugConfig
- type GitConfig
- type K8sIngressRouteConfig
- type KubernetesRuntimeConfig
- type LLMConfig
- type LLMProviderConfig
- type LogConfig
- type ModelProviderConfig
- type ProxyConfig
- type RealtimeConfig
- type RouteConfig
- type Section
- type ServerConfig
- type StorageConfig
- type TraefikRouteConfig
- type UserConfig
Constants ¶
const ( DefaultGitUser = "gobrave" DefaultGitEmail = "gobrave@123.com" )
默认 git 提交身份:config.yml 未配置 git 段或字段为空时使用。
const ( // DatabaseLogLevelSilent 完全关闭 SQL 日志。 DatabaseLogLevelSilent = "silent" // DatabaseLogLevelError 只打印执行报错的 SQL。 DatabaseLogLevelError = "error" // DatabaseLogLevelWarn 打印慢查询与报错的 SQL。 DatabaseLogLevelWarn = "warn" // DatabaseLogLevelInfo 打印每一条 SQL,仅用于排查问题。 DatabaseLogLevelInfo = "info" )
数据库 SQL 日志级别取值,与 GORM logger.LogLevel 一一对应。
const DefaultConfigFileName = "config.yml"
DefaultConfigFileName 是默认的配置文件名。
const DefaultDatabaseLogLevel = DatabaseLogLevelWarn
DefaultDatabaseLogLevel 是 database.log_level 未配置或取值非法时的默认级别。
Variables ¶
This section is empty.
Functions ¶
func ConfigFilePath ¶ added in v0.1.4
ConfigFilePath 解析 config.yml 的路径,规则与 LoadConfig 保持一致: CLI --config > BRAVE_CONFIG_DIR > 当前工作目录。
func ResolveAppsPathPrefix ¶
func ResolveContainerRuntime ¶
func ResolveContainerRuntimes ¶ added in v0.1.4
ResolveContainerRuntimes returns the normalized list of container runtimes to register at startup. It prefers the explicit `runtimes` list and falls back to the single resolved default runtime.
func ResolveDatabaseLogLevel ¶ added in v0.1.4
ResolveDatabaseLogLevel 返回当前生效的数据库 SQL 日志级别。 cfg 或其 database 段为空时返回默认级别。
func ResolveGitIdentity ¶ added in v0.1.4
ResolveGitIdentity 返回 git 提交使用的用户名与邮箱。 cfg 为 nil、git 段缺失或字段为空时,逐项回退到默认值。 保证返回值始终非空(go-git 的 commit author 不允许为空)。
func SaveConfigSection ¶ added in v0.1.4
SaveConfigSection 把某个顶层配置段写入 config.yml(不存在则创建), 其余配置段保持原样,该段中未建模的键也会保留。返回实际写入的文件路径。
func SetCLIFlags ¶
func SetCLIFlags(f *CLIFlags)
SetCLIFlags sets the CLI overrides to be applied by LoadConfig. Call this before LoadConfig is invoked (e.g. in main.go).
Types ¶
type AgentConfig ¶ added in v0.1.2
type AgentConfig struct {
// Providers 是「模型提供商」配置表,key 为模型名(与 Profile.Model 对应)。
// 一次请求使用的模型由 Profile.Model 指定,据此在此表中查找 base_url / api_key 等 LLM 配置。
Providers map[string]ModelProviderConfig `yaml:"providers" json:"providers"`
}
AgentConfig 是 AI Agent 调用框架的配置。 用于灵活切换第三方 Agent(claude_code / codex / copilot)以及后续自研 Agent。
type CLIFlags ¶
type CLIFlags struct {
ConfigPath string // --config, config file path
Port int // --port, server port
Host string // --host, server host
LogPath string // --log-path, server log path
LogLevel string // --log-level, log level (debug/info/warn/error/fatal)
GinMode string // --gin-mode, gin run mode (debug/release/test)
DBDriver string // --db-driver, database driver (sqlite/postgres)
DBHost string // --db-host, database host
DBPort string // --db-port, database port
DBUser string // --db-user, database user
DBPassword string // --db-password, database password
DBName string // --db-name, database name
DBPath string // --db-path, sqlite database file path
DBSSLMode string // --db-ssl-mode, database ssl mode
DefaultRuntime string // --default-runtime, default container runtime (docker/k8s/k3s)
BaseDir string // --base-dir, storage base directory
// contains filtered or unexported fields
}
CLIFlags holds command-line arguments that can override config.yml values.
func ParseCLIFlags ¶
func ParseCLIFlags() *CLIFlags
ParseCLIFlags parses command-line flags into a CLIFlags struct. It does NOT call flag.Parse() — the caller should do that.
func (*CLIFlags) DisableRegistrationSet ¶
DisableRegistrationSet reports whether --disable-registration was explicitly provided on the command line and returns its value.
type Config ¶
type Config struct {
Server *ServerConfig `yaml:"server" json:"server"`
Database *DatabaseConfig `yaml:"database" json:"database"`
Proxy *ProxyConfig `yaml:"proxy" json:"proxy"`
Route *RouteConfig `yaml:"route" json:"route"`
Storage *StorageConfig `yaml:"storage" json:"storage"`
Git *GitConfig `yaml:"git" json:"git"`
Realtime *RealtimeConfig `yaml:"realtime" json:"realtime"`
LLM *LLMConfig `yaml:"llm" json:"llm"`
Agent *AgentConfig `yaml:"agent" json:"agent"`
Container *ContainerConfig `yaml:"container" json:"container"`
DebugConfig *DebugConfig `yaml:"debug" json:"debug"`
User *UserConfig `yaml:"user" json:"user"`
Log *LogConfig `yaml:"log" json:"log"`
}
func LoadConfig ¶
LoadConfig 加载配置:先取代码内置默认值,再用 config.yml 覆盖。 文件中没有出现的键会保留默认值,具体语义见 applyConfigData。
type ConfigFile ¶ added in v0.1.4
type ConfigFile struct {
// Path 是 config.yml 的绝对路径。
Path string
// Exists 表示文档被加载时文件是否已经存在。
Exists bool
// contains filtered or unexported fields
}
ConfigFile 表示 config.yml 的原始 YAML 文档。 它保留顶层与嵌套键的顺序,因此更新某个配置段时不会打乱文件中的其他内容。
func LoadConfigFile ¶ added in v0.1.4
func LoadConfigFile() (*ConfigFile, error)
LoadConfigFile 读取 config.yml。 文件不存在时返回 Exists=false 的空文档(不视为错误), 调用方可以据此回退到代码中的默认配置。
func (*ConfigFile) Save ¶ added in v0.1.4
func (d *ConfigFile) Save() error
Save 把文档写回 config.yml;文件或其父目录不存在时自动创建。
func (*ConfigFile) Section ¶ added in v0.1.4
func (d *ConfigFile) Section(key string) any
Section 返回某个顶层配置段的原始值,不存在时返回 nil。
func (*ConfigFile) SetSection ¶ added in v0.1.4
func (d *ConfigFile) SetSection(key string, value any)
SetSection 写入或替换一个顶层配置段。
func (*ConfigFile) SetSectionMerged ¶ added in v0.1.4
func (d *ConfigFile) SetSectionMerged(key string, value any) error
SetSectionMerged 用 value 覆盖某个顶层配置段,同时保留原段落中 value 未声明的键。
这样即使 config.yml 里存在当前版本结构体尚未建模的键(例如旧版本的 container.create_queue_enabled),保存其它字段时也不会把它们丢掉。
type ContainerConfig ¶
type ContainerConfig struct {
Kubernetes *KubernetesRuntimeConfig `yaml:"kubernetes" json:"kubernetes"`
// Runtimes is the list of container runtimes to register at startup.
// e.g. [docker, k8s]. Each entry is normalized via normalizeContainerRuntime.
Runtimes []string `yaml:"runtimes" json:"runtimes"`
// DefaultRuntime is the runtime used when no specific runtime is selected.
// Falls back to the first entry in Runtimes, then "docker".
DefaultRuntime string `yaml:"default_runtime" json:"default_runtime"`
// RefreshImageStatusOnStart bool `yaml:"refresh_image_status_on_start" json:"refresh_image_status_on_start"`
RecoverRunningDagOnStart bool `yaml:"recover_running_dag_on_start" json:"recover_running_dag_on_start"`
CleanupDagNodeContainersBeforeStart bool `yaml:"cleanup_dag_node_containers_before_start" json:"cleanup_dag_node_containers_before_start"`
DeleteContainerOnNodeSuccess bool `yaml:"delete_container_on_node_success" json:"delete_container_on_node_success"`
DagNodeCleanupOnFailed string `yaml:"dag_node_cleanup_on_failed" json:"dag_node_cleanup_on_failed"`
DagNodeCleanupOnDagFinished string `yaml:"dag_node_cleanup_on_dag_finished" json:"dag_node_cleanup_on_dag_finished"`
// CreateQueueMaxConcurrency limits how many containers can be created concurrently.
CreateQueueMaxConcurrency int `yaml:"create_queue_max_concurrency" json:"create_queue_max_concurrency"`
// CreateQueueMaxPending limits how many creation requests can wait in the queue.
CreateQueueMaxPending int `yaml:"create_queue_max_pending" json:"create_queue_max_pending"`
}
func DefaultContainerConfig ¶ added in v0.1.4
func DefaultContainerConfig() *ContainerConfig
DefaultContainerConfig 返回 container 段在代码中的默认配置。 LoadConfig 与可视化配置共用它,保证 config.yml 缺失/缺段时的默认值一致。
type DatabaseConfig ¶
type DatabaseConfig struct {
Driver string `yaml:"driver" json:"driver"`
Host string `yaml:"host" json:"host"`
Port string `yaml:"port" json:"port"`
User string `yaml:"user" json:"user"`
Password string `yaml:"password" json:"password"`
Name string `yaml:"name" json:"name"`
SSLMode string `yaml:"ssl_mode" json:"ssl_mode"`
Path string `yaml:"path" json:"path"`
// LogLevel 控制 GORM 的 SQL 日志级别,取值 silent / error / warn / info。
// 默认 warn(只打印慢查询与报错的 SQL);设为 info 可打印每条 SQL,
// 仅在排查问题时开启;设为 silent 完全关闭。
// 该级别只影响 SQL 日志,与 log.level(进程日志级别)互不影响。
LogLevel string `yaml:"log_level" json:"log_level"`
}
DatabaseConfig 数据库配置
type DebugConfig ¶
type DebugConfig struct {
// EnableDagOrchestrator 为 true 时,提交分析会把编排器入参写入调试目录。
EnableDagOrchestrator bool `yaml:"enable_dag_orchestrator" json:"enable_dag_orchestrator"`
}
DebugConfig 调试开关。
type GitConfig ¶ added in v0.1.4
type GitConfig struct {
User string `yaml:"user" json:"user"`
Email string `yaml:"email" json:"email"`
}
GitConfig 是版本仓库(脚本/工作流目录)的提交身份配置。 SaveScript 等在初始化 git 仓库并提交变更时用它构造 commit 的 author/committer。
func DefaultGitConfig ¶ added in v0.1.4
func DefaultGitConfig() *GitConfig
DefaultGitConfig 返回 git 段在代码中的默认配置。 LoadConfig 与可视化配置共用它,保证 config.yml 缺失/缺段时的默认值一致。
type K8sIngressRouteConfig ¶
type K8sIngressRouteConfig struct {
Namespace string `yaml:"namespace" json:"namespace"`
Kubeconfig string `yaml:"kubeconfig" json:"kubeconfig"`
InCluster bool `yaml:"in_cluster" json:"in_cluster"`
IngressClassName string `yaml:"ingress_class_name" json:"ingress_class_name"`
Host string `yaml:"host" json:"host"`
PathType string `yaml:"path_type" json:"path_type"`
Annotations map[string]string `yaml:"annotations" json:"annotations"`
}
type KubernetesRuntimeConfig ¶
type KubernetesRuntimeConfig struct {
Namespace string `yaml:"namespace" json:"namespace"`
Kubeconfig string `yaml:"kubeconfig" json:"kubeconfig"`
InCluster bool `yaml:"in_cluster" json:"in_cluster"`
}
func DefaultKubernetesRuntimeConfig ¶ added in v0.1.4
func DefaultKubernetesRuntimeConfig() *KubernetesRuntimeConfig
DefaultKubernetesRuntimeConfig 返回 kubernetes 段的默认配置。
type LLMConfig ¶
type LLMConfig struct {
CLIURL string `yaml:"cli_url" json:"cli_url"`
Model string `yaml:"model" json:"model"`
GitHubToken string `yaml:"github_token" json:"github_token"`
Provider *LLMProviderConfig `yaml:"provider" json:"provider"`
}
type LLMProviderConfig ¶
type LogConfig ¶ added in v0.1.4
type LogConfig struct {
// Level 日志级别:trace/debug/info/warn/error/fatal/panic。默认 info。
// 需要开启 debug 模式时将其设为 debug 即可。
Level string `yaml:"level" json:"level"`
// Path 日志文件路径;为空时使用默认路径 logs/app.log。
Path string `yaml:"path" json:"path"`
// Color 颜色模式:auto(默认,仅终端着色)/always/never。
Color string `yaml:"color" json:"color"`
}
LogConfig 控制进程日志的级别与输出方式。 它的取值最终由 logger.Configure 应用,因此修改后无需改动日志代码。
func DefaultLogConfig ¶ added in v0.1.4
func DefaultLogConfig() *LogConfig
DefaultLogConfig 返回 log 段在代码中的默认配置。
type ModelProviderConfig ¶ added in v0.1.4
type ModelProviderConfig struct {
Model string `yaml:"model" json:"model"`
BaseURL string `yaml:"base_url" json:"base_url"`
APIKey string `yaml:"api_key" json:"api_key"`
BearerToken string `yaml:"bearer_token" json:"bearer_token"`
WorkingDir string `yaml:"working_dir" json:"working_dir"`
Extra map[string]string `yaml:"extra" json:"extra"`
}
ModelProviderConfig 描述一个「模型提供商」的连接配置(base_url / api_key / 类型等)。 与具体 Agent 无关,可被多个 Agent 共享。
type ProxyConfig ¶
type RealtimeConfig ¶
type RealtimeConfig struct {
Transport string `yaml:"transport" json:"transport"`
MaxConnectionsPerUser int `yaml:"max_connections_per_user" json:"max_connections_per_user"`
AckTimeoutSeconds int `yaml:"ack_timeout_seconds" json:"ack_timeout_seconds"`
AckMaxRetries int `yaml:"ack_max_retries" json:"ack_max_retries"`
}
type RouteConfig ¶
type RouteConfig struct {
// Registrys is the list of route registries to register at startup.
// e.g. [gateway, traefik, k8s-ingress]. Each entry is normalized via
// normalizeRouteRegistry.
Registrys []string `yaml:"registrys" json:"registrys"`
AppsPrefix string `yaml:"apps_prefix" json:"apps_prefix"`
Traefik *TraefikRouteConfig `yaml:"traefik" json:"traefik"`
K8sIngress *K8sIngressRouteConfig `yaml:"k8s_ingress" json:"k8s_ingress"`
}
type Section ¶ added in v0.1.4
type Section struct {
// Key 是配置段在 config.yml 中的顶层键名,同时也是 API 中使用的段标识。
Key string
// Label 是用于错误提示的中文名称。
Label string
// Effective 返回当前生效的配置段值(用于表单回填与落盘)。
Effective func(cfg *Config) any
// Decode 解析并归一化请求体,返回待落盘的值;不会修改 cfg。
Decode func(raw json.RawMessage) (any, error)
// Apply 把已经成功落盘的值写入内存配置,使其立即生效。
Apply func(cfg *Config, value any) error
}
Section 描述一个可以通过可视化界面编辑的配置段。
新增一个可编辑的配置段只需要在 sections 中注册一次, HTTP 层无需新增接口,前端只需新增一个 section 组件。
func FindSection ¶ added in v0.1.4
FindSection 按 key 查找已注册的配置段。
func RegisteredSections ¶ added in v0.1.4
func RegisteredSections() []*Section
RegisteredSections 返回所有已注册的可视化配置段。
type ServerConfig ¶
type ServerConfig struct {
Port int `yaml:"port" json:"port"`
// GRPCPort int `yaml:"grpc_port" json:"grpc_port"`
Host string `yaml:"host" json:"host"`
ShutdownTimeout time.Duration `yaml:"shutdown_timeout" json:"shutdown_timeout" default:"30s"`
// Mode 是 Gin 运行模式:debug / release / test。
// 留空时回退到 GIN_MODE 环境变量,最后回退到默认值(debug)。
Mode string `yaml:"mode" json:"mode"`
}
ServerConfig 服务器配置
type StorageConfig ¶
type StorageConfig struct {
// ImageDir string `yaml:"image_dir" json:"image_dir"`
BaseDir string `yaml:"base_dir" json:"base_dir"`
}
type TraefikRouteConfig ¶
type TraefikRouteConfig struct {
Provider string `yaml:"provider" json:"provider"`
BaseURL string `yaml:"base_url" json:"base_url"`
UpsertPath string `yaml:"upsert_path" json:"upsert_path"`
DeletePath string `yaml:"delete_path" json:"delete_path"`
AuthToken string `yaml:"auth_token" json:"auth_token"`
TimeoutSecond int `yaml:"timeout_second" json:"timeout_second"`
FilePath string `yaml:"file_path" json:"file_path"`
}