Move assets to its own folder

This commit is contained in:
Jacob Gunther 2023-07-20 13:37:45 -05:00
parent 17948164fd
commit d814d6bd05
No known key found for this signature in database
GPG Key ID: 9E6F3F4BF45EC433
6 changed files with 15 additions and 7 deletions

10
src/assets/assets.go Normal file
View File

@ -0,0 +1,10 @@
package assets
import _ "embed"
var (
//go:embed icon.png
DefaultIcon []byte
//go:embed favicon.ico
Favicon []byte
)

View File

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

View File

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

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

View File

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

View File

@ -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}$`)
)