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