diff --git a/router/home_router.go b/router/home_router.go index 599d40d..b0636cb 100644 --- a/router/home_router.go +++ b/router/home_router.go @@ -62,8 +62,9 @@ type HomeRouter interface { } type homeRouterImpl struct { - serverMeta ServerMeta - myPubKey KeyPair + serverMeta ServerMeta + myPubKey KeyPair + cachedPubKey *PublicKeys } func NewHomeRouter(meta *ServerMeta) HomeRouter { @@ -81,6 +82,10 @@ func (h *homeRouterImpl) Home(c *gin.Context) { } func (h *homeRouterImpl) PublicKeys(c *gin.Context) { + if h.cachedPubKey != nil { + c.JSON(http.StatusOK, h.cachedPubKey) + return + } publicKeys := PublicKeys{} err := util.GetObject("https://api.minecraftservices.com/publickeys", &publicKeys) if err != nil { @@ -90,4 +95,5 @@ func (h *homeRouterImpl) PublicKeys(c *gin.Context) { publicKeys.ProfilePropertyKeys = append(publicKeys.ProfilePropertyKeys, h.myPubKey) publicKeys.PlayerCertificateKeys = append(publicKeys.PlayerCertificateKeys, h.myPubKey) c.JSON(http.StatusOK, publicKeys) + h.cachedPubKey = &publicKeys }