Skip to content
Snippets Groups Projects
Verified Commit 4421cd58 authored by Ernesto Rico Schmidt's avatar Ernesto Rico Schmidt
Browse files

feat: add handler to reset application state

parent 9ebc5f4c
No related branches found
No related tags found
No related merge requests found
......@@ -46,6 +46,7 @@ const (
WebAPIDocsPrefix = "/api/docs/"
WebAPIv1Prefix = "/api/v1/"
HealthzEndpoint = "/healthz"
ResetEndpoint = "/api/v1/debug/application-state"
)
func apache2CombinedLogger(param gin.LogFormatterParams) string {
......@@ -140,6 +141,24 @@ func healthzHandler(c *gin.Context, st *store.Store, im *importer.Importer) {
c.JSON(code, h)
}
// resetApplicationStateHandler purges all the data
//
// @Summary Purges all the data
// @Description Purges all the data and returns the deleted count for each of the models
// @Produce json
// @Success 200 {object} store.DeleteCounter
// @Failure 500 {object} apiV1.ErrorResponse
// @Router /api/v1/debug/application-state [delete]
func resetApplicationStateHandler(c *gin.Context, st *store.Store) {
deleteCounter, err := st.ResetState()
if err != nil {
c.JSON(http.StatusInternalServerError, apiV1.ErrorResponse{Error: err.Error()})
}
c.JSON(http.StatusOK, deleteCounter)
}
func runWeb(ln net.Listener, st *store.Store, im *importer.Importer, conf WebConfig) error {
gin.SetMode(gin.ReleaseMode)
......@@ -174,6 +193,10 @@ func runWeb(ln net.Listener, st *store.Store, im *importer.Importer, conf WebCon
r.GET(HealthzEndpoint, func(c *gin.Context) { healthzHandler(c, st, im) })
r.GET(WebAPIDocsPrefix+"*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
if os.Getenv("OPERATION_MODE") == "tests" {
r.DELETE(ResetEndpoint, func(c *gin.Context) { resetApplicationStateHandler(c, st) })
}
srv := &http.Server{
Handler: r,
WriteTimeout: 12 * time.Hour,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment