feat: 添加公钥缓存功能
This commit is contained in:
@@ -62,8 +62,9 @@ type HomeRouter interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type homeRouterImpl struct {
|
type homeRouterImpl struct {
|
||||||
serverMeta ServerMeta
|
serverMeta ServerMeta
|
||||||
myPubKey KeyPair
|
myPubKey KeyPair
|
||||||
|
cachedPubKey *PublicKeys
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHomeRouter(meta *ServerMeta) HomeRouter {
|
func NewHomeRouter(meta *ServerMeta) HomeRouter {
|
||||||
@@ -81,6 +82,10 @@ func (h *homeRouterImpl) Home(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *homeRouterImpl) PublicKeys(c *gin.Context) {
|
func (h *homeRouterImpl) PublicKeys(c *gin.Context) {
|
||||||
|
if h.cachedPubKey != nil {
|
||||||
|
c.JSON(http.StatusOK, h.cachedPubKey)
|
||||||
|
return
|
||||||
|
}
|
||||||
publicKeys := PublicKeys{}
|
publicKeys := PublicKeys{}
|
||||||
err := util.GetObject("https://api.minecraftservices.com/publickeys", &publicKeys)
|
err := util.GetObject("https://api.minecraftservices.com/publickeys", &publicKeys)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -90,4 +95,5 @@ func (h *homeRouterImpl) PublicKeys(c *gin.Context) {
|
|||||||
publicKeys.ProfilePropertyKeys = append(publicKeys.ProfilePropertyKeys, h.myPubKey)
|
publicKeys.ProfilePropertyKeys = append(publicKeys.ProfilePropertyKeys, h.myPubKey)
|
||||||
publicKeys.PlayerCertificateKeys = append(publicKeys.PlayerCertificateKeys, h.myPubKey)
|
publicKeys.PlayerCertificateKeys = append(publicKeys.PlayerCertificateKeys, h.myPubKey)
|
||||||
c.JSON(http.StatusOK, publicKeys)
|
c.JSON(http.StatusOK, publicKeys)
|
||||||
|
h.cachedPubKey = &publicKeys
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user