mirror of
https://github.com/grassrootseconomics/cic-custodial.git
synced 2024-11-24 06:56:47 +01:00
fix: global lock middleware func signature
This commit is contained in:
parent
5f5678e25b
commit
750fdd9c1f
@ -40,7 +40,7 @@ func initApiServer(custodialContainer *custodial.Custodial) *echo.Echo {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
apiRoute := server.Group("/api", systemGlobalLock)
|
apiRoute := server.Group("/api", systemGlobalLock(custodialContainer))
|
||||||
|
|
||||||
apiRoute.POST("/account/create", api.HandleAccountCreate(custodialContainer))
|
apiRoute.POST("/account/create", api.HandleAccountCreate(custodialContainer))
|
||||||
apiRoute.GET("/account/status/:address", api.HandleNetworkAccountStatus(custodialContainer))
|
apiRoute.GET("/account/status/:address", api.HandleNetworkAccountStatus(custodialContainer))
|
||||||
@ -78,24 +78,22 @@ func customHTTPErrorHandler(err error, c echo.Context) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func systemGlobalLock(next echo.HandlerFunc) echo.HandlerFunc {
|
func systemGlobalLock(cu *custodial.Custodial) echo.MiddlewareFunc {
|
||||||
return func(c echo.Context) error {
|
return func(next echo.HandlerFunc) echo.HandlerFunc {
|
||||||
var (
|
return func(c echo.Context) error {
|
||||||
cu = c.Get("cu").(*custodial.Custodial)
|
locked, err := cu.RedisClient.Get(c.Request().Context(), systemGlobalLockKey).Bool()
|
||||||
)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
locked, err := cu.RedisClient.Get(c.Request().Context(), systemGlobalLockKey).Bool()
|
if locked {
|
||||||
if err != nil {
|
return c.JSON(http.StatusServiceUnavailable, api.ErrResp{
|
||||||
return err
|
Ok: false,
|
||||||
|
Message: "System manually locked.",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return next(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
if locked {
|
|
||||||
return c.JSON(http.StatusServiceUnavailable, api.ErrResp{
|
|
||||||
Ok: false,
|
|
||||||
Message: "System manually locked.",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return next(c)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user