mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-06 07:54:22 +00:00
Test config package
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
// Package config provides the configuration for the application
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"novamd/internal/crypto"
|
||||
)
|
||||
|
||||
// Config holds the configuration for the application
|
||||
type Config struct {
|
||||
DBPath string
|
||||
WorkDir string
|
||||
@@ -27,6 +28,7 @@ type Config struct {
|
||||
IsDevelopment bool
|
||||
}
|
||||
|
||||
// DefaultConfig returns a new Config instance with default values
|
||||
func DefaultConfig() *Config {
|
||||
return &Config{
|
||||
DBPath: "./novamd.db",
|
||||
@@ -39,6 +41,7 @@ func DefaultConfig() *Config {
|
||||
}
|
||||
}
|
||||
|
||||
// Validate checks if the configuration is valid
|
||||
func (c *Config) Validate() error {
|
||||
if c.AdminEmail == "" || c.AdminPassword == "" {
|
||||
return fmt.Errorf("NOVAMD_ADMIN_EMAIL and NOVAMD_ADMIN_PASSWORD must be set")
|
||||
@@ -63,16 +66,10 @@ func Load() (*Config, error) {
|
||||
if dbPath := os.Getenv("NOVAMD_DB_PATH"); dbPath != "" {
|
||||
config.DBPath = dbPath
|
||||
}
|
||||
if err := ensureDir(filepath.Dir(config.DBPath)); err != nil {
|
||||
return nil, fmt.Errorf("failed to create database directory: %w", err)
|
||||
}
|
||||
|
||||
if workDir := os.Getenv("NOVAMD_WORKDIR"); workDir != "" {
|
||||
config.WorkDir = workDir
|
||||
}
|
||||
if err := ensureDir(config.WorkDir); err != nil {
|
||||
return nil, fmt.Errorf("failed to create work directory: %w", err)
|
||||
}
|
||||
|
||||
if staticPath := os.Getenv("NOVAMD_STATIC_PATH"); staticPath != "" {
|
||||
config.StaticPath = staticPath
|
||||
@@ -115,10 +112,3 @@ func Load() (*Config, error) {
|
||||
|
||||
return config, nil
|
||||
}
|
||||
|
||||
func ensureDir(dir string) error {
|
||||
if dir == "" {
|
||||
return nil
|
||||
}
|
||||
return os.MkdirAll(dir, 0755)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user