refactor: rename visitor counter to hit counter
This commit is contained in:
parent
38b93391a1
commit
32aea2cbd5
4 changed files with 12 additions and 12 deletions
|
|
@ -6,15 +6,15 @@ import (
|
|||
"net/http"
|
||||
)
|
||||
|
||||
func HandleGetVisitCounter(w http.ResponseWriter, r *http.Request) {
|
||||
data := service.GetVisitCounter()
|
||||
func HandleGetHitCounter(w http.ResponseWriter, r *http.Request) {
|
||||
data := service.GetHitCounter()
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(data)
|
||||
}
|
||||
|
||||
func HandlePatchVisitCounter(w http.ResponseWriter, r *http.Request) {
|
||||
data := service.IncrementVisitCounter()
|
||||
func HandlePatchHitCounter(w http.ResponseWriter, r *http.Request) {
|
||||
data := service.IncrementHitCounter()
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(data)
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
package model
|
||||
|
||||
type VisitCounter struct {
|
||||
type HitCounter struct {
|
||||
Counter uint32 `json:"counter"`
|
||||
}
|
||||
|
|
@ -46,8 +46,8 @@ func NewRouter() {
|
|||
http.Redirect(w, r, "https://trafficlunar.net", http.StatusPermanentRedirect)
|
||||
})
|
||||
|
||||
r.Get("/visit", handler.HandleGetVisitCounter)
|
||||
r.With(httprate.LimitByRealIP(1, time.Hour)).Patch("/visit", handler.HandlePatchVisitCounter)
|
||||
r.Get("/hit", handler.HandleGetHitCounter)
|
||||
r.With(httprate.LimitByRealIP(1, time.Hour)).Patch("/hit", handler.HandlePatchHitCounter)
|
||||
r.Get("/song", handler.HandleGetCurrentlyPlaying)
|
||||
r.Get("/computer", handler.HandleComputerGraphData)
|
||||
r.Get("/computer/ws", handler.HandleComputerWebSocket)
|
||||
|
|
|
|||
|
|
@ -10,10 +10,10 @@ import (
|
|||
"backend/internal/model"
|
||||
)
|
||||
|
||||
const path = "./data/visit.json"
|
||||
const path = "./data/hit.json"
|
||||
|
||||
func GetVisitCounter() model.VisitCounter {
|
||||
var data model.VisitCounter
|
||||
func GetHitCounter() model.HitCounter {
|
||||
var data model.HitCounter
|
||||
|
||||
jsonFile, err := os.Open(path)
|
||||
if err != nil {
|
||||
|
|
@ -37,8 +37,8 @@ func GetVisitCounter() model.VisitCounter {
|
|||
return data
|
||||
}
|
||||
|
||||
func IncrementVisitCounter() model.Success {
|
||||
data := GetVisitCounter()
|
||||
func IncrementHitCounter() model.Success {
|
||||
data := GetHitCounter()
|
||||
data.Counter++
|
||||
|
||||
err := os.MkdirAll(filepath.Dir(path), 0755)
|
||||
Loading…
Reference in a new issue