new-app-doxatodo

This commit is contained in:
kankys committed 2026-08-08 10:28:03 +02:00
1 parent 5eacbb0182
commit 16414091b4
14 files changed
+2287 -20

No files matched your search

+47
View File
@@ -0,0 +1,47 @@
package main
import (
"encoding/json"
"fmt"
"os"
"path/filepath"
)
// getStoragePath returns the path to the .doxa-todo directory and file
func getStoragePath() string {
home, err := os.UserHomeDir()
if err != nil {
return "doxa_todo.json" // fallback to current directory
}
configDir := filepath.Join(home, ".doxa-todo")
// Create directory if it doesn't exist
if _, err := os.Stat(configDir); os.IsNotExist(err) {
os.MkdirAll(configDir, 0755)
}
return filepath.Join(configDir, "doxa_todo.json")
}
// loadTodos loads all todos from the storage file
func loadTodos() []Todo {
path := getStoragePath()
file, err := os.ReadFile(path)
if err != nil {
return []Todo{}
}
var todos []Todo
json.Unmarshal(file, &todos)
return todos
}
// saveTodos saves all todos to the storage file
func saveTodos(todos []Todo) {
path := getStoragePath()
data, err := json.MarshalIndent(todos, "", " ")
if err != nil {
fmt.Println("Chyba při ukládání dat:", err)
return
}
os.WriteFile(path, data, 0644)
}