ketotrack/config/config.go

32 lines
1.1 KiB
Go
Raw Normal View History

2024-05-12 21:03:47 +00:00
// Package config handles the configuration aspects of the KetoTrack application.
// It includes definitions and routines necessary for setting up and retrieving
// application configuration settings, such as data storage paths.
2024-05-12 19:46:06 +00:00
package config
import (
"os"
"path/filepath"
)
2024-05-12 21:03:47 +00:00
// AppConfig holds configuration details for the application. It currently
// only includes the path to the data storage location.
2024-05-12 19:46:06 +00:00
type AppConfig struct {
DataPath string
}
2024-05-12 21:03:47 +00:00
// Load initializes the application configuration by ensuring the required
// directories exist and setting the path for data storage. It creates a
// directory named ".ketotrack" in the user's home directory if it does not already
// exist, and sets the data path to "records.json" within this directory.
// The function loads these settings into an AppConfig instance and returns it.
2024-05-12 19:46:06 +00:00
func Load() AppConfig {
2024-05-12 21:03:47 +00:00
// TODO: Handle os.UserHomeDir errors
// TODO: Handle os.MkdirAll errors
2024-05-12 19:46:06 +00:00
homeDir, _ := os.UserHomeDir()
ketotrackDir := filepath.Join(homeDir, ".ketotrack")
2024-05-12 21:03:47 +00:00
os.MkdirAll(ketotrackDir, 0770)
2024-05-12 19:46:06 +00:00
return AppConfig{
DataPath: filepath.Join(ketotrackDir, "records.json"),
}
}