Files
Thomas Peetz 2aeba70906
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 12s
Gitea Actions Demo / build-and-test (push) Failing after 19m54s
add Database type to cli and server config
2026-10-29 00:14:54 +01:00

37 lines
766 B
Go

package api
import (
"encoding/json"
"log/slog"
"os"
)
func WriteJson(data *ExportData, fileName string) error {
jsonData, err := json.MarshalIndent(data, "", " ")
if err != nil {
slog.Info("JSON MarshalIndent failed", "Error:", err)
return err
}
// Write bytes to file
err = os.WriteFile(fileName, jsonData, 0644)
if err != nil {
slog.Info("Error writing file:", "Error", err.Error())
return err
}
return nil
}
func ReadJson(data *ExportData, fileName string) error {
content, err := os.ReadFile(fileName)
if err != nil {
slog.Info("Error reading file", "Error", err.Error())
return err
}
if err := json.Unmarshal(content, data); err != nil {
slog.Info("Error unmarshal json", "Error", err.Error())
return err
}
return nil
}