Add internal sessions manager
This commit is contained in:
@@ -23,6 +23,7 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
logger *logrus.Logger
|
||||
options command.Options
|
||||
|
||||
readonlyWarning = `
|
||||
@@ -36,6 +37,10 @@ For proper read-only access please follow postgresql role management documentati
|
||||
regexErrAuthFailed = regexp.MustCompile(`authentication failed`)
|
||||
)
|
||||
|
||||
func init() {
|
||||
logger = logrus.New()
|
||||
}
|
||||
|
||||
func exitWithMessage(message string) {
|
||||
fmt.Println("Error:", message)
|
||||
os.Exit(1)
|
||||
@@ -152,6 +157,10 @@ func initOptions() {
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
if options.Debug {
|
||||
logger.SetLevel(logrus.DebugLevel)
|
||||
}
|
||||
|
||||
if options.ReadOnly {
|
||||
fmt.Println(readonlyWarning)
|
||||
}
|
||||
@@ -184,11 +193,6 @@ func printVersion() {
|
||||
}
|
||||
|
||||
func startServer() {
|
||||
logger := logrus.New()
|
||||
if options.Debug {
|
||||
logger.SetLevel(logrus.DebugLevel)
|
||||
}
|
||||
|
||||
router := gin.New()
|
||||
router.Use(api.RequestLogger(logger))
|
||||
router.Use(gin.Recovery())
|
||||
@@ -258,8 +262,12 @@ func Run() {
|
||||
}
|
||||
|
||||
// Start session cleanup worker
|
||||
if options.Sessions && !command.Opts.DisableConnectionIdleTimeout {
|
||||
go api.StartSessionCleanup()
|
||||
if options.Sessions {
|
||||
api.DbSessions = api.NewSessionManager(logger)
|
||||
|
||||
if !command.Opts.DisableConnectionIdleTimeout {
|
||||
go api.DbSessions.RunPeriodicCleanup()
|
||||
}
|
||||
}
|
||||
|
||||
startServer()
|
||||
|
||||
Reference in New Issue
Block a user