Remove debug routes and profiler

This commit is contained in:
Jacob Gunther
2023-08-07 22:35:51 -05:00
parent 5eed28681e
commit 2782ac52e6
4 changed files with 7 additions and 176 deletions

View File

@@ -6,7 +6,6 @@ import (
"log" "log"
"net/http" "net/http"
"os" "os"
"strconv"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors" "github.com/gofiber/fiber/v2/middleware/cors"
@@ -80,18 +79,6 @@ func init() {
} }
func main() { func main() {
if v := os.Getenv("PROFILE"); len(v) > 0 {
port, err := strconv.ParseUint(v, 10, 16)
if err != nil {
panic(err)
}
go Profile(uint16(port))
log.Printf("Profiler is listening on :%d\n", port)
}
defer r.Close() defer r.Close()
log.Printf("Listening on %s:%d\n", conf.Host, conf.Port+instanceID) log.Printf("Listening on %s:%d\n", conf.Host, conf.Port+instanceID)

View File

@@ -1,15 +0,0 @@
package main
import (
"fmt"
"log"
"net/http"
"net/http/pprof"
)
func Profile(port uint16) {
mux := http.NewServeMux()
mux.HandleFunc("/", pprof.Profile)
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), mux))
}

View File

@@ -1,7 +1,6 @@
package main package main
import ( import (
"encoding/json"
"fmt" "fmt"
"main/src/assets" "main/src/assets"
"net/http" "net/http"
@@ -21,11 +20,6 @@ func init() {
app.Get("/icon", DefaultIconHandler) app.Get("/icon", DefaultIconHandler)
app.Get("/icon/:address", IconHandler) app.Get("/icon/:address", IconHandler)
app.Post("/vote", SendVoteHandler) app.Post("/vote", SendVoteHandler)
app.Get("/debug/java/:address", DebugJavaStatusHandler)
app.Get("/debug/legacy/:address", DebugLegacyStatusHandler)
app.Get("/debug/bedrock/:address", DebugBedrockStatusHandler)
app.Get("/debug/query/basic/:address", DebugBasicQueryHandler)
app.Get("/debug/query/full/:address", DebugFullQueryHandler)
app.Use(NotFoundHandler) app.Use(NotFoundHandler)
} }
@@ -150,141 +144,6 @@ func DefaultIconHandler(ctx *fiber.Ctx) error {
return ctx.Type("png").Send(assets.DefaultIcon) return ctx.Type("png").Send(assets.DefaultIcon)
} }
// DebugJavaStatusHandler returns the status of the Java edition Minecraft server specified in the address parameter.
func DebugJavaStatusHandler(ctx *fiber.Ctx) error {
host, port, err := ParseAddress(ctx.Params("address"), 25565)
if err != nil {
return ctx.Status(http.StatusBadRequest).SendString("Invalid address value")
}
if err = r.Increment(fmt.Sprintf("java-hits:%s-%d", host, port)); err != nil {
return err
}
result, err := mcutil.StatusRaw(host, port)
if err != nil {
return ctx.Status(http.StatusBadRequest).SendString(err.Error())
}
data, err := json.MarshalIndent(result, "", " ")
if err != nil {
return err
}
return ctx.Type("json").Send(data)
}
// DebugJavaStatusHandler returns the legacy status of the Java edition Minecraft server specified in the address parameter.
func DebugLegacyStatusHandler(ctx *fiber.Ctx) error {
host, port, err := ParseAddress(ctx.Params("address"), 25565)
if err != nil {
return ctx.Status(http.StatusBadRequest).SendString("Invalid address value")
}
if err = r.Increment(fmt.Sprintf("java-hits:%s-%d", host, port)); err != nil {
return err
}
result, err := mcutil.StatusLegacy(host, port)
if err != nil {
return ctx.Status(http.StatusBadRequest).SendString(err.Error())
}
data, err := json.MarshalIndent(result, "", " ")
if err != nil {
return err
}
return ctx.Type("json").Send(data)
}
// DebugBedrockStatusHandler returns the status of the Bedrock edition Minecraft server specified in the address parameter.
func DebugBedrockStatusHandler(ctx *fiber.Ctx) error {
host, port, err := ParseAddress(ctx.Params("address"), 19132)
if err != nil {
return ctx.Status(http.StatusBadRequest).SendString("Invalid address value")
}
if err = r.Increment(fmt.Sprintf("bedrock-hits:%s-%d", host, port)); err != nil {
return err
}
result, err := mcutil.StatusBedrock(host, port)
if err != nil {
return ctx.Status(http.StatusBadRequest).SendString(err.Error())
}
data, err := json.MarshalIndent(result, "", " ")
if err != nil {
return err
}
return ctx.Type("json").Send(data)
}
// DebugBasicQueryHandler returns the basic query information of the Java edition Minecraft server specified in the address parameter.
func DebugBasicQueryHandler(ctx *fiber.Ctx) error {
host, port, err := ParseAddress(ctx.Params("address"), 25565)
if err != nil {
return ctx.Status(http.StatusBadRequest).SendString("Invalid address value")
}
if err = r.Increment(fmt.Sprintf("bedrock-hits:%s-%d", host, port)); err != nil {
return err
}
result, err := mcutil.BasicQuery(host, port)
if err != nil {
return ctx.Status(http.StatusBadRequest).SendString(err.Error())
}
data, err := json.MarshalIndent(result, "", " ")
if err != nil {
return err
}
return ctx.Type("json").Send(data)
}
// DebugFullQueryHandler returns the full query information of the Java edition Minecraft server specified in the address parameter.
func DebugFullQueryHandler(ctx *fiber.Ctx) error {
host, port, err := ParseAddress(ctx.Params("address"), 25565)
if err != nil {
return ctx.Status(http.StatusBadRequest).SendString("Invalid address value")
}
if err = r.Increment(fmt.Sprintf("bedrock-hits:%s-%d", host, port)); err != nil {
return err
}
result, err := mcutil.FullQuery(host, port)
if err != nil {
return ctx.Status(http.StatusBadRequest).SendString(err.Error())
}
data, err := json.MarshalIndent(result, "", " ")
if err != nil {
return err
}
return ctx.Type("json").Send(data)
}
// NotFoundHandler handles requests to routes that do not exist and returns a 404 Not Found status. // NotFoundHandler handles requests to routes that do not exist and returns a 404 Not Found status.
func NotFoundHandler(ctx *fiber.Ctx) error { func NotFoundHandler(ctx *fiber.Ctx) error {
return ctx.SendStatus(http.StatusNotFound) return ctx.SendStatus(http.StatusNotFound)

View File

@@ -16,8 +16,8 @@ import (
"github.com/mcstatus-io/mcutil/response" "github.com/mcstatus-io/mcutil/response"
) )
// StatusResponse is the root response for returning any status response from the API. // BaseStatus is the base response properties for returning any status response from the API.
type StatusResponse struct { type BaseStatus struct {
Online bool `json:"online"` Online bool `json:"online"`
Host string `json:"host"` Host string `json:"host"`
Port uint16 `json:"port"` Port uint16 `json:"port"`
@@ -28,7 +28,7 @@ type StatusResponse struct {
// JavaStatusResponse is the combined response of the root response and the Java Edition status response. // JavaStatusResponse is the combined response of the root response and the Java Edition status response.
type JavaStatusResponse struct { type JavaStatusResponse struct {
StatusResponse BaseStatus
*JavaStatus *JavaStatus
} }
@@ -45,7 +45,7 @@ type JavaStatus struct {
// BedrockStatusResponse is the combined response of the root response and the Bedrock Edition status response. // BedrockStatusResponse is the combined response of the root response and the Bedrock Edition status response.
type BedrockStatusResponse struct { type BedrockStatusResponse struct {
StatusResponse BaseStatus
*BedrockStatus *BedrockStatus
} }
@@ -308,7 +308,7 @@ func FetchBedrockStatus(host string, port uint16) *BedrockStatusResponse {
if err != nil { if err != nil {
return &BedrockStatusResponse{ return &BedrockStatusResponse{
StatusResponse: StatusResponse{ BaseStatus: BaseStatus{
Online: false, Online: false,
Host: host, Host: host,
Port: port, Port: port,
@@ -320,7 +320,7 @@ func FetchBedrockStatus(host string, port uint16) *BedrockStatusResponse {
} }
response := &BedrockStatusResponse{ response := &BedrockStatusResponse{
StatusResponse: StatusResponse{ BaseStatus: BaseStatus{
Online: true, Online: true,
Host: host, Host: host,
Port: port, Port: port,
@@ -396,7 +396,7 @@ func FetchBedrockStatus(host string, port uint16) *BedrockStatusResponse {
// BuildJavaResponse builds the response data from the status and query information. // BuildJavaResponse builds the response data from the status and query information.
func BuildJavaResponse(host string, port uint16, status interface{}, query *response.FullQuery) (result JavaStatusResponse) { func BuildJavaResponse(host string, port uint16, status interface{}, query *response.FullQuery) (result JavaStatusResponse) {
result = JavaStatusResponse{ result = JavaStatusResponse{
StatusResponse: StatusResponse{ BaseStatus: BaseStatus{
Online: status != nil || query != nil, Online: status != nil || query != nil,
Host: host, Host: host,
Port: port, Port: port,