mirror of
https://github.com/Cernobor/oko-server.git
synced 2025-02-24 08:27:17 +00:00
remote DB reset
This commit is contained in:
parent
e2aa0d1aea
commit
3615deb985
@ -4,6 +4,7 @@ const (
|
|||||||
URIPing = "/ping"
|
URIPing = "/ping"
|
||||||
URIHardFail = "/hard-fail"
|
URIHardFail = "/hard-fail"
|
||||||
URISoftFail = "/soft-fail"
|
URISoftFail = "/soft-fail"
|
||||||
|
URIReinit = "/reinit"
|
||||||
URIMapPack = "/mappack"
|
URIMapPack = "/mappack"
|
||||||
URIHandshake = "/handshake"
|
URIHandshake = "/handshake"
|
||||||
URIData = "/data"
|
URIData = "/data"
|
||||||
|
@ -22,6 +22,7 @@ func internalError(gc *gin.Context, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) setupRouter() *gin.Engine {
|
func (s *Server) setupRouter() *gin.Engine {
|
||||||
|
gin.SetMode(gin.ReleaseMode)
|
||||||
router := gin.New()
|
router := gin.New()
|
||||||
router.Use(gin.Recovery())
|
router.Use(gin.Recovery())
|
||||||
|
|
||||||
@ -68,6 +69,8 @@ func (s *Server) setupRouter() *gin.Engine {
|
|||||||
entry.Error(msg)
|
entry.Error(msg)
|
||||||
} else if statusCode >= 400 {
|
} else if statusCode >= 400 {
|
||||||
entry.Warn(msg)
|
entry.Warn(msg)
|
||||||
|
} else if path == URIPing {
|
||||||
|
entry.Debug(msg)
|
||||||
} else {
|
} else {
|
||||||
entry.Info(msg)
|
entry.Info(msg)
|
||||||
}
|
}
|
||||||
@ -84,6 +87,7 @@ func (s *Server) setupRouter() *gin.Engine {
|
|||||||
router.GET(URISoftFail, func(gc *gin.Context) {
|
router.GET(URISoftFail, func(gc *gin.Context) {
|
||||||
gc.JSON(http.StatusOK, map[string]string{"error": "artificial fail"})
|
gc.JSON(http.StatusOK, map[string]string{"error": "artificial fail"})
|
||||||
})
|
})
|
||||||
|
router.POST(URIReinit, s.handlePOSTReset)
|
||||||
|
|
||||||
// resources
|
// resources
|
||||||
router.GET(URIMapPack, s.handleGETTilepack)
|
router.GET(URIMapPack, s.handleGETTilepack)
|
||||||
@ -102,6 +106,15 @@ func (s *Server) setupRouter() *gin.Engine {
|
|||||||
return router
|
return router
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) handlePOSTReset(gc *gin.Context) {
|
||||||
|
err := s.reinitDB()
|
||||||
|
if err != nil {
|
||||||
|
internalError(gc, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
gc.Status(http.StatusOK)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Server) handleGETTilepack(gc *gin.Context) {
|
func (s *Server) handleGETTilepack(gc *gin.Context) {
|
||||||
gc.File(s.config.TilepackPath)
|
gc.File(s.config.TilepackPath)
|
||||||
}
|
}
|
||||||
|
@ -100,11 +100,7 @@ func (s *Server) setupDB() {
|
|||||||
s.dbpool = dbpool
|
s.dbpool = dbpool
|
||||||
|
|
||||||
if s.config.ReinitDB {
|
if s.config.ReinitDB {
|
||||||
s.log.Info("Reinitializing DB.")
|
err = s.reinitDB()
|
||||||
conn := s.getDbConn()
|
|
||||||
defer s.dbpool.Put(conn)
|
|
||||||
|
|
||||||
err = sqlitex.ExecScript(conn, initDB)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.log.WithError(err).Fatal("init DB transaction failed")
|
s.log.WithError(err).Fatal("init DB transaction failed")
|
||||||
}
|
}
|
||||||
@ -139,6 +135,14 @@ func (s *Server) setupTiles() {
|
|||||||
s.mapPackSize = info.Size()
|
s.mapPackSize = info.Size()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) reinitDB() error {
|
||||||
|
s.log.Info("Reinitializing DB.")
|
||||||
|
conn := s.getDbConn()
|
||||||
|
defer s.dbpool.Put(conn)
|
||||||
|
|
||||||
|
return sqlitex.ExecScript(conn, initDB)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Server) handshake(hc models.HandshakeChallenge) (models.UserID, error) {
|
func (s *Server) handshake(hc models.HandshakeChallenge) (models.UserID, error) {
|
||||||
conn := s.getDbConn()
|
conn := s.getDbConn()
|
||||||
defer s.dbpool.Put(conn)
|
defer s.dbpool.Put(conn)
|
||||||
|
Loading…
Reference in New Issue
Block a user