Add internal sessions manager

This commit is contained in:
Dan Sosedoff
2022-12-02 13:36:31 -06:00
parent d8ee50ece6
commit 9074d4bfb8
6 changed files with 147 additions and 55 deletions

View File

@@ -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()