refactor: rename visitor counter to hit counter

This commit is contained in:
trafficlunar 2025-03-20 22:31:39 +00:00
parent 38b93391a1
commit 32aea2cbd5
4 changed files with 12 additions and 12 deletions

View file

@ -6,15 +6,15 @@ import (
"net/http" "net/http"
) )
func HandleGetVisitCounter(w http.ResponseWriter, r *http.Request) { func HandleGetHitCounter(w http.ResponseWriter, r *http.Request) {
data := service.GetVisitCounter() data := service.GetHitCounter()
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(data) json.NewEncoder(w).Encode(data)
} }
func HandlePatchVisitCounter(w http.ResponseWriter, r *http.Request) { func HandlePatchHitCounter(w http.ResponseWriter, r *http.Request) {
data := service.IncrementVisitCounter() data := service.IncrementHitCounter()
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(data) json.NewEncoder(w).Encode(data)

View file

@ -1,5 +1,5 @@
package model package model
type VisitCounter struct { type HitCounter struct {
Counter uint32 `json:"counter"` Counter uint32 `json:"counter"`
} }

View file

@ -46,8 +46,8 @@ func NewRouter() {
http.Redirect(w, r, "https://trafficlunar.net", http.StatusPermanentRedirect) http.Redirect(w, r, "https://trafficlunar.net", http.StatusPermanentRedirect)
}) })
r.Get("/visit", handler.HandleGetVisitCounter) r.Get("/hit", handler.HandleGetHitCounter)
r.With(httprate.LimitByRealIP(1, time.Hour)).Patch("/visit", handler.HandlePatchVisitCounter) r.With(httprate.LimitByRealIP(1, time.Hour)).Patch("/hit", handler.HandlePatchHitCounter)
r.Get("/song", handler.HandleGetCurrentlyPlaying) r.Get("/song", handler.HandleGetCurrentlyPlaying)
r.Get("/computer", handler.HandleComputerGraphData) r.Get("/computer", handler.HandleComputerGraphData)
r.Get("/computer/ws", handler.HandleComputerWebSocket) r.Get("/computer/ws", handler.HandleComputerWebSocket)

View file

@ -10,10 +10,10 @@ import (
"backend/internal/model" "backend/internal/model"
) )
const path = "./data/visit.json" const path = "./data/hit.json"
func GetVisitCounter() model.VisitCounter { func GetHitCounter() model.HitCounter {
var data model.VisitCounter var data model.HitCounter
jsonFile, err := os.Open(path) jsonFile, err := os.Open(path)
if err != nil { if err != nil {
@ -37,8 +37,8 @@ func GetVisitCounter() model.VisitCounter {
return data return data
} }
func IncrementVisitCounter() model.Success { func IncrementHitCounter() model.Success {
data := GetVisitCounter() data := GetHitCounter()
data.Counter++ data.Counter++
err := os.MkdirAll(filepath.Dir(path), 0755) err := os.MkdirAll(filepath.Dir(path), 0755)