Add statistics route
This commit is contained in:
@@ -7,16 +7,18 @@ import (
|
|||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type CacheConfig struct {
|
||||||
|
JavaStatusDuration time.Duration `yaml:"java_status_duration" json:"java_status_duration"`
|
||||||
|
BedrockStatusDuration time.Duration `yaml:"bedrock_status_duration" json:"bedrock_status_duration"`
|
||||||
|
IconDuration time.Duration `yaml:"icon_duration" json:"icon_duration"`
|
||||||
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Environment string `yaml:"environment"`
|
Environment string `yaml:"environment"`
|
||||||
Host string `yaml:"host"`
|
Host string `yaml:"host"`
|
||||||
Port uint16 `yaml:"port"`
|
Port uint16 `yaml:"port"`
|
||||||
Redis *string `yaml:"redis"`
|
Redis *string `yaml:"redis"`
|
||||||
Cache struct {
|
Cache CacheConfig `yaml:"cache"`
|
||||||
JavaStatusDuration time.Duration `yaml:"java_status_duration"`
|
|
||||||
BedrockStatusDuration time.Duration `yaml:"bedrock_status_duration"`
|
|
||||||
IconDuration time.Duration `yaml:"icon_duration"`
|
|
||||||
} `yaml:"cache"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) ReadFile(file string) error {
|
func (c *Config) ReadFile(file string) error {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
app.Get("/ping", PingHandler)
|
app.Get("/ping", PingHandler)
|
||||||
|
app.Get("/statistics", StatisticsHandler)
|
||||||
app.Get("/status/java/:address", JavaStatusHandler)
|
app.Get("/status/java/:address", JavaStatusHandler)
|
||||||
app.Get("/status/bedrock/:address", BedrockStatusHandler)
|
app.Get("/status/bedrock/:address", BedrockStatusHandler)
|
||||||
app.Get("/icon", DefaultIconHandler)
|
app.Get("/icon", DefaultIconHandler)
|
||||||
@@ -17,10 +18,20 @@ func init() {
|
|||||||
app.Use(NotFoundHandler)
|
app.Use(NotFoundHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type StatisticsResponse struct {
|
||||||
|
Cache CacheConfig `json:"cache"`
|
||||||
|
}
|
||||||
|
|
||||||
func PingHandler(ctx *fiber.Ctx) error {
|
func PingHandler(ctx *fiber.Ctx) error {
|
||||||
return ctx.SendStatus(http.StatusOK)
|
return ctx.SendStatus(http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func StatisticsHandler(ctx *fiber.Ctx) error {
|
||||||
|
return ctx.JSON(StatisticsResponse{
|
||||||
|
Cache: config.Cache,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func JavaStatusHandler(ctx *fiber.Ctx) error {
|
func JavaStatusHandler(ctx *fiber.Ctx) error {
|
||||||
host, port, err := ParseAddress(ctx.Params("address"), 25565)
|
host, port, err := ParseAddress(ctx.Params("address"), 25565)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user