refactor: rename /visitor-counter to /visit-counter
This commit is contained in:
parent
521a634d2e
commit
b62f4cd017
4 changed files with 12 additions and 12 deletions
|
|
@ -6,15 +6,15 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
func HandleGetVisitorCounter(w http.ResponseWriter, r *http.Request) {
|
func HandleGetVisitCounter(w http.ResponseWriter, r *http.Request) {
|
||||||
data := service.GetVisitorCounter()
|
data := service.GetVisitCounter()
|
||||||
|
|
||||||
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 HandlePatchVisitorCounter(w http.ResponseWriter, r *http.Request) {
|
func HandlePatchVisitCounter(w http.ResponseWriter, r *http.Request) {
|
||||||
data := service.IncrementVisitorCounter()
|
data := service.IncrementVisitCounter()
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
json.NewEncoder(w).Encode(data)
|
json.NewEncoder(w).Encode(data)
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
package model
|
package model
|
||||||
|
|
||||||
type VisitorCounter struct {
|
type VisitCounter struct {
|
||||||
Counter uint32 `json:"counter"`
|
Counter uint32 `json:"counter"`
|
||||||
}
|
}
|
||||||
|
|
@ -32,8 +32,8 @@ func NewRouter() {
|
||||||
http.Redirect(w, r, "https://axolotlmaid.com", http.StatusPermanentRedirect)
|
http.Redirect(w, r, "https://axolotlmaid.com", http.StatusPermanentRedirect)
|
||||||
})
|
})
|
||||||
|
|
||||||
r.Get("/visitor-counter", handler.HandleGetVisitorCounter)
|
r.Get("/visit-counter", handler.HandleGetVisitCounter)
|
||||||
r.With(httprate.LimitByRealIP(1, time.Hour)).Patch("/visitor-counter", handler.HandlePatchVisitorCounter)
|
r.With(httprate.LimitByRealIP(1, time.Hour)).Patch("/visit-counter", handler.HandlePatchVisitCounter)
|
||||||
|
|
||||||
r.Get("/currently-playing", handler.HandleGetCurrentlyPlaying)
|
r.Get("/currently-playing", handler.HandleGetCurrentlyPlaying)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,10 @@ import (
|
||||||
"backend/internal/model"
|
"backend/internal/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
const path = "./data/visitor.json"
|
const path = "./data/visit.json"
|
||||||
|
|
||||||
func GetVisitorCounter() model.VisitorCounter {
|
func GetVisitCounter() model.VisitCounter {
|
||||||
var data model.VisitorCounter
|
var data model.VisitCounter
|
||||||
|
|
||||||
jsonFile, err := os.Open(path)
|
jsonFile, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -37,8 +37,8 @@ func GetVisitorCounter() model.VisitorCounter {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
func IncrementVisitorCounter() model.Success {
|
func IncrementVisitCounter() model.Success {
|
||||||
data := GetVisitorCounter()
|
data := GetVisitCounter()
|
||||||
data.Counter++
|
data.Counter++
|
||||||
|
|
||||||
err := os.MkdirAll(filepath.Dir(path), 0755)
|
err := os.MkdirAll(filepath.Dir(path), 0755)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue