package main import ( "log" "os" "path/filepath" ) type config struct { todoDir string taskFilePath string doneFilePath string } func NewConfig() config { homePath := os.Getenv("HOME") todoDir, exists := os.LookupEnv("TODO_DIR") if !exists { todoDir = filepath.Join(homePath, ".todo") } _ = os.MkdirAll(todoDir, os.ModePerm) taskFilePath := filepath.Join(todoDir, "todo.txt") doneFilePath := filepath.Join(todoDir, "done.txt") if _, err := os.Stat(taskFilePath); os.IsNotExist(err) { _, e := os.Create(taskFilePath) if e != nil { log.Fatal(e) } } return config{ todoDir: todoDir, taskFilePath: taskFilePath, doneFilePath: doneFilePath, } }