From 8ee2db155ae3156c9aab82298e345a9741e86477 Mon Sep 17 00:00:00 2001 From: hytracer Date: Wed, 22 Nov 2023 15:08:45 +0100 Subject: [PATCH] chore: refactor online request handler in separate files --- nas/online.go | 13 +++++++++++++ nas/route.go | 5 +---- 2 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 nas/online.go diff --git a/nas/online.go b/nas/online.go new file mode 100644 index 0000000..0560aa4 --- /dev/null +++ b/nas/online.go @@ -0,0 +1,13 @@ +package nas + +import ( + "strconv" + "wwfc/common" + "net/http" +) + +func returnOnlineStats(w http.ResponseWriter) { + w.Header().Set("Content-Type", "text/plain") + w.Header().Set("Content-Length", strconv.Itoa(len(strconv.Itoa(common.OnlineUsers)))) + w.Write([]byte(strconv.Itoa(common.OnlineUsers))) +} diff --git a/nas/route.go b/nas/route.go index 9a8a91c..b693278 100644 --- a/nas/route.go +++ b/nas/route.go @@ -10,7 +10,6 @@ import ( "strings" "wwfc/logging" "wwfc/sake" - "wwfc/common" ) type Route struct { @@ -76,9 +75,7 @@ func (route *Route) Handle() http.Handler { // Check for /online if strings.HasPrefix(r.URL.String(), "/online") { - w.Header().Set("Content-Type", "text/plain") - w.Header().Set("Content-Length", strconv.Itoa(len(strconv.Itoa(common.OnlineUsers)))) - w.Write([]byte(strconv.Itoa(common.OnlineUsers))) + returnOnlineStats(w) return }