Enhance configuration path resolution in LoadWithRoot function
- Update the LoadWithRoot function in config.go to ensure DataRoot is set correctly when it is empty, and resolve relative database paths for SQLite3 driver based on the Root directory. - Improve handling of non-absolute paths for primary and secondary database connections, enhancing overall configuration management.
This commit is contained in:
parent
2d86ee5b6e
commit
88c55b39c0
1 changed files with 14 additions and 2 deletions
|
|
@ -138,8 +138,20 @@ func LoadWithRoot(root string) Config {
|
|||
// DataRoot
|
||||
if cfg.DataRoot == "" {
|
||||
cfg.DataRoot = filepath.Join(cfg.Root, "data")
|
||||
if !filepath.IsAbs(cfg.DataRoot) {
|
||||
cfg.DataRoot, _ = filepath.Abs(cfg.DataRoot)
|
||||
}
|
||||
if !filepath.IsAbs(cfg.DataRoot) {
|
||||
cfg.DataRoot = filepath.Join(cfg.Root, cfg.DataRoot)
|
||||
}
|
||||
|
||||
// Resolve DB relative paths based on Root
|
||||
for i, dsn := range cfg.DB.Primary {
|
||||
if !filepath.IsAbs(dsn) && (cfg.DB.Driver == "sqlite3" || cfg.DB.Driver == "") {
|
||||
cfg.DB.Primary[i] = filepath.Join(cfg.Root, dsn)
|
||||
}
|
||||
}
|
||||
for i, dsn := range cfg.DB.Secondary {
|
||||
if !filepath.IsAbs(dsn) && (cfg.DB.Driver == "sqlite3" || cfg.DB.Driver == "") {
|
||||
cfg.DB.Secondary[i] = filepath.Join(cfg.Root, dsn)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue