From d814d6bd05f18ae169633cc6ed30613678e68661 Mon Sep 17 00:00:00 2001 From: Jacob Gunther Date: Thu, 20 Jul 2023 13:37:45 -0500 Subject: [PATCH] Move assets to its own folder --- src/assets/assets.go | 10 ++++++++++ src/{ => assets}/favicon.ico | Bin src/{ => assets}/icon.png | Bin src/routes.go | 5 +++-- src/status.go | 3 ++- src/util.go | 4 ---- 6 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 src/assets/assets.go rename src/{ => assets}/favicon.ico (100%) rename src/{ => assets}/icon.png (100%) diff --git a/src/assets/assets.go b/src/assets/assets.go new file mode 100644 index 0000000..8cd9014 --- /dev/null +++ b/src/assets/assets.go @@ -0,0 +1,10 @@ +package assets + +import _ "embed" + +var ( + //go:embed icon.png + DefaultIcon []byte + //go:embed favicon.ico + Favicon []byte +) diff --git a/src/favicon.ico b/src/assets/favicon.ico similarity index 100% rename from src/favicon.ico rename to src/assets/favicon.ico diff --git a/src/icon.png b/src/assets/icon.png similarity index 100% rename from src/icon.png rename to src/assets/icon.png diff --git a/src/routes.go b/src/routes.go index e4f1fe9..249fe03 100644 --- a/src/routes.go +++ b/src/routes.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "main/src/assets" "net/http" "strconv" @@ -25,7 +26,7 @@ func PingHandler(ctx *fiber.Ctx) error { // FaviconHandler serves the favicon.ico file to any users that visit the API using a browser. func FaviconHandler(ctx *fiber.Ctx) error { - return ctx.Type("ico").Send(favicon) + return ctx.Type("ico").Send(assets.Favicon) } // JavaStatusHandler returns the status of the Java edition Minecraft server specified in the address parameter. @@ -107,7 +108,7 @@ func IconHandler(ctx *fiber.Ctx) error { // DefaultIconHandler returns the default server icon. func DefaultIconHandler(ctx *fiber.Ctx) error { - return ctx.Type("png").Send(defaultIconBytes) + return ctx.Type("png").Send(assets.DefaultIcon) } // NotFoundHandler handles requests to routes that do not exist and returns a 404 Not Found status. diff --git a/src/status.go b/src/status.go index 91353c4..0f107fe 100644 --- a/src/status.go +++ b/src/status.go @@ -4,6 +4,7 @@ import ( "encoding/base64" "encoding/json" "fmt" + "main/src/assets" "strconv" "strings" "sync" @@ -210,7 +211,7 @@ func GetServerIcon(host string, port uint16) ([]byte, time.Duration, error) { return cache, ttl, err } - icon := defaultIconBytes + icon := assets.DefaultIcon status, err := mcutil.Status(host, port) diff --git a/src/util.go b/src/util.go index 61809c4..8d20a2b 100644 --- a/src/util.go +++ b/src/util.go @@ -16,10 +16,6 @@ import ( ) var ( - //go:embed icon.png - defaultIconBytes []byte - //go:embed favicon.ico - favicon []byte blockedServers *MutexArray[string] = nil ipAddressRegex *regexp.Regexp = regexp.MustCompile(`^\d{1,3}(\.\d{1,3}){3}$`) )