refactor: adopt PathRegistry in api server_config.go
Update internal/api/server_config.go to use centralized PathRegistry: Changes: - Update EnsureLogDirectory() to use config.FromEnv().LogDir() with EnsureDir() - Update Validate() to use PathRegistry for default BasePath and DataDir - Remove hardcoded /tmp/ml-experiments default - Use paths.ExperimentsDir() and paths.DataDir() for consistent paths Benefits: - Consistent directory locations via PathRegistry - Centralized directory creation with EnsureDir() - Better error handling for directory creation
This commit is contained in:
parent
2101e4a01c
commit
4bee42493b
1 changed files with 14 additions and 7 deletions
|
|
@ -3,7 +3,6 @@ package api
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
|
@ -135,15 +134,20 @@ func secureFileRead(path string) ([]byte, error) {
|
||||||
return fileutil.SecureFileRead(path)
|
return fileutil.SecureFileRead(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
// EnsureLogDirectory creates the log directory if needed
|
// EnsureLogDirectory creates the log directory if needed using PathRegistry
|
||||||
func (c *ServerConfig) EnsureLogDirectory() error {
|
func (c *ServerConfig) EnsureLogDirectory() error {
|
||||||
if c.Logging.File == "" {
|
if c.Logging.File == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
logDir := filepath.Dir(c.Logging.File)
|
// Use PathRegistry for consistent log directory management
|
||||||
log.Printf("Creating log directory: %s", logDir)
|
paths := config.FromEnv()
|
||||||
return os.MkdirAll(logDir, 0750)
|
logDir := paths.LogDir()
|
||||||
|
|
||||||
|
if err := paths.EnsureDir(logDir); err != nil {
|
||||||
|
return fmt.Errorf("failed to create log directory: %w", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// BuildAuthConfig creates the auth configuration
|
// BuildAuthConfig creates the auth configuration
|
||||||
|
|
@ -163,11 +167,14 @@ func (c *ServerConfig) Validate() error {
|
||||||
c.Server.Address = ":8080"
|
c.Server.Address = ":8080"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Use PathRegistry for consistent path management
|
||||||
|
paths := config.FromEnv()
|
||||||
|
|
||||||
if c.BasePath == "" {
|
if c.BasePath == "" {
|
||||||
c.BasePath = "/tmp/ml-experiments"
|
c.BasePath = paths.ExperimentsDir()
|
||||||
}
|
}
|
||||||
if c.DataDir == "" {
|
if c.DataDir == "" {
|
||||||
c.DataDir = config.DefaultDataDir
|
c.DataDir = paths.DataDir()
|
||||||
}
|
}
|
||||||
|
|
||||||
backend := strings.ToLower(strings.TrimSpace(c.Queue.Backend))
|
backend := strings.ToLower(strings.TrimSpace(c.Queue.Backend))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue