config

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package config 负责加载与解析 dbm 的 YAML 配置。

配置文件查找顺序(首个命中即用):

  1. --config 指定的路径
  2. 当前目录:./.dbm-cli.yaml → ./.dbm-cli.yml → ./dbm-cli.yaml → ./dbm-cli.yml
  3. 用户主目录:~/.dbm-cli.yaml → ~/.dbm-cli.yml
  4. $XDG_CONFIG_HOME/dbm-cli/config.yaml(或 ~/.config/dbm-cli/config.yaml)

配置内支持 ${ENV_VAR} 占位,加载时从环境变量展开,避免在文件里明文存放密码。

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("config: no dbm-cli config file found (create ./.dbm-cli.yaml or ~/.dbm-cli.yaml, or set --config)")

ErrNotFound 表示未找到任何配置文件。

Functions

func DefaultSearchPaths

func DefaultSearchPaths() []string

DefaultSearchPaths 返回配置文件的查找路径(按优先级从高到低), 但不包含显式 --config 指定的路径(该路径在 Load 中单独处理)。 注意:这里返回的都是「候选」,首个存在者生效。

规范的配置文件名是 .dbm-cli.yaml(dotfile 形式,cwd 与 home 一致); 此外也兼容不带点的 dbm-cli.yaml/.yml 与 XDG 标准位置。

Types

type File

type File struct {
	Default     string                              `yaml:"default"`     // 默认数据源名
	Datasources map[string]*driver.DatasourceConfig `yaml:"datasources"` // 数据源集合
}

File 是 dbm.yaml 的顶层结构。

func Load

func Load(path string) (*File, error)

Load 从指定路径加载配置。 若 path 为空,则按 DefaultSearchPaths 顺序查找首个存在文件。 找不到任何配置文件时返回 ErrNotFound。

func (*File) Validate

func (f *File) Validate() error

Validate 做基本完整性校验:default 指向的数据源必须存在。

type ValidationError

type ValidationError struct {
	Field   string
	Message string
}

ValidationError 表示配置校验失败。

func (*ValidationError) Error

func (e *ValidationError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL