mirror of
https://codeberg.org/Kankys/doxa.git
synced 2026-11-11 14:44:36 +01:00
48 lines
1.0 KiB
Go
48 lines
1.0 KiB
Go
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)
|
|
}
|