refactor: rename /visitor-counter to /visit-counter

This commit is contained in:
axolotlmaid 2024-09-26 17:59:13 +01:00
parent 521a634d2e
commit b62f4cd017
4 changed files with 12 additions and 12 deletions

View file

@ -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)

View file

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

View file

@ -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)

View file

@ -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)