Add favicon route

This commit is contained in:
Jacob Gunther 2023-07-20 13:36:20 -05:00
parent 7ecc250f03
commit 17948164fd
No known key found for this signature in database
GPG Key ID: 9E6F3F4BF45EC433
3 changed files with 10 additions and 2 deletions

BIN
src/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View File

@ -10,6 +10,7 @@ import (
func init() {
app.Get("/ping", PingHandler)
app.Get("/favicon.ico", FaviconHandler)
app.Get("/status/java/:address", JavaStatusHandler)
app.Get("/status/bedrock/:address", BedrockStatusHandler)
app.Get("/icon", DefaultIconHandler)
@ -22,6 +23,11 @@ func PingHandler(ctx *fiber.Ctx) error {
return ctx.SendStatus(http.StatusOK)
}
// 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)
}
// JavaStatusHandler returns the status of the Java edition Minecraft server specified in the address parameter.
func JavaStatusHandler(ctx *fiber.Ctx) error {
host, port, err := ParseAddress(ctx.Params("address"), 25565)

View File

@ -18,8 +18,10 @@ import (
var (
//go:embed icon.png
defaultIconBytes []byte
blockedServers *MutexArray[string] = nil
ipAddressRegex *regexp.Regexp = regexp.MustCompile(`^\d{1,3}(\.\d{1,3}){3}$`)
//go:embed favicon.ico
favicon []byte
blockedServers *MutexArray[string] = nil
ipAddressRegex *regexp.Regexp = regexp.MustCompile(`^\d{1,3}(\.\d{1,3}){3}$`)
)
// MutexArray is a thread-safe array for storing and retrieving values.