feat: add getting visitor counter

This commit is contained in:
axolotlmaid 2024-09-25 17:55:40 +01:00
parent 0f2d805df2
commit bd31a363df
4 changed files with 58 additions and 0 deletions

View file

@ -0,0 +1,30 @@
package service
import (
"encoding/json"
"io"
"log/slog"
"os"
"path/filepath"
"backend/internal/model"
)
func GetVisitorCounter() model.VisitorCounter {
path := filepath.Join(".", "data", "visitor.json")
jsonFile, err := os.Open(path)
if err != nil {
slog.Warn("File not found!", slog.Any("file", path))
return model.VisitorCounter{}
}
bytes, _ := io.ReadAll(jsonFile)
var data model.VisitorCounter
err = json.Unmarshal(bytes, &data)
if err != nil {
slog.Error("Error unmarshalling JSON", slog.Any("error", err), slog.Any("file", path))
}
return data
}