add method to handlers
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
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)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user