mirror of
https://codeberg.org/Kankys/doxa.git
synced 2026-11-11 06:44:36 +01:00
55 lines
1.1 KiB
Go
55 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"time"
|
|
)
|
|
|
|
type Note struct {
|
|
ID int64 `json:"id"`
|
|
Name string `json:"name"`
|
|
Content string `json:"content"`
|
|
Tags []string `json:"tags"`
|
|
Folder string `json:"folder"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
ModifiedAt time.Time `json:"modified_at"`
|
|
}
|
|
|
|
func getStoragePath() string {
|
|
home, err := os.UserHomeDir()
|
|
if err != nil {
|
|
return "doxa_notes.json" // fallback do aktuálního adresáře
|
|
}
|
|
configDir := filepath.Join(home, ".doxa-cli")
|
|
|
|
// Vytvoření složky, pokud neexistuje
|
|
if _, err := os.Stat(configDir); os.IsNotExist(err) {
|
|
os.MkdirAll(configDir, 0755)
|
|
}
|
|
|
|
return filepath.Join(configDir, "doxa_notes.json")
|
|
}
|
|
|
|
func loadNotes() []Note {
|
|
path := getStoragePath()
|
|
file, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return []Note{}
|
|
}
|
|
var notes []Note
|
|
json.Unmarshal(file, ¬es)
|
|
return notes
|
|
}
|
|
|
|
func saveNotes(notes []Note) {
|
|
path := getStoragePath()
|
|
data, err := json.MarshalIndent(notes, "", " ")
|
|
if err != nil {
|
|
fmt.Println("Chyba při ukládání dat:", err)
|
|
return
|
|
}
|
|
os.WriteFile(path, data, 0644)
|
|
} |