diff --git a/internal/handler/visitor.go b/internal/handler/visit.go similarity index 55% rename from internal/handler/visitor.go rename to internal/handler/visit.go index 998fdb6..7a5d538 100644 --- a/internal/handler/visitor.go +++ b/internal/handler/visit.go @@ -6,15 +6,15 @@ import ( "net/http" ) -func HandleGetVisitorCounter(w http.ResponseWriter, r *http.Request) { - data := service.GetVisitorCounter() +func HandleGetVisitCounter(w http.ResponseWriter, r *http.Request) { + data := service.GetVisitCounter() w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(data) } -func HandlePatchVisitorCounter(w http.ResponseWriter, r *http.Request) { - data := service.IncrementVisitorCounter() +func HandlePatchVisitCounter(w http.ResponseWriter, r *http.Request) { + data := service.IncrementVisitCounter() w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(data) diff --git a/internal/model/visitor.go b/internal/model/visit.go similarity index 63% rename from internal/model/visitor.go rename to internal/model/visit.go index e8d5393..986cf3a 100644 --- a/internal/model/visitor.go +++ b/internal/model/visit.go @@ -1,5 +1,5 @@ package model -type VisitorCounter struct { +type VisitCounter struct { Counter uint32 `json:"counter"` } diff --git a/internal/server/router.go b/internal/server/router.go index 2caf584..1a9510c 100644 --- a/internal/server/router.go +++ b/internal/server/router.go @@ -32,8 +32,8 @@ func NewRouter() { http.Redirect(w, r, "https://axolotlmaid.com", http.StatusPermanentRedirect) }) - r.Get("/visitor-counter", handler.HandleGetVisitorCounter) - r.With(httprate.LimitByRealIP(1, time.Hour)).Patch("/visitor-counter", handler.HandlePatchVisitorCounter) + r.Get("/visit-counter", handler.HandleGetVisitCounter) + r.With(httprate.LimitByRealIP(1, time.Hour)).Patch("/visit-counter", handler.HandlePatchVisitCounter) r.Get("/currently-playing", handler.HandleGetCurrentlyPlaying) diff --git a/internal/service/visitor.go b/internal/service/visitor.go index 7403f51..ba8e8b0 100644 --- a/internal/service/visitor.go +++ b/internal/service/visitor.go @@ -10,10 +10,10 @@ import ( "backend/internal/model" ) -const path = "./data/visitor.json" +const path = "./data/visit.json" -func GetVisitorCounter() model.VisitorCounter { - var data model.VisitorCounter +func GetVisitCounter() model.VisitCounter { + var data model.VisitCounter jsonFile, err := os.Open(path) if err != nil { @@ -37,8 +37,8 @@ func GetVisitorCounter() model.VisitorCounter { return data } -func IncrementVisitorCounter() model.Success { - data := GetVisitorCounter() +func IncrementVisitCounter() model.Success { + data := GetVisitCounter() data.Counter++ err := os.MkdirAll(filepath.Dir(path), 0755)