This commit is contained in:
@@ -3,22 +3,32 @@ package config
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
DatabasePath string
|
||||
CachePath string
|
||||
}
|
||||
|
||||
// LoadConfig loads configuration from environment variables
|
||||
func LoadConfig() *Config {
|
||||
cfg := &Config{
|
||||
DatabasePath: getEnv("DATABASE_PATH", "./butterfliu.db"),
|
||||
CachePath: getEnv("CACHE_PATH", "./cache"),
|
||||
}
|
||||
os.MkdirAll(cfg.CachePath, os.ModeAppend)
|
||||
|
||||
return cfg
|
||||
}
|
||||
|
||||
func (self *Config) GetCachePath(cacheType string) string {
|
||||
path := path.Join(self.CachePath, cacheType)
|
||||
os.MkdirAll(path, os.ModeAppend)
|
||||
return path
|
||||
}
|
||||
|
||||
// getEnv gets an environment variable with a default value
|
||||
func getEnv(key, defaultValue string) string {
|
||||
if value := os.Getenv(key); value != "" {
|
||||
|
||||
Reference in New Issue
Block a user