From fcaef78ab77c15c834a2c0b7d4f3fc85f2f1148b Mon Sep 17 00:00:00 2001 From: Yang Luo Date: Sun, 17 Jul 2022 21:46:58 +0800 Subject: [PATCH] Add redisEndpoint. --- conf/app.conf | 1 + main.go | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/conf/app.conf b/conf/app.conf index 5e8100f..80be789 100644 --- a/conf/app.conf +++ b/conf/app.conf @@ -5,6 +5,7 @@ SessionOn = true copyrequestbody = true dataSourceName = root:123@tcp(localhost:3306)/ dbName = casbase +redisEndpoint = casdoorEndpoint = http://localhost:8000 clientId = af6b5aa958822fb9dc33 clientSecret = 8bc3010c1c951c8d876b1f311a901ff8deeb93bc diff --git a/main.go b/main.go index 15ee553..13efdc3 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "github.com/astaxie/beego" "github.com/astaxie/beego/plugins/cors" + _ "github.com/astaxie/beego/session/redis" "github.com/casbin/casbase/object" "github.com/casbin/casbase/routers" ) @@ -24,8 +25,13 @@ func main() { beego.InsertFilter("/", beego.BeforeRouter, routers.TransparentStatic) // must has this for default page beego.InsertFilter("/*", beego.BeforeRouter, routers.TransparentStatic) - beego.BConfig.WebConfig.Session.SessionProvider = "file" - beego.BConfig.WebConfig.Session.SessionProviderConfig = "./tmp" + if beego.AppConfig.String("redisEndpoint") == "" { + beego.BConfig.WebConfig.Session.SessionProvider = "file" + beego.BConfig.WebConfig.Session.SessionProviderConfig = "./tmp" + } else { + beego.BConfig.WebConfig.Session.SessionProvider = "redis" + beego.BConfig.WebConfig.Session.SessionProviderConfig = beego.AppConfig.String("redisEndpoint") + } beego.BConfig.WebConfig.Session.SessionGCMaxLifetime = 3600 * 24 * 365 beego.Run()