Add X-Cache-Time-Remaining header

This commit is contained in:
Jacob Gunther
2022-08-21 19:24:39 -05:00
parent 6c750bcaed
commit e16f8c38bb
4 changed files with 68 additions and 28 deletions

View File

@@ -3,6 +3,7 @@ package main
import (
"log"
"net/http"
"strconv"
"github.com/gofiber/fiber/v2"
)
@@ -27,18 +28,17 @@ func JavaStatusHandler(ctx *fiber.Ctx) error {
return ctx.Status(http.StatusBadRequest).SendString("Invalid address value")
}
response, err := GetJavaStatus(host, port)
response, expiresAt, err := GetJavaStatus(host, port)
if err != nil {
return err
}
switch v := response.(type) {
case string:
return ctx.Type("json").SendString(v)
default:
return ctx.JSON(response)
if expiresAt != nil {
ctx.Set("X-Cache-Time-Remaining", strconv.Itoa(int(expiresAt.Seconds())))
}
return ctx.JSON(response)
}
func BedrockStatusHandler(ctx *fiber.Ctx) error {
@@ -48,18 +48,17 @@ func BedrockStatusHandler(ctx *fiber.Ctx) error {
return ctx.Status(http.StatusBadRequest).SendString("Invalid address value")
}
response, err := GetBedrockStatus(host, port)
response, expiresAt, err := GetBedrockStatus(host, port)
if err != nil {
return err
}
switch v := response.(type) {
case string:
return ctx.Type("json").SendString(v)
default:
return ctx.JSON(response)
if expiresAt != nil {
ctx.Set("X-Cache-Time-Remaining", strconv.Itoa(int(expiresAt.Seconds())))
}
return ctx.JSON(response)
}
func IconHandler(ctx *fiber.Ctx) error {