mirror of
https://codeberg.org/Kankys/doxa.git
synced 2026-11-11 14:44:36 +01:00
new-doxa-monorepo
This commit is contained in:
1 parent
b4401527a3
commit
5eacbb0182
162 files changed
+21820
-2
No files matched your search
@@ -0,0 +1,55 @@
|
||||
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)
|
||||
}
|
||||
Reference in new issue
Block a user